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;
}
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;
}
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);
}
}
}
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;
}
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);
}
}
Aggregations