Search in sources :

Example 1 with RowOutputConverter

use of org.apache.hop.pipeline.transforms.jsoninput.reader.RowOutputConverter in project hop by apache.

the class JsonInput method prepareToRowProcessing.

@Override
protected void prepareToRowProcessing() throws HopException, HopTransformException, HopValueException {
    if (!meta.isInFields()) {
        data.outputRowMeta = new RowMeta();
        if (!meta.isDoNotFailIfNoFile() && (data.files == null || 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 HopException(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 HopException(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, getTransformName(), null, null, this, metadataProvider);
    // Create convert meta-data objects that will contain Date & Number formatters
    data.convertRowMeta = data.outputRowMeta.cloneToType(IValueMeta.TYPE_STRING);
    data.inputs = new InputsReader(this, meta, data, new InputErrorHandler()).iterator();
    data.readerRowSet = new QueueRowSet();
    data.readerRowSet.setDone();
    this.rowOutputConverter = new RowOutputConverter(getLogChannel());
}
Also used : RowMeta(org.apache.hop.core.row.RowMeta) HopException(org.apache.hop.core.exception.HopException) QueueRowSet(org.apache.hop.core.QueueRowSet) RowOutputConverter(org.apache.hop.pipeline.transforms.jsoninput.reader.RowOutputConverter) InputsReader(org.apache.hop.pipeline.transforms.jsoninput.reader.InputsReader)

Aggregations

QueueRowSet (org.apache.hop.core.QueueRowSet)1 HopException (org.apache.hop.core.exception.HopException)1 RowMeta (org.apache.hop.core.row.RowMeta)1 InputsReader (org.apache.hop.pipeline.transforms.jsoninput.reader.InputsReader)1 RowOutputConverter (org.apache.hop.pipeline.transforms.jsoninput.reader.RowOutputConverter)1