use of org.pentaho.di.trans.steps.jsoninput.reader.RowOutputConverter in project pentaho-kettle by pentaho.
the class JsonInput method prepareToRowProcessing.
@Override
protected void prepareToRowProcessing() throws KettleException, KettleStepException, KettleValueException {
if (!meta.isInFields()) {
data.outputRowMeta = new RowMeta();
if (!meta.isDoNotFailIfNoFile() && data.files.nrOfFiles() == 0) {
String errMsg = BaseMessages.getString(PKG, "JsonInput.Log.NoFiles");
logError(errMsg);
inputError(errMsg);
}
} else {
data.readrow = getRow();
data.inputRowMeta = getInputRowMeta();
if (data.inputRowMeta == null) {
data.hasFirstRow = false;
return;
}
data.hasFirstRow = true;
data.outputRowMeta = data.inputRowMeta.clone();
// Check if source field is provided
if (Utils.isEmpty(meta.getFieldValue())) {
logError(BaseMessages.getString(PKG, "JsonInput.Log.NoField"));
throw new KettleException(BaseMessages.getString(PKG, "JsonInput.Log.NoField"));
}
// cache the position of the field
if (data.indexSourceField < 0) {
data.indexSourceField = getInputRowMeta().indexOfValue(meta.getFieldValue());
if (data.indexSourceField < 0) {
logError(BaseMessages.getString(PKG, "JsonInput.Log.ErrorFindingField", meta.getFieldValue()));
throw new KettleException(BaseMessages.getString(PKG, "JsonInput.Exception.CouldnotFindField", meta.getFieldValue()));
}
}
// if RemoveSourceField option is set, we remove the source field from the output meta
if (meta.isRemoveSourceField()) {
data.outputRowMeta.removeValueMeta(data.indexSourceField);
// Get total previous fields minus one since we remove source field
data.totalpreviousfields = data.inputRowMeta.size() - 1;
} else {
// Get total previous fields
data.totalpreviousfields = data.inputRowMeta.size();
}
}
meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
// Create convert meta-data objects that will contain Date & Number formatters
data.convertRowMeta = data.outputRowMeta.cloneToType(ValueMetaInterface.TYPE_STRING);
data.inputs = new InputsReader(this, meta, data, new InputErrorHandler()).iterator();
// data.recordnr = 0;
data.readerRowSet = new QueueRowSet();
data.readerRowSet.setDone();
this.rowOutputConverter = new RowOutputConverter(getLogChannel());
// provide reader input fields with real path [PDI-15942]
JsonInputField[] inputFields = new JsonInputField[data.nrInputFields];
for (int i = 0; i < data.nrInputFields; i++) {
JsonInputField field = meta.getInputFields()[i].clone();
field.setPath(environmentSubstitute(field.getPath()));
inputFields[i] = field;
}
data.reader.setFields(inputFields);
}
Aggregations