Search code examples
javapentahopentaho-spoonpentaho-data-integration

How can I use PDI job variables/parameters for integer step parameters?


I've written a custom step plugin for PDI and want to use job variables/parameters (accessed e.g via ${divisor}) for an integer input parameter of the step. When I try to do it like with the built-in plugins I get the error message 'Unable to open dialog for this step: For input string "${divisor}"'.

I've adapted my step plugin from the official demo step plugin and confirmed that the step generally works if all step input parameters are given hard values.

The integer parameter in question is defined as int in the Meta class and has appropriate getters/setters and is for example initialized via its XML representation.

In the Dialog class the parameter is represented as a text field, the value of which is parsed as integer when the dialog is confirmed and the values are written to the Meta class instance.

Excerpt of TimeMappingMeta.java

public class TimeMappingMeta extends BaseStepMeta implements StepMetaInterface {
    private int divisor;

    public void loadXML(Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore) throws KettleXMLException {
        setDivisor(Integer.parseInt(XMLHandler.getNodeValue(XMLHandler.getSubNode(stepnode, "divisor"))));
    }
}

Excerpt of TimeMappingDialog.java

public class TimeMappingDialog extends BaseStepDialog implements StepDialogInterface {
    private Text wDivisor;

    private void populateDialog() {
        wDivisor.setText("" + meta.getDivisor());
    }

    private void ok() {
        meta.setDivisor(Integer.parseInt(wDivisor.getText()));
    }
}

The problem is now that the string of the job parameter/variable ${divisor} can be entered into the field for the step parameter TimeMappingMeta.divisor, but the dialog will fail on confirmation because the string can't be parsed into an integer. The value is only replaced with the actual parameter value during job execution and we can't save the job parameter string in the step parameter.

Am I missing something? Is it even possible to use job variables/parameters for non-string step parameters? Maybe I can switch all step parameters to string and only parse the integer value during execution when the rows start coming through. But then why does kettle even support non-string step parameters?


Solution

  • I have come to the conclusion that it is not possible to use variable substitution for non-String step parameters. The value of the variable, e.g. ${divisor}, can only be saved as a string, even if the values are logically integers.

    Furthermore, the replacement of the variable string is not automatic and has to be performed explicitly where the value is used with the method BaseStep.environmentSubstitute. For example, using the value in the inititalization for the step looks like:

    public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
        TimeMappingMeta meta = (TimeMappingMeta) smi
        divisor = Integer.parseInt(environmentSubstitute(meta.getDivisor()));
    }