Skip to main content
Pentaho Documentation

Implementing the Partitioner Interface

Partitioner is the main Java interface that a plugin implements.

Keep Track of Partitioner Settings

The implementing class keeps track of partitioner settings using private fields with corresponding get and set methods. The dialog class implementing PartionerDialogInterface is using these methods to copy the user supplied configuration in and out of the dialog.

public Object clone()

This method is called when a step containing partitioning configuration is duplicated in Spoon. It needs to return a deep copy of this partitioner object. It is essential that the implementing class creates proper deep copies if the configuration is stored in modifiable objects, such as lists or custom helper objects. The copy is created by calling super.clone() and deep-copying any fields the partitioner may have declared.

public Partitioner getInstance()

This method is required to return a new instance of the partitioner class, with the plugin id and plugin description inherited from the instance upon which this method is called.

Serialize Partitioner Settings

The plugin serializes its settings to both XML and a PDI repository.

public String getXML()

This method is called by PDI whenever the plugin needs to serialize its settings to XML. It is called when saving a transformation in Spoon. The method returns an XML string containing the serialized settings. The string contains a series of XML tags, one tag per setting. The helper class org.pentaho.di.core.xml.XMLHandler constructs the XML string.

public void loadXML()

This method is called by PDI whenever a plugin reads its settings from XML. The XML node containing the plugin settings is passed in as an argument. Again, the helper class org.pentaho.di.core.xml.XMLHandler is used to read the settings from the XML node.

public void saveRep()

This method is called by PDI whenever a plugin saves its settings to a PDI repository. The repository object passed in as the first argument provides a convenient set of methods for serializing settings. The transformation id and step id passed in are used as identifiers when calling the repository serialization methods.

public void readRep()

This method is called by PDI whenever a plugin needs to read its configuration from a PDI repository. The step id given in the arguments should be used as the identifier when using the repositories serialization methods.

When developing plugins, make sure the serialization code is in synch with the settings available from the partitioner plugin dialog. When testing a partitioned step in Spoon, PDI internally saves and loads a copy of the transformation before it is executed. 

Provide the Name of the Dialog Class

PDI needs to know which class will take care of the settings dialog for the plugin. The interface method getDialogClassName() must return the name of the class implementing the StepDialogInterface for the partitioner. 

Partition Incoming Rows During Runtime

The class implementing Partitioner executes the actual logic that distributes the rows to available partitions.

public int getPartition()

This method is called with the row structure and the actual row as arguments. It returns the partition to which this row is sent. The total number of partitions is available in the inherited field nrPartitions and the return value is between zero (0, inclusive) and nrPartitions (exclusive).

Interface with the PDI plugin system

In order for PDI to recognize the plugin, the class implementing the Partitioner interface must also be annotated with the Java annotation org.pentaho.di.core.annotations.PartitionerPlugin.

Supply these annotation attributes:

Attribute Description
id A globally unique ID for the plugin
name A short label for the plugin
description A longer description for the plugin
i18nPackageName If the i18nPackageName attribute is supplied in the annotation attributes, the values of name and description are interpreted as i18n keys. The keys may be supplied in the extended form  i18n:<packagename> key to specify a package that is different from the default package given in the i18nPackageName attribute.