Search in sources :

Example 1 with RowGeneratorMeta

use of org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta in project pentaho-kettle by pentaho.

the class MappingIT method buildRowGeneratorStep.

/**
 * Builds a {@link org.pentaho.di.trans.steps.rowgenerator.RowGenerator} Step
 * with a single String field.
 *
 * @param registry
 *          Plugin Registry.
 * @param stepName
 *          Name to use for step
 * @return {@link StepMeta} for a Row Generator step.
 */
private StepMeta buildRowGeneratorStep(PluginRegistry registry, String stepName) {
    RowGeneratorMeta rm = new RowGeneratorMeta();
    // Set the information of the row generator.
    String rowGeneratorPid = registry.getPluginId(StepPluginType.class, rm);
    StepMeta rowGeneratorStep = new StepMeta(rowGeneratorPid, stepName, rm);
    String[] fieldName = { "string" };
    String[] type = { "String" };
    String[] value = { "string_value" };
    String[] fieldFormat = { "" };
    String[] group = { "" };
    String[] decimal = { "" };
    String[] currency = { "" };
    int[] intDummies = { -1, -1, -1 };
    boolean[] setEmptystring = { false, false, false };
    rm.setDefault();
    rm.setFieldName(fieldName);
    rm.setFieldType(type);
    rm.setValue(value);
    rm.setFieldLength(intDummies);
    rm.setFieldPrecision(intDummies);
    rm.setRowLimit("1");
    rm.setFieldFormat(fieldFormat);
    rm.setGroup(group);
    rm.setDecimal(decimal);
    rm.setCurrency(currency);
    rm.setEmptyString(setEmptystring);
    return rowGeneratorStep;
}
Also used : RowGeneratorMeta(org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta) StepMeta(org.pentaho.di.trans.step.StepMeta)

Example 2 with RowGeneratorMeta

use of org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta in project pentaho-kettle by pentaho.

the class MergeRowsIT method createRowGenerator.

void createRowGenerator(TransMeta transMeta, PluginRegistry registry, String stepName, String[] values, StepMeta mergeRowsStep, MergeRowsMeta mergeRowsMeta, int index) {
    RowGeneratorMeta rowGeneratorMeta = new RowGeneratorMeta();
    String rowGeneratorPid = registry.getPluginId(StepPluginType.class, rowGeneratorMeta);
    StepMeta rowGeneratorStep = new StepMeta(rowGeneratorPid, stepName, rowGeneratorMeta);
    transMeta.addStep(rowGeneratorStep);
    rowGeneratorMeta.setDefault();
    rowGeneratorMeta.setFieldName(fieldName);
    rowGeneratorMeta.setFieldType(type);
    rowGeneratorMeta.setFieldLength(intDummies);
    rowGeneratorMeta.setFieldPrecision(intDummies);
    rowGeneratorMeta.setRowLimit("1");
    rowGeneratorMeta.setFieldFormat(fieldFormat);
    rowGeneratorMeta.setGroup(group);
    rowGeneratorMeta.setDecimal(decimal);
    rowGeneratorMeta.setCurrency(currency);
    rowGeneratorMeta.setEmptyString(setEmptystring);
    rowGeneratorMeta.setValue(values);
    TransHopMeta hi1 = new TransHopMeta(rowGeneratorStep, mergeRowsStep);
    transMeta.addTransHop(hi1);
    List<StreamInterface> infoStreams = mergeRowsMeta.getStepIOMeta().getInfoStreams();
    StreamInterface infoStream = infoStreams.get(index);
    infoStream.setStepMeta(transMeta.findStep(stepName));
}
Also used : TransHopMeta(org.pentaho.di.trans.TransHopMeta) RowGeneratorMeta(org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 3 with RowGeneratorMeta

use of org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta in project pentaho-kettle by pentaho.

the class AddSequenceIT method testAddSequence.

/**
 * Test case for add sequence step. Row generator attached to several add sequence steps and checking whether the end
 * result is as expected.
 */
public void testAddSequence() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("addsequencetest");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create a row generator step...
    // 
    String rowGeneratorStepname = "row generator step";
    RowGeneratorMeta rm = new RowGeneratorMeta();
    // Set the information of the row generator.
    String rowGeneratorPid = registry.getPluginId(rm);
    StepMeta rowGeneratorStep = new StepMeta(rowGeneratorPid, rowGeneratorStepname, rm);
    transMeta.addStep(rowGeneratorStep);
    // 
    // Generate 10 empty rows
    // 
    String[] fieldName = {};
    String[] type = {};
    String[] value = {};
    String[] fieldFormat = {};
    String[] group = {};
    String[] decimal = {};
    int[] intDummies = {};
    rm.setDefault();
    rm.setFieldName(fieldName);
    rm.setFieldType(type);
    rm.setValue(value);
    rm.setFieldLength(intDummies);
    rm.setFieldPrecision(intDummies);
    rm.setRowLimit("10");
    rm.setFieldFormat(fieldFormat);
    rm.setGroup(group);
    rm.setDecimal(decimal);
    // 
    // Create first add sequence
    // 
    String seqStepname1 = "add sequence 1";
    AddSequenceMeta asm1 = new AddSequenceMeta();
    asm1.setUseCounter(true);
    asm1.setValuename("counter1");
    asm1.setStartAt(10);
    asm1.setIncrementBy(1);
    asm1.setMaxValue(100);
    String addSeqPid1 = registry.getPluginId(asm1);
    StepMeta addSeqStep1 = new StepMeta(addSeqPid1, seqStepname1, asm1);
    transMeta.addStep(addSeqStep1);
    TransHopMeta hi1 = new TransHopMeta(rowGeneratorStep, addSeqStep1);
    transMeta.addTransHop(hi1);
    // 
    // Create second add sequence
    // 
    String seqStepname2 = "add sequence 2";
    AddSequenceMeta asm2 = new AddSequenceMeta();
    asm2.setUseCounter(true);
    asm2.setValuename("valuename2");
    asm2.setStartAt(1);
    asm2.setIncrementBy(1);
    asm2.setMaxValue(5);
    String addSeqPid2 = registry.getPluginId(asm2);
    StepMeta addSeqStep2 = new StepMeta(addSeqPid2, seqStepname2, asm2);
    transMeta.addStep(addSeqStep2);
    TransHopMeta hi2 = new TransHopMeta(addSeqStep1, addSeqStep2);
    transMeta.addTransHop(hi2);
    // 
    // Create third add sequence
    // 
    String seqStepname3 = "add sequence 3";
    AddSequenceMeta asm3 = new AddSequenceMeta();
    asm3.setUseCounter(true);
    asm3.setValuename("valuename3");
    asm3.setStartAt(1);
    asm3.setIncrementBy(3);
    asm3.setMaxValue(17);
    String addSeqPid3 = registry.getPluginId(asm3);
    StepMeta addSeqStep3 = new StepMeta(addSeqPid3, seqStepname3, asm3);
    transMeta.addStep(addSeqStep3);
    TransHopMeta hi3 = new TransHopMeta(addSeqStep2, addSeqStep3);
    transMeta.addTransHop(hi3);
    // 
    // Create fourth add sequence
    // 
    String seqStepname4 = "add sequence 4";
    AddSequenceMeta asm4 = new AddSequenceMeta();
    asm4.setUseCounter(true);
    asm4.setValuename("valuename4");
    asm4.setStartAt(10);
    asm4.setIncrementBy(-2);
    asm4.setMaxValue(3);
    String addSeqPid4 = registry.getPluginId(asm4);
    StepMeta addSeqStep4 = new StepMeta(addSeqPid4, seqStepname4, asm4);
    transMeta.addStep(addSeqStep4);
    TransHopMeta hi4 = new TransHopMeta(addSeqStep3, addSeqStep4);
    transMeta.addTransHop(hi4);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(seqStepname4, 0);
    RowStepCollector endRc = new RowStepCollector();
    si.addRowListener(endRc);
    trans.startThreads();
    trans.waitUntilFinished();
    // Now check whether the output is still as we expect.
    List<RowMetaAndData> goldenImageRows = createResultData1();
    List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
}
Also used : RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) RowGeneratorMeta(org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans)

Example 4 with RowGeneratorMeta

use of org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta in project pentaho-kettle by pentaho.

the class CalculatorIT method testCalculator1.

public void testCalculator1() throws Exception {
    KettleEnvironment.init();
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("calculatortest1");
    // 
    // create a row generator step...
    // 
    String rowGeneratorStepname = "row generator step";
    RowGeneratorMeta rm = new RowGeneratorMeta();
    // Set the information of the row generator.
    String rowGeneratorPid = registry.getPluginId(StepPluginType.class, rm);
    StepMeta rowGeneratorStep = new StepMeta(rowGeneratorPid, rowGeneratorStepname, rm);
    transMeta.addStep(rowGeneratorStep);
    // 
    // Generate 1 empty row
    // 
    String[] strDummies = {};
    int[] intDummies = {};
    rm.setDefault();
    rm.setFieldName(strDummies);
    rm.setFieldType(strDummies);
    rm.setValue(strDummies);
    rm.setFieldLength(intDummies);
    rm.setFieldPrecision(intDummies);
    rm.setRowLimit("1");
    rm.setFieldFormat(strDummies);
    rm.setGroup(strDummies);
    rm.setDecimal(strDummies);
    // 
    // Add calculator step.
    // 
    String calculatorStepname1 = "calculator 1";
    CalculatorMeta calc1 = new CalculatorMeta();
    CalculatorMetaFunction[] calculations = new CalculatorMetaFunction[] { new CalculatorMetaFunction(// fieldName
    "timestamp1", // calctype
    CalculatorMetaFunction.CALC_CONSTANT, // fieldA
    "1970-01-01 00:00:00.100100", // String fieldB
    "", // String fieldC
    "", // valueType,
    ValueMetaInterface.TYPE_TIMESTAMP, // int valueLength,
    0, // int valuePrecision,
    0, // boolean removedFromResult,
    false, // String conversionMask,
    "", // String decimalSymbol,
    "", // String groupingSymbol,
    "", // String currencySymbol
    ""), new CalculatorMetaFunction(// fieldName
    "int1", // calctype
    CalculatorMetaFunction.CALC_CONSTANT, // fieldA
    "1", // String fieldB
    "", // String fieldC
    "", // valueType,
    ValueMetaInterface.TYPE_INTEGER, // int valueLength,
    0, // int valuePrecision,
    0, // boolean removedFromResult,
    false, // String conversionMask,
    "", // String decimalSymbol,
    "", // String groupingSymbol,
    "", // String currencySymbol
    ""), new CalculatorMetaFunction(// fieldName
    "timestamp plus 1 day", // calctype
    CalculatorMetaFunction.CALC_ADD_DAYS, // fieldA
    "timestamp1", // String fieldB
    "int1", // String fieldC
    "", // valueType,
    ValueMetaInterface.TYPE_DATE, // int valueLength,
    0, // int valuePrecision,
    0, // boolean removedFromResult,
    false, // String conversionMask,
    "", // String decimalSymbol,
    "", // String groupingSymbol,
    "", // String currencySymbol
    "") };
    calc1.setCalculation(calculations);
    // 
    String calculatorPid1 = registry.getPluginId(StepPluginType.class, calc1);
    StepMeta calcualtorStep1 = new StepMeta(calculatorPid1, calculatorStepname1, calc1);
    transMeta.addStep(calcualtorStep1);
    // 
    TransHopMeta hi1 = new TransHopMeta(rowGeneratorStep, calcualtorStep1);
    transMeta.addTransHop(hi1);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(calculatorStepname1, 0);
    RowStepCollector endRc = new RowStepCollector();
    si.addRowListener(endRc);
    trans.startThreads();
    trans.waitUntilFinished();
    // Now check whether the output is still as we expect.
    List<RowMetaAndData> goldenImageRows = createResultData1();
    List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
}
Also used : RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) RowGeneratorMeta(org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans)

Example 5 with RowGeneratorMeta

use of org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta in project pentaho-kettle by pentaho.

the class ConstantIT method testConstant1.

/**
 * Test case for Constant step. Row generator attached to a constant step.
 */
public void testConstant1() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("constanttest1");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create a row generator step...
    // 
    String rowGeneratorStepname = "row generator step";
    RowGeneratorMeta rm = new RowGeneratorMeta();
    // Set the information of the row generator.
    String rowGeneratorPid = registry.getPluginId(StepPluginType.class, rm);
    StepMeta rowGeneratorStep = new StepMeta(rowGeneratorPid, rowGeneratorStepname, rm);
    transMeta.addStep(rowGeneratorStep);
    // 
    // Generate 1 empty row
    // 
    String[] fieldName = {};
    String[] type = {};
    String[] value = {};
    String[] fieldFormat = {};
    String[] group = {};
    String[] decimal = {};
    int[] intDummies = {};
    rm.setDefault();
    rm.setFieldName(fieldName);
    rm.setFieldType(type);
    rm.setValue(value);
    rm.setFieldLength(intDummies);
    rm.setFieldPrecision(intDummies);
    rm.setRowLimit("1");
    rm.setFieldFormat(fieldFormat);
    rm.setGroup(group);
    rm.setDecimal(decimal);
    // 
    // Add constant step.
    // 
    String constStepname1 = "constant 1";
    ConstantMeta cnst1 = new ConstantMeta();
    String[] fieldName1 = { "boolean1", "boolean2", "boolean3", "boolean4", "boolean5", "boolean6", "boolean7", "string1", "string2", "string3", "integer1", "integer2", "integer3", "integer4", "number1", "number2", "number3", "number4", "timestamp1" };
    String[] type1 = { "boolean", "Boolean", "bOOLEAN", "BOOLEAN", "boolean", "boolean", "boolean", "string", "string", "String", "integer", "integer", "integer", "integer", "number", "number", "number", "number", "timestamp" };
    String[] value1 = { "Y", "T", "a", "TRUE", "0", "9", "", "AAAAAAAAAAAAAA", "   ", "", "-100", "0", "212", "", "-100.2", "0.0", "212.23", "", "1970-01-01 00:00:00.000" };
    String[] fieldFormat1 = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
    String[] group1 = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", ",", ",", ",", ",", "" };
    String[] decimal1 = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", ".", ".", ".", ".", "" };
    String[] currency = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
    int[] intDummies1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    boolean[] setEmptystring = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false };
    cnst1.setFieldName(fieldName1);
    cnst1.setFieldType(type1);
    cnst1.setValue(value1);
    cnst1.setFieldLength(intDummies1);
    cnst1.setFieldPrecision(intDummies1);
    cnst1.setFieldFormat(fieldFormat1);
    cnst1.setGroup(group1);
    cnst1.setDecimal(decimal1);
    cnst1.setCurrency(currency);
    cnst1.setEmptyString(setEmptystring);
    String addSeqPid1 = registry.getPluginId(StepPluginType.class, cnst1);
    StepMeta addSeqStep1 = new StepMeta(addSeqPid1, constStepname1, cnst1);
    transMeta.addStep(addSeqStep1);
    TransHopMeta hi1 = new TransHopMeta(rowGeneratorStep, addSeqStep1);
    transMeta.addTransHop(hi1);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(constStepname1, 0);
    RowStepCollector endRc = new RowStepCollector();
    si.addRowListener(endRc);
    trans.startThreads();
    trans.waitUntilFinished();
    // Now check whether the output is still as we expect.
    List<RowMetaAndData> goldenImageRows = createResultData1();
    List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
}
Also used : RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) RowGeneratorMeta(org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans)

Aggregations

RowGeneratorMeta (org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta)14 StepMeta (org.pentaho.di.trans.step.StepMeta)10 TransMeta (org.pentaho.di.trans.TransMeta)9 Trans (org.pentaho.di.trans.Trans)8 TransHopMeta (org.pentaho.di.trans.TransHopMeta)8 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)6 KettleException (org.pentaho.di.core.exception.KettleException)5 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)5 Point (org.eclipse.swt.graphics.Point)4 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)4 PreviewRowsDialog (org.pentaho.di.ui.core.dialog.PreviewRowsDialog)4 TransPreviewProgressDialog (org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog)4 Date (java.util.Date)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 StepPluginType (org.pentaho.di.core.plugins.StepPluginType)3 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)3 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)3 RowStepCollector (org.pentaho.di.trans.RowStepCollector)3 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)3 StepInterface (org.pentaho.di.trans.step.StepInterface)3