Search in sources :

Example 56 with RowSet

use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.

the class TransformClassBase method findTargetRowSet.

public RowSet findTargetRowSet(String tag) throws KettleException {
    if (tag == null) {
        return null;
    }
    String stepname = data.targetMap.get(tag);
    if (Utils.isEmpty(stepname)) {
        throw new KettleException(BaseMessages.getString(PKG, "TransformClassBase.Exception.UnableToFindTargetStepNameForTag", tag));
    }
    RowSet rowSet = findOutputRowSet(stepname);
    if (rowSet == null) {
        throw new KettleException(BaseMessages.getString(PKG, "TransformClassBase.Exception.UnableToFindTargetRowSetForStep", stepname));
    }
    return rowSet;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowSet(org.pentaho.di.core.RowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet)

Example 57 with RowSet

use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.

the class TableInput method readStartDate.

private RowMetaAndData readStartDate() throws KettleException {
    if (log.isDetailed()) {
        logDetailed("Reading from step [" + data.infoStream.getStepname() + "]");
    }
    RowMetaInterface parametersMeta = new RowMeta();
    Object[] parametersData = new Object[] {};
    RowSet rowSet = findInputRowSet(data.infoStream.getStepname());
    if (rowSet != null) {
        // rows are originating from "lookup_from"
        Object[] rowData = getRowFrom(rowSet);
        while (rowData != null) {
            parametersData = RowDataUtil.addRowData(parametersData, parametersMeta.size(), rowData);
            parametersMeta.addRowMeta(rowSet.getRowMeta());
            // take all input rows if needed!
            rowData = getRowFrom(rowSet);
        }
        if (parametersMeta.size() == 0) {
            throw new KettleException("Expected to read parameters from step [" + data.infoStream.getStepname() + "] but none were found.");
        }
    } else {
        throw new KettleException("Unable to find rowset to read from, perhaps step [" + data.infoStream.getStepname() + "] doesn't exist. (or perhaps you are trying a preview?)");
    }
    RowMetaAndData parameters = new RowMetaAndData(parametersMeta, parametersData);
    return parameters;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface)

Example 58 with RowSet

use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.

the class TransExecutor method collectExecutionResultFiles.

@VisibleForTesting
void collectExecutionResultFiles(Result result) throws KettleException {
    RowSet resultFilesRowSet = getData().getResultFilesRowSet();
    if (meta.getResultFilesTargetStepMeta() != null && result.getResultFilesList() != null && resultFilesRowSet != null) {
        for (ResultFile resultFile : result.getResultFilesList()) {
            Object[] targetRow = RowDataUtil.allocateRowData(getData().getResultFilesOutputRowMeta().size());
            int idx = 0;
            targetRow[idx++] = resultFile.getFile().getName().toString();
            // TODO: time, origin, ...
            putRowTo(getData().getResultFilesOutputRowMeta(), targetRow, resultFilesRowSet);
        }
    }
}
Also used : RowSet(org.pentaho.di.core.RowSet) ResultFile(org.pentaho.di.core.ResultFile) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 59 with RowSet

use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.

the class SwitchCase method processRow.

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (SwitchCaseMeta) smi;
    data = (SwitchCaseData) sdi;
    // Get next usable row from input rowset(s)!
    Object[] r = getRow();
    if (r == null) {
        // no more input to be expected...
        setOutputDone();
        return false;
    }
    if (first) {
        first = false;
        // map input to output streams
        createOutputValueMapping();
    }
    // We already know the target values, but we need to make sure that the input data type is the same as the specified
    // one.
    // Perhaps there is some conversion needed.
    // 
    Object lookupData = data.valueMeta.convertData(data.inputValueMeta, r[data.fieldIndex]);
    // Determine the output set of rowset to use...
    Set<RowSet> rowSetSet = (data.valueMeta.isNull(lookupData)) ? data.nullRowSetSet : data.outputMap.get(lookupData);
    // For now: send it to the default step...
    if (rowSetSet == null) {
        rowSetSet = data.defaultRowSetSet;
    }
    for (RowSet rowSet : rowSetSet) {
        putRowTo(data.outputRowMeta, r, rowSet);
    }
    if (checkFeedback(getLinesRead())) {
        if (log.isBasic()) {
            logBasic(BaseMessages.getString(PKG, "SwitchCase.Log.LineNumber") + getLinesRead());
        }
    }
    return true;
}
Also used : RowSet(org.pentaho.di.core.RowSet)

Example 60 with RowSet

use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.

the class SwitchCase method createOutputValueMapping.

/**
 * This will prepare step for execution:
 * <ol>
 * <li>will copy input row meta info, fields info, etc. step related info
 * <li>will get step IO meta info and discover target streams for target output steps
 * <li>for every target output find output rowset and expected value.
 * <li>for every discovered output rowset put it as a key-value: 'expected value'-'output rowSet'. If expected value
 * is null - put output rowset to special 'null set' (avoid usage of null as a map keys)
 * <li>Discover default row set. We expect only one default rowset, even if technically can have many. *
 * </ol>
 *
 * @throws KettleException
 *           if something goes wrong during step preparation.
 */
void createOutputValueMapping() throws KettleException {
    data.outputRowMeta = getInputRowMeta().clone();
    meta.getFields(getInputRowMeta(), getStepname(), null, null, this, repository, metaStore);
    data.fieldIndex = getInputRowMeta().indexOfValue(meta.getFieldname());
    if (data.fieldIndex < 0) {
        throw new KettleException(BaseMessages.getString(PKG, "SwitchCase.Exception.UnableToFindFieldName", meta.getFieldname()));
    }
    data.inputValueMeta = getInputRowMeta().getValueMeta(data.fieldIndex);
    try {
        StepIOMetaInterface ioMeta = meta.getStepIOMeta();
        // There is one or many case target for each target stream.
        // The ioMeta object has one more target stream for the default target though.
        // 
        List<StreamInterface> targetStreams = ioMeta.getTargetStreams();
        for (int i = 0; i < targetStreams.size(); i++) {
            SwitchCaseTarget target = (SwitchCaseTarget) targetStreams.get(i).getSubject();
            if (target == null) {
                // Skip over default option
                break;
            }
            if (target.caseTargetStep == null) {
                throw new KettleException(BaseMessages.getString(PKG, "SwitchCase.Log.NoTargetStepSpecifiedForValue", target.caseValue));
            }
            RowSet rowSet = findOutputRowSet(target.caseTargetStep.getName());
            if (rowSet == null) {
                throw new KettleException(BaseMessages.getString(PKG, "SwitchCase.Log.UnableToFindTargetRowSetForStep", target.caseTargetStep));
            }
            try {
                Object value = data.valueMeta.convertDataFromString(target.caseValue, data.stringValueMeta, null, null, ValueMetaInterface.TRIM_TYPE_NONE);
                // 
                if (data.valueMeta.isNull(value)) {
                    data.nullRowSetSet.add(rowSet);
                } else {
                    data.outputMap.put(value, rowSet);
                }
            } catch (Exception e) {
                throw new KettleException(BaseMessages.getString(PKG, "SwitchCase.Log.UnableToConvertValue", target.caseValue), e);
            }
        }
        if (meta.getDefaultTargetStep() != null) {
            RowSet rowSet = findOutputRowSet(meta.getDefaultTargetStep().getName());
            if (rowSet != null) {
                data.defaultRowSetSet.add(rowSet);
                if (data.nullRowSetSet.isEmpty()) {
                    data.nullRowSetSet.add(rowSet);
                }
            }
        }
    } catch (Exception e) {
        throw new KettleException(e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowSet(org.pentaho.di.core.RowSet) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) KettleException(org.pentaho.di.core.exception.KettleException) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Aggregations

RowSet (org.pentaho.di.core.RowSet)109 Test (org.junit.Test)43 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)40 RowMeta (org.pentaho.di.core.row.RowMeta)34 QueueRowSet (org.pentaho.di.core.QueueRowSet)26 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)25 KettleException (org.pentaho.di.core.exception.KettleException)23 BlockingRowSet (org.pentaho.di.core.BlockingRowSet)21 KettleStepException (org.pentaho.di.core.exception.KettleStepException)19 ArrayList (java.util.ArrayList)16 StepInterface (org.pentaho.di.trans.step.StepInterface)13 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)12 StepMeta (org.pentaho.di.trans.step.StepMeta)11 SingleRowRowSet (org.pentaho.di.core.SingleRowRowSet)10 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)9 RowAdapter (org.pentaho.di.trans.step.RowAdapter)9 Matchers.anyString (org.mockito.Matchers.anyString)7 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)7 IOException (java.io.IOException)6 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)6