Search in sources :

Example 6 with MappingValueRename

use of org.pentaho.di.trans.steps.mapping.MappingValueRename in project pentaho-kettle by pentaho.

the class MappingInputFieldsTest method testSelectingAndSortingUnspecifiedFields.

/**
 * verifies: If SelectingAndSortingUnspecifiedFields checkbox is checked, then
 * <ol>
 * <li>all fields throw to the next step;
 * <li>fields are resorted: mapped fields, then alphabetical sorted not mapped fields.
 * </ol>
 */
@Test
public void testSelectingAndSortingUnspecifiedFields() throws Exception {
    meta.setSelectingAndSortingUnspecifiedFields(true);
    MappingInputData sdi = new MappingInputData();
    sdi.linked = true;
    sdi.valueRenames = new ArrayList<MappingValueRename>();
    sdi.valueRenames.add(new MappingValueRename("number2", "n2"));
    sdi.valueRenames.add(new MappingValueRename("number4", "n4"));
    BlockingRowSet in = new BlockingRowSet(10);
    BlockingRowSet out = new BlockingRowSet(10);
    RowMeta rm = new RowMeta();
    rm.addValueMeta(new ValueMetaString("string"));
    rm.addValueMeta(new ValueMetaInteger("number1"));
    rm.addValueMeta(new ValueMetaInteger("number2"));
    rm.addValueMeta(new ValueMetaInteger("number3"));
    rm.addValueMeta(new ValueMetaInteger("number"));
    rm.addValueMeta(new ValueMetaInteger("number4"));
    rm.addValueMeta(new ValueMetaInteger("number5"));
    in.putRow(rm, new Object[] { "str", new Integer(100501), new Integer(100502), new Integer(100503), new Integer(100500), new Integer(100504), new Integer(100505) });
    in.putRow(rm, new Object[] { "str_1", new Integer(200501), new Integer(200502), new Integer(200503), new Integer(200500), new Integer(200504), new Integer(200505) });
    step.addRowSetToInputRowSets(in);
    step.addRowSetToOutputRowSets(out);
    assertTrue(step.init(meta, sdi));
    assertTrue(step.processRow(meta, sdi));
    Object[] outRowData = out.getRow();
    RowMetaInterface outMeta = out.getRowMeta();
    assertEquals("All fields are expected.", 7, outMeta.size());
    int i = 0;
    // Check if row-meta is formed according to the step specification
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "n2", outMeta.getValueMeta(i++).getName());
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "n4", outMeta.getValueMeta(i++).getName());
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "number", outMeta.getValueMeta(i++).getName());
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "number1", outMeta.getValueMeta(i++).getName());
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "number3", outMeta.getValueMeta(i++).getName());
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "number5", outMeta.getValueMeta(i++).getName());
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_STRING, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "string", outMeta.getValueMeta(i++).getName());
    // Check if row-data corresponds to the row-meta
    assertEquals("the field value mismatch.", new Integer(100502), outRowData[0]);
    assertEquals("the field value mismatch.", new Integer(100504), outRowData[1]);
    assertEquals("the field value mismatch.", new Integer(100500), outRowData[2]);
    assertEquals("the field value mismatch.", new Integer(100501), outRowData[3]);
    assertEquals("the field value mismatch.", new Integer(100503), outRowData[4]);
    assertEquals("the field value mismatch.", new Integer(100505), outRowData[5]);
    assertEquals("the field value mismatch.", "str", outRowData[6]);
    assertTrue(step.processRow(meta, sdi));
    outRowData = out.getRow();
    outMeta = out.getRowMeta();
    assertEquals("All fields are expected.", 7, outMeta.size());
    i = 0;
    // Check if row-meta is formed according to the step specification
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "n2", outMeta.getValueMeta(i++).getName());
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "n4", outMeta.getValueMeta(i++).getName());
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "number", outMeta.getValueMeta(i++).getName());
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "number1", outMeta.getValueMeta(i++).getName());
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "number3", outMeta.getValueMeta(i++).getName());
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "number5", outMeta.getValueMeta(i++).getName());
    assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_STRING, outMeta.getValueMeta(i).getType());
    assertEquals("the field name-meta mismatch.", "string", outMeta.getValueMeta(i++).getName());
    // Check if row-data corresponds to the row-meta
    assertEquals("the field value mismatch.", new Integer(200502), outRowData[0]);
    assertEquals("the field value mismatch.", new Integer(200504), outRowData[1]);
    assertEquals("the field value mismatch.", new Integer(200500), outRowData[2]);
    assertEquals("the field value mismatch.", new Integer(200501), outRowData[3]);
    assertEquals("the field value mismatch.", new Integer(200503), outRowData[4]);
    assertEquals("the field value mismatch.", new Integer(200505), outRowData[5]);
    assertEquals("the field value mismatch.", "str_1", outRowData[6]);
}
Also used : MappingValueRename(org.pentaho.di.trans.steps.mapping.MappingValueRename) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Test(org.junit.Test)

Example 7 with MappingValueRename

use of org.pentaho.di.trans.steps.mapping.MappingValueRename in project pentaho-kettle by pentaho.

the class MappingInputMeta_GetFields_Test method renameAndSort.

private static Object[] renameAndSort() {
    RowMeta inputRowMeta = createRowMeta("field1", "field2", "2", "1");
    List<MappingValueRename> renames = Collections.singletonList(new MappingValueRename("field2", "renamed"));
    String[] fields = new String[] { "field1", "renamed" };
    String[] expected = new String[] { "field1", "renamed", "1", "2" };
    return createCaseData(inputRowMeta, renames, fields, true, expected);
}
Also used : MappingValueRename(org.pentaho.di.trans.steps.mapping.MappingValueRename) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 8 with MappingValueRename

use of org.pentaho.di.trans.steps.mapping.MappingValueRename in project pentaho-kettle by pentaho.

the class MappingIODefinitionLoadSaveValidator method getTestObject.

@Override
public MappingIODefinition getTestObject() {
    MappingIODefinition rtn = new MappingIODefinition();
    rtn.setDescription(UUID.randomUUID().toString());
    rtn.setInputStepname(UUID.randomUUID().toString());
    rtn.setMainDataPath(rand.nextBoolean());
    rtn.setOutputStepname(UUID.randomUUID().toString());
    rtn.setRenamingOnOutput(rand.nextBoolean());
    List<MappingValueRename> renames = new ArrayList<MappingValueRename>() {

        {
            add(new MappingValueRename(UUID.randomUUID().toString(), UUID.randomUUID().toString()));
            add(new MappingValueRename(UUID.randomUUID().toString(), UUID.randomUUID().toString()));
            add(new MappingValueRename(UUID.randomUUID().toString(), UUID.randomUUID().toString()));
        }
    };
    rtn.setValueRenames(renames);
    return rtn;
}
Also used : MappingValueRename(org.pentaho.di.trans.steps.mapping.MappingValueRename) MappingIODefinition(org.pentaho.di.trans.steps.mapping.MappingIODefinition) ArrayList(java.util.ArrayList)

Example 9 with MappingValueRename

use of org.pentaho.di.trans.steps.mapping.MappingValueRename in project pentaho-kettle by pentaho.

the class RowOutputDataMapper method rowWrittenEvent.

@Override
public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
    if (first) {
        first = false;
        renamedRowMeta = rowMeta.clone();
        if (inputDefinition.isRenamingOnOutput()) {
            for (MappingValueRename valueRename : inputDefinition.getValueRenames()) {
                ValueMetaInterface valueMeta = renamedRowMeta.searchValueMeta(valueRename.getTargetValueName());
                if (valueMeta != null) {
                    valueMeta.setName(valueRename.getSourceValueName());
                }
            }
        }
        for (MappingValueRename valueRename : outputDefinition.getValueRenames()) {
            ValueMetaInterface valueMeta = renamedRowMeta.searchValueMeta(valueRename.getSourceValueName());
            if (valueMeta != null) {
                valueMeta.setName(valueRename.getTargetValueName());
            }
        }
    }
    putRowInterface.putRow(renamedRowMeta, row);
}
Also used : MappingValueRename(org.pentaho.di.trans.steps.mapping.MappingValueRename) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 10 with MappingValueRename

use of org.pentaho.di.trans.steps.mapping.MappingValueRename in project pentaho-kettle by pentaho.

the class SingleThreader method prepareMappingExecution.

public void prepareMappingExecution() throws KettleException {
    SingleThreaderData singleThreaderData = getData();
    // Set the type to single threaded in case the user forgot...
    // 
    singleThreaderData.mappingTransMeta.setTransformationType(TransformationType.SingleThreaded);
    // Create the transformation from meta-data...
    singleThreaderData.mappingTrans = new Trans(singleThreaderData.mappingTransMeta, getTrans());
    // Pass the parameters down to the sub-transformation.
    // 
    StepWithMappingMeta.activateParams(getData().mappingTrans, getData().mappingTrans, this, getData().mappingTrans.listParameters(), meta.getParameters(), meta.getParameterValues(), meta.isPassingAllParameters());
    getData().mappingTrans.activateParameters();
    // Disable thread priority managment as it will slow things down needlessly.
    // The single threaded engine doesn't use threads and doesn't need row locking.
    // 
    singleThreaderData.mappingTrans.getTransMeta().setUsingThreadPriorityManagment(false);
    // Leave a path up so that we can set variables in sub-transformations...
    // 
    singleThreaderData.mappingTrans.setParentTrans(getTrans());
    // Pass down the safe mode flag to the mapping...
    // 
    singleThreaderData.mappingTrans.setSafeModeEnabled(getTrans().isSafeModeEnabled());
    // Pass down the metrics gathering flag to the mapping...
    // 
    singleThreaderData.mappingTrans.setGatheringMetrics(getTrans().isGatheringMetrics());
    // Also set the name of this step in the mapping transformation for logging purposes
    // 
    singleThreaderData.mappingTrans.setMappingStepName(getStepname());
    initServletConfig();
    // prepare the execution
    // 
    singleThreaderData.mappingTrans.prepareExecution(null);
    // 
    if (singleThreaderData.injectStepMeta.isMappingInput()) {
        MappingInputData mappingInputData = (MappingInputData) singleThreaderData.mappingTrans.findDataInterface(singleThreaderData.injectStepMeta.getName());
        mappingInputData.sourceSteps = new StepInterface[0];
        mappingInputData.valueRenames = new ArrayList<MappingValueRename>();
    }
    // Add row producer & row listener
    singleThreaderData.rowProducer = singleThreaderData.mappingTrans.addRowProducer(meta.getInjectStep(), 0);
    StepInterface retrieveStep = singleThreaderData.mappingTrans.getStepInterface(meta.getRetrieveStep(), 0);
    retrieveStep.addRowListener(new RowAdapter() {

        @Override
        public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
            // Simply pass it along to the next steps after the SingleThreader
            // 
            SingleThreader.this.putRow(rowMeta, row);
        }
    });
    singleThreaderData.mappingTrans.startThreads();
    // Create the executor...
    singleThreaderData.executor = new SingleThreadedTransExecutor(singleThreaderData.mappingTrans);
    // 
    try {
        boolean ok = singleThreaderData.executor.init();
        if (!ok) {
            throw new KettleException(BaseMessages.getString(PKG, "SingleThreader.Exception.UnableToInitSingleThreadedTransformation"));
        }
    } catch (KettleException e) {
        throw new KettleException(BaseMessages.getString(PKG, "SingleThreader.Exception.UnableToPrepareExecutionOfMapping"), e);
    }
    // Add the mapping transformation to the active sub-transformations map in the parent transformation
    // 
    getTrans().addActiveSubTransformation(getStepname(), singleThreaderData.mappingTrans);
}
Also used : MappingValueRename(org.pentaho.di.trans.steps.mapping.MappingValueRename) KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepInterface(org.pentaho.di.trans.step.StepInterface) MappingInputData(org.pentaho.di.trans.steps.mappinginput.MappingInputData) RowAdapter(org.pentaho.di.trans.step.RowAdapter) SingleThreadedTransExecutor(org.pentaho.di.trans.SingleThreadedTransExecutor) Trans(org.pentaho.di.trans.Trans)

Aggregations

MappingValueRename (org.pentaho.di.trans.steps.mapping.MappingValueRename)23 RowMeta (org.pentaho.di.core.row.RowMeta)7 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)7 ArrayList (java.util.ArrayList)6 KettleException (org.pentaho.di.core.exception.KettleException)6 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)6 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)5 MappingIODefinition (org.pentaho.di.trans.steps.mapping.MappingIODefinition)5 KettleStepException (org.pentaho.di.core.exception.KettleStepException)4 HashMap (java.util.HashMap)3 TableItem (org.eclipse.swt.widgets.TableItem)3 SourceToTargetMapping (org.pentaho.di.core.SourceToTargetMapping)3 List (java.util.List)2 CTabItem (org.eclipse.swt.custom.CTabItem)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 FormAttachment (org.eclipse.swt.layout.FormAttachment)2 FormData (org.eclipse.swt.layout.FormData)2 FormLayout (org.eclipse.swt.layout.FormLayout)2 Button (org.eclipse.swt.widgets.Button)2