Search in sources :

Example 1 with FieldDefinition

use of org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition in project pentaho-kettle by pentaho.

the class GetVariableDialog method getData.

/**
 * Copy information from the meta-data input to the dialog fields.
 */
public void getData() {
    wStepname.setText(stepname);
    for (int i = 0; i < input.getFieldDefinitions().length; i++) {
        TableItem item = wFields.table.getItem(i);
        int index = 1;
        FieldDefinition currentField = input.getFieldDefinitions()[i];
        item.setText(index++, Const.NVL(currentField.getFieldName(), ""));
        item.setText(index++, Const.NVL(currentField.getVariableString(), ""));
        item.setText(index++, ValueMetaFactory.getValueMetaName(currentField.getFieldType()));
        item.setText(index++, Const.NVL(currentField.getFieldFormat(), ""));
        item.setText(index++, currentField.getFieldLength() < 0 ? "" : ("" + currentField.getFieldLength()));
        item.setText(index++, currentField.getFieldPrecision() < 0 ? "" : ("" + currentField.getFieldPrecision()));
        item.setText(index++, Const.NVL(currentField.getCurrency(), ""));
        item.setText(index++, Const.NVL(currentField.getDecimal(), ""));
        item.setText(index++, Const.NVL(currentField.getGroup(), ""));
        item.setText(index++, ValueMetaString.getTrimTypeDesc(currentField.getTrimType()));
    }
    wFields.setRowNums();
    wFields.optWidth(true);
    wStepname.selectAll();
    wStepname.setFocus();
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) FieldDefinition(org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition)

Example 2 with FieldDefinition

use of org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition in project pentaho-kettle by pentaho.

the class GetVariableMetaTest method testGetValueMetaPlugin.

@Test
public void testGetValueMetaPlugin() throws KettleStepException {
    GetVariableMeta meta = new GetVariableMeta();
    meta.setDefault();
    FieldDefinition field = new FieldDefinition();
    field.setFieldName("outputField");
    field.setVariableString(String.valueOf(2000000L));
    field.setFieldType(ValueMetaInterface.TYPE_TIMESTAMP);
    meta.setFieldDefinitions(new FieldDefinition[] { field });
    RowMetaInterface rowMeta = new RowMeta();
    meta.getFields(rowMeta, "stepName", null, null, new Variables(), null, null);
    assertNotNull(rowMeta);
    assertEquals(1, rowMeta.size());
    assertEquals("outputField", rowMeta.getFieldNames()[0]);
    assertEquals(ValueMetaInterface.TYPE_TIMESTAMP, rowMeta.getValueMeta(0).getType());
    assertTrue(rowMeta.getValueMeta(0) instanceof ValueMetaTimestamp);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) RowMeta(org.pentaho.di.core.row.RowMeta) FieldDefinition(org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Test(org.junit.Test)

Example 3 with FieldDefinition

use of org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition in project pentaho-kettle by pentaho.

the class ParameterSimpleTransIT method testParameterSimpleTrans2.

/**
 * Test case for parameters using a simple transformation. Here 1 parameter is not provided as value, so the default
 * will be used.
 *
 * @throws Exception
 *           exception on any problem.
 */
public void testParameterSimpleTrans2() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("parameter_simple_trans2");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create a get variables step...
    // 
    String getVariablesStepname = "get variables step";
    GetVariableMeta gvm = new GetVariableMeta();
    // Set the information of the get variables step.
    String getVariablesPid = registry.getPluginId(StepPluginType.class, gvm);
    StepMeta getVariablesStep = new StepMeta(getVariablesPid, getVariablesStepname, gvm);
    transMeta.addStep(getVariablesStep);
    // 
    // Generate 1 row
    // 
    String[] fieldName = { "Param1", "PARAM2" };
    String[] varName = { "${Param1}", "%%PARAM2%%" };
    int[] fieldType = { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING };
    int[] length = { -1, -1 };
    int[] precision = { -1, -1 };
    String[] format = { "", "" };
    String[] currency = { "", "" };
    String[] decimal = { "", "" };
    String[] grouping = { "", "" };
    int[] trimType = { ValueMetaInterface.TRIM_TYPE_NONE, ValueMetaInterface.TRIM_TYPE_NONE };
    FieldDefinition[] fields = new FieldDefinition[fieldName.length];
    for (int i = 0; i < fields.length; i++) {
        FieldDefinition field = new FieldDefinition();
        field.setFieldName(fieldName[i]);
        field.setVariableString(varName[i]);
        field.setFieldType(fieldType[i]);
        field.setFieldLength(length[i]);
        field.setFieldPrecision(precision[i]);
        field.setFieldFormat(format[i]);
        field.setCurrency(currency[i]);
        field.setDecimal(decimal[i]);
        field.setGroup(grouping[i]);
        field.setTrimType(trimType[i]);
        fields[i] = field;
    }
    gvm.setFieldDefinitions(fields);
    // 
    // Create a dummy step 1
    // 
    String dummyStepname1 = "dummy step 1";
    DummyTransMeta dm1 = new DummyTransMeta();
    String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
    StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
    transMeta.addStep(dummyStep1);
    TransHopMeta hi1 = new TransHopMeta(getVariablesStep, dummyStep1);
    transMeta.addTransHop(hi1);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.addParameterDefinition("Param1", "default1", "Parameter 1");
    trans.addParameterDefinition("PARAM2", "default2", "Parameter 2");
    trans.setParameterValue("Param1", "ParamValue1");
    // PARAM2 is not set
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(dummyStepname1, 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 = createResultData2();
    List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
}
Also used : FieldDefinition(org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) 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) GetVariableMeta(org.pentaho.di.trans.steps.getvariable.GetVariableMeta)

Example 4 with FieldDefinition

use of org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition in project pentaho-kettle by pentaho.

the class ParameterSimpleTransIT method testParameterSimpleTrans3.

/**
 * Test case for parameters using a simple transformation. Here blocking some unwise usage of parameters.
 *
 * @throws Exception
 *           exception on any problem.
 */
public void testParameterSimpleTrans3() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("parameter_simple_trans3");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create a get variables step...
    // 
    String getVariablesStepname = "get variables step";
    GetVariableMeta gvm = new GetVariableMeta();
    // Set the information of the get variables step.
    String getVariablesPid = registry.getPluginId(StepPluginType.class, gvm);
    StepMeta getVariablesStep = new StepMeta(getVariablesPid, getVariablesStepname, gvm);
    transMeta.addStep(getVariablesStep);
    // 
    // Generate 1 row
    // 
    String[] fieldName = { "PARAM1", "PARAM2" };
    String[] varName = { "${JAVA_HOME}", "%%PARAM2%%" };
    int[] fieldType = { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING };
    int[] length = { -1, -1 };
    int[] precision = { -1, -1 };
    String[] format = { "", "" };
    String[] currency = { "", "" };
    String[] decimal = { "", "" };
    String[] grouping = { "", "" };
    int[] trimType = { ValueMetaInterface.TRIM_TYPE_NONE, ValueMetaInterface.TRIM_TYPE_NONE };
    FieldDefinition[] fields = new FieldDefinition[fieldName.length];
    for (int i = 0; i < fields.length; i++) {
        FieldDefinition field = new FieldDefinition();
        field.setFieldName(fieldName[i]);
        field.setVariableString(varName[i]);
        field.setFieldType(fieldType[i]);
        field.setFieldLength(length[i]);
        field.setFieldPrecision(precision[i]);
        field.setFieldFormat(format[i]);
        field.setCurrency(currency[i]);
        field.setDecimal(decimal[i]);
        field.setGroup(grouping[i]);
        field.setTrimType(trimType[i]);
        fields[i] = field;
    }
    gvm.setFieldDefinitions(fields);
    // 
    // Create a dummy step 1
    // 
    String dummyStepname1 = "dummy step 1";
    DummyTransMeta dm1 = new DummyTransMeta();
    String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
    StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
    transMeta.addStep(dummyStep1);
    TransHopMeta hi1 = new TransHopMeta(getVariablesStep, dummyStep1);
    transMeta.addTransHop(hi1);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.addParameterDefinition("${JAVA_HOME}", "default1", "Parameter 1");
    trans.addParameterDefinition("PARAM2", "default2", "Parameter 2");
    trans.setParameterValue("${JAVA_HOME}", "param1");
    // PARAM2 is not set
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(dummyStepname1, 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 = createResultData3();
    List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
}
Also used : FieldDefinition(org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) 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) GetVariableMeta(org.pentaho.di.trans.steps.getvariable.GetVariableMeta)

Example 5 with FieldDefinition

use of org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition in project pentaho-kettle by pentaho.

the class ParameterSimpleTransIT method testParameterSimpleTrans4.

/**
 * Test case for parameters using a simple transformation. Check whether parameters override variables.
 *
 * @throws Exception
 *           exception on any problem.
 */
public void testParameterSimpleTrans4() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("parameter_simple_trans4");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create a get variables step...
    // 
    String getVariablesStepname = "get variables step";
    GetVariableMeta gvm = new GetVariableMeta();
    // Set the information of the get variables step.
    String getVariablesPid = registry.getPluginId(StepPluginType.class, gvm);
    StepMeta getVariablesStep = new StepMeta(getVariablesPid, getVariablesStepname, gvm);
    transMeta.addStep(getVariablesStep);
    // 
    // Generate 1 row
    // 
    String[] fieldName = { "PARAM1", "PARAM2" };
    String[] varName = { "${Param1}", "%%PARAM2%%" };
    int[] fieldType = { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING };
    int[] length = { -1, -1 };
    int[] precision = { -1, -1 };
    String[] format = { "", "" };
    String[] currency = { "", "" };
    String[] decimal = { "", "" };
    String[] grouping = { "", "" };
    int[] trimType = { ValueMetaInterface.TRIM_TYPE_NONE, ValueMetaInterface.TRIM_TYPE_NONE };
    FieldDefinition[] fields = new FieldDefinition[fieldName.length];
    for (int i = 0; i < fields.length; i++) {
        FieldDefinition field = new FieldDefinition();
        field.setFieldName(fieldName[i]);
        field.setVariableString(varName[i]);
        field.setFieldType(fieldType[i]);
        field.setFieldLength(length[i]);
        field.setFieldPrecision(precision[i]);
        field.setFieldFormat(format[i]);
        field.setCurrency(currency[i]);
        field.setDecimal(decimal[i]);
        field.setGroup(grouping[i]);
        field.setTrimType(trimType[i]);
        fields[i] = field;
    }
    gvm.setFieldDefinitions(fields);
    // 
    // Create a dummy step 1
    // 
    String dummyStepname1 = "dummy step 1";
    DummyTransMeta dm1 = new DummyTransMeta();
    String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
    StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
    transMeta.addStep(dummyStep1);
    TransHopMeta hi1 = new TransHopMeta(getVariablesStep, dummyStep1);
    transMeta.addTransHop(hi1);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.addParameterDefinition("Param1", "", "Parameter 1");
    trans.addParameterDefinition("PARAM2", "", "Parameter 2");
    trans.setParameterValue("Param1", "ParamValue1");
    trans.setParameterValue("PARAM2", "PARAMVALUE2");
    // See whether this variable overrides the parameter... it should NOT.
    trans.setVariable("Param1", "Variable1");
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(dummyStepname1, 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 : FieldDefinition(org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) 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) GetVariableMeta(org.pentaho.di.trans.steps.getvariable.GetVariableMeta)

Aggregations

FieldDefinition (org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition)10 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)6 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)6 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)6 RowStepCollector (org.pentaho.di.trans.RowStepCollector)6 Trans (org.pentaho.di.trans.Trans)6 TransHopMeta (org.pentaho.di.trans.TransHopMeta)6 TransMeta (org.pentaho.di.trans.TransMeta)6 StepInterface (org.pentaho.di.trans.step.StepInterface)6 StepMeta (org.pentaho.di.trans.step.StepMeta)6 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)6 GetVariableMeta (org.pentaho.di.trans.steps.getvariable.GetVariableMeta)6 TableItem (org.eclipse.swt.widgets.TableItem)2 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 Test (org.junit.Test)1 RowMeta (org.pentaho.di.core.row.RowMeta)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)1 Variables (org.pentaho.di.core.variables.Variables)1