Running Transformations
If you want to run a PDI transformation from Java code in a stand-alone application, take a look at this sample class, org.pentaho.di.sdk.samples.embedding.RunningTransformations
. It sets the parameters and executes the transformation in etl/parametrized_transformation.ktr. The transform can be run from the .ktr file using runTransformationFromFileSystem()
or from a PDI repository using runTransfomrationFromRepository()
.
- Always make the first call to
KettleEnvironment.init()
whenever you are working with the PDI APIs. - Prepare the transformation. The definition of a PDI transformation is represented by a
TransMeta
object. You can load this object from a .ktr file, a PDI repository, or you can generate it dynamically. To query the declared parameters of the transformation definition uselistParameters()
, or to query the assigned values usesetParameterValue()
. - Execute the transformation. An executable
Trans
object is derived from theTransMeta
object that is passed to the constructor. TheTrans
object starts and then executes asynchronously. To ensure that all steps of theTrans
object have completed, callwaitUntilFinished()
. - Evaluate the transformation outcome. After the
Trans
object completes, you can access the result usinggetResult()
. TheResult
object can be queried for success by evaluatinggetNrErrors()
. This method returns zero (0) on success and a non-zero value when there are errors. To get more information, retrieve the transformation log lines.