Search in sources :

Example 46 with StreamInterface

use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.

the class StreamLookupMeta method saveRep.

@Override
public void saveRep(Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step) throws KettleException {
    try {
        StreamInterface infoStream = getStepIOMeta().getInfoStreams().get(0);
        rep.saveStepAttribute(id_transformation, id_step, "lookup_from_step", infoStream.getStepname());
        rep.saveStepAttribute(id_transformation, id_step, "input_sorted", isInputSorted());
        rep.saveStepAttribute(id_transformation, id_step, "preserve_memory", isMemoryPreservationActive());
        rep.saveStepAttribute(id_transformation, id_step, "sorted_list", isUsingSortedList());
        rep.saveStepAttribute(id_transformation, id_step, "integer_pair", isUsingIntegerPair());
        for (int i = 0; i < getKeystream().length; i++) {
            rep.saveStepAttribute(id_transformation, id_step, i, "lookup_key_name", getKeystream()[i]);
            rep.saveStepAttribute(id_transformation, id_step, i, "lookup_key_field", getKeylookup()[i]);
        }
        for (int i = 0; i < getValue().length; i++) {
            rep.saveStepAttribute(id_transformation, id_step, i, "return_value_name", getValue()[i]);
            rep.saveStepAttribute(id_transformation, id_step, i, "return_value_rename", getValueName()[i]);
            rep.saveStepAttribute(id_transformation, id_step, i, "return_value_default", getValueDefault()[i]);
            rep.saveStepAttribute(id_transformation, id_step, i, "return_value_type", ValueMetaFactory.getValueMetaName(getValueDefaultType()[i]));
        }
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "StreamLookupMeta.Exception.UnableToSaveStepInfoToRepository") + id_step, e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 47 with StreamInterface

use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.

the class StreamLookupMeta method getXML.

@Override
public String getXML() {
    StringBuilder retval = new StringBuilder();
    StreamInterface infoStream = getStepIOMeta().getInfoStreams().get(0);
    retval.append("    ").append(XMLHandler.addTagValue("from", infoStream.getStepname()));
    retval.append("    ").append(XMLHandler.addTagValue("input_sorted", isInputSorted()));
    retval.append("    ").append(XMLHandler.addTagValue("preserve_memory", isMemoryPreservationActive()));
    retval.append("    ").append(XMLHandler.addTagValue("sorted_list", isUsingSortedList()));
    retval.append("    ").append(XMLHandler.addTagValue("integer_pair", isUsingIntegerPair()));
    retval.append("    <lookup>").append(Const.CR);
    for (int i = 0; i < getKeystream().length; i++) {
        retval.append("      <key>").append(Const.CR);
        retval.append("        ").append(XMLHandler.addTagValue("name", getKeystream()[i]));
        retval.append("        ").append(XMLHandler.addTagValue("field", getKeylookup()[i]));
        retval.append("      </key>").append(Const.CR);
    }
    for (int i = 0; i < getValue().length; i++) {
        retval.append("      <value>").append(Const.CR);
        retval.append("        ").append(XMLHandler.addTagValue("name", getValue()[i]));
        retval.append("        ").append(XMLHandler.addTagValue("rename", getValueName()[i]));
        retval.append("        ").append(XMLHandler.addTagValue("default", getValueDefault()[i]));
        retval.append("        ").append(XMLHandler.addTagValue("type", ValueMetaFactory.getValueMetaName(getValueDefaultType()[i])));
        retval.append("      </value>").append(Const.CR);
    }
    retval.append("    </lookup>").append(Const.CR);
    return retval.toString();
}
Also used : StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 48 with StreamInterface

use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.

the class StreamLookupMeta method readRep.

@Override
public void readRep(Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases) throws KettleException {
    try {
        String lookupFromStepname = rep.getStepAttributeString(id_step, "lookup_from_step");
        StreamInterface infoStream = getStepIOMeta().getInfoStreams().get(0);
        infoStream.setSubject(lookupFromStepname);
        setInputSorted(rep.getStepAttributeBoolean(id_step, "input_sorted"));
        setMemoryPreservationActive(rep.getStepAttributeBoolean(id_step, "preserve_memory"));
        setUsingSortedList(rep.getStepAttributeBoolean(id_step, "sorted_list"));
        setUsingIntegerPair(rep.getStepAttributeBoolean(id_step, "integer_pair"));
        int nrkeys = rep.countNrStepAttributes(id_step, "lookup_key_name");
        int nrvalues = rep.countNrStepAttributes(id_step, "return_value_name");
        allocate(nrkeys, nrvalues);
        for (int i = 0; i < nrkeys; i++) {
            // CHECKSTYLE:Indentation:OFF
            getKeystream()[i] = rep.getStepAttributeString(id_step, i, "lookup_key_name");
            getKeylookup()[i] = rep.getStepAttributeString(id_step, i, "lookup_key_field");
        // CHECKSTYLE:Indentation:ON
        }
        for (int i = 0; i < nrvalues; i++) {
            // CHECKSTYLE:Indentation:OFF
            getValue()[i] = rep.getStepAttributeString(id_step, i, "return_value_name");
            getValueName()[i] = rep.getStepAttributeString(id_step, i, "return_value_rename");
            getValueDefault()[i] = rep.getStepAttributeString(id_step, i, "return_value_default");
            getValueDefaultType()[i] = ValueMetaFactory.getIdForValueMeta(rep.getStepAttributeString(id_step, i, "return_value_type"));
        // CHECKSTYLE:Indentation:ON
        }
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "StreamLookupMeta.Exception.UnexpecteErrorReadingStepInfoFromRepository"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 49 with StreamInterface

use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.

the class StreamLookupMeta method readData.

private void readData(Node stepnode) throws KettleXMLException {
    try {
        String dtype;
        int nrkeys, nrvalues;
        String lookupFromStepname = XMLHandler.getTagValue(stepnode, "from");
        StreamInterface infoStream = getStepIOMeta().getInfoStreams().get(0);
        infoStream.setSubject(lookupFromStepname);
        setInputSorted("Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "input_sorted")));
        setMemoryPreservationActive("Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "preserve_memory")));
        setUsingSortedList("Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "sorted_list")));
        setUsingIntegerPair("Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "integer_pair")));
        Node lookup = XMLHandler.getSubNode(stepnode, "lookup");
        nrkeys = XMLHandler.countNodes(lookup, "key");
        nrvalues = XMLHandler.countNodes(lookup, "value");
        allocate(nrkeys, nrvalues);
        for (int i = 0; i < nrkeys; i++) {
            Node knode = XMLHandler.getSubNodeByNr(lookup, "key", i);
            // CHECKSTYLE:Indentation:OFF
            getKeystream()[i] = XMLHandler.getTagValue(knode, "name");
            getKeylookup()[i] = XMLHandler.getTagValue(knode, "field");
        // CHECKSTYLE:Indentation:ON
        }
        for (int i = 0; i < nrvalues; i++) {
            Node vnode = XMLHandler.getSubNodeByNr(lookup, "value", i);
            // CHECKSTYLE:Indentation:OFF
            getValue()[i] = XMLHandler.getTagValue(vnode, "name");
            getValueName()[i] = XMLHandler.getTagValue(vnode, "rename");
            if (getValueName()[i] == null) {
                // default: same name to return!
                getValueName()[i] = getValue()[i];
            }
            getValueDefault()[i] = XMLHandler.getTagValue(vnode, "default");
            dtype = XMLHandler.getTagValue(vnode, "type");
            getValueDefaultType()[i] = ValueMetaFactory.getIdForValueMeta(dtype);
        // CHECKSTYLE:Indentation:ON
        }
    } catch (Exception e) {
        throw new KettleXMLException(BaseMessages.getString(PKG, "StreamLookupMeta.Exception.UnableToLoadStepInfoFromXML"), e);
    }
}
Also used : Node(org.w3c.dom.Node) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 50 with StreamInterface

use of org.pentaho.di.trans.step.errorhandling.StreamInterface 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

StreamInterface (org.pentaho.di.trans.step.errorhandling.StreamInterface)84 KettleException (org.pentaho.di.core.exception.KettleException)31 KettleStepException (org.pentaho.di.core.exception.KettleStepException)26 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)19 StepIOMetaInterface (org.pentaho.di.trans.step.StepIOMetaInterface)19 StepMeta (org.pentaho.di.trans.step.StepMeta)19 Stream (org.pentaho.di.trans.step.errorhandling.Stream)10 TableItem (org.eclipse.swt.widgets.TableItem)8 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)8 Test (org.junit.Test)7 CheckResult (org.pentaho.di.core.CheckResult)7 KettleRowException (org.pentaho.di.core.exception.KettleRowException)7 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)7 ArrayList (java.util.ArrayList)6 TransHopMeta (org.pentaho.di.trans.TransHopMeta)6 StepIOMeta (org.pentaho.di.trans.step.StepIOMeta)6 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)5 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)5 Point (org.pentaho.di.core.gui.Point)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)5