Search in sources :

Example 1 with StreamInterface

use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGenerator method generateIifStep.

/**
 * This method generates a 4 steps for every IIF clause... TODO: replace with one step...
 *
 * @param iifField
 * @param lastStep
 * @param transMeta
 * @return steps
 */
private StepMeta generateIifStep(SQLField iifField, TransMeta transMeta, StepMeta lastStep) {
    IifFunction iif = iifField.getIif();
    // The Filter condition...
    // 
    FilterRowsMeta filterMeta = new FilterRowsMeta();
    filterMeta.setCondition(iifField.getIif().getSqlCondition().getCondition());
    StepMeta filterStep = new StepMeta(iifField.getExpression(), filterMeta);
    filterStep.setLocation(xLocation, 50);
    xLocation += 100;
    filterStep.setDraw(true);
    lastStep = addToTrans(filterStep, transMeta, lastStep);
    // The True and false steps...
    // 
    StepMetaInterface trueMetaInterface;
    ValueMetaInterface valueMeta = iif.getTrueValue().getValueMeta();
    if (iif.isTrueField()) {
        CalculatorMeta trueMeta = new CalculatorMeta();
        trueMetaInterface = trueMeta;
        trueMeta.allocate(1);
        CalculatorMetaFunction function = new CalculatorMetaFunction();
        function.setFieldName(Const.NVL(iifField.getAlias(), iifField.getField()));
        function.setCalcType(CalculatorMetaFunction.CALC_COPY_OF_FIELD);
        function.setValueType(valueMeta.getType());
        function.setValueLength(valueMeta.getLength());
        function.setValuePrecision(valueMeta.getPrecision());
        function.setFieldA(iif.getTrueValueString());
        function.setConversionMask(valueMeta.getConversionMask());
        // CHECKSTYLE:Indentation:OFF
        trueMeta.getCalculation()[0] = function;
    } else {
        ConstantMeta trueMeta = new ConstantMeta();
        trueMetaInterface = trueMeta;
        trueMeta.allocate(1);
        // CHECKSTYLE:Indentation:OFF
        trueMeta.getFieldName()[0] = Const.NVL(iifField.getAlias(), iifField.getField());
        trueMeta.getFieldType()[0] = iif.getTrueValue().getValueMeta().getTypeDesc();
        trueMeta.getValue()[0] = iif.getTrueValue().toString();
        trueMeta.getFieldFormat()[0] = valueMeta.getConversionMask();
    }
    StepMeta trueStep = new StepMeta("TRUE: " + iifField.getExpression(), trueMetaInterface);
    trueStep.setLocation(xLocation, 50);
    trueStep.setDraw(true);
    lastStep = addToTrans(trueStep, transMeta, filterStep);
    StepMetaInterface falseMetaInterface;
    valueMeta = iif.getFalseValue().getValueMeta();
    if (iif.isFalseField()) {
        CalculatorMeta falseMeta = new CalculatorMeta();
        falseMetaInterface = falseMeta;
        falseMeta.allocate(1);
        CalculatorMetaFunction function = new CalculatorMetaFunction();
        function.setFieldName(Const.NVL(iifField.getAlias(), iifField.getField()));
        function.setCalcType(CalculatorMetaFunction.CALC_COPY_OF_FIELD);
        function.setValueType(valueMeta.getType());
        function.setValueLength(valueMeta.getLength());
        function.setValuePrecision(valueMeta.getPrecision());
        function.setFieldA(iif.getFalseValueString());
        function.setConversionMask(valueMeta.getConversionMask());
        falseMeta.getCalculation()[0] = function;
    } else {
        ConstantMeta falseMeta = new ConstantMeta();
        falseMetaInterface = falseMeta;
        falseMeta.allocate(1);
        falseMeta.getFieldName()[0] = Const.NVL(iifField.getAlias(), iifField.getField());
        falseMeta.getFieldType()[0] = iif.getFalseValue().getValueMeta().getTypeDesc();
        falseMeta.getFieldFormat()[0] = valueMeta.getConversionMask();
        falseMeta.getValue()[0] = iif.getFalseValue().toString();
    }
    StepMeta falseStep = new StepMeta("FALSE: " + iifField.getExpression(), falseMetaInterface);
    falseStep.setLocation(xLocation, 150);
    xLocation += 100;
    falseStep.setDraw(true);
    lastStep = addToTrans(falseStep, transMeta, filterStep);
    // specify true/false targets
    List<StreamInterface> targetStreams = filterMeta.getStepIOMeta().getTargetStreams();
    targetStreams.get(0).setSubject(trueStep.getName());
    targetStreams.get(1).setSubject(falseStep.getName());
    filterMeta.searchInfoAndTargetSteps(transMeta.getSteps());
    DummyTransMeta dummyMeta = new DummyTransMeta();
    StepMeta dummyStep = new StepMeta("Collect: " + iifField.getExpression(), dummyMeta);
    dummyStep.setLocation(xLocation, 50);
    xLocation += 100;
    dummyStep.setDraw(true);
    lastStep = addToTrans(dummyStep, transMeta, trueStep);
    transMeta.addTransHop(new TransHopMeta(falseStep, dummyStep));
    return lastStep;
}
Also used : FilterRowsMeta(org.pentaho.di.trans.steps.filterrows.FilterRowsMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) IifFunction(org.pentaho.di.core.sql.IifFunction) CalculatorMeta(org.pentaho.di.trans.steps.calculator.CalculatorMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) ConstantMeta(org.pentaho.di.trans.steps.constant.ConstantMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) CalculatorMetaFunction(org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)

Example 2 with StreamInterface

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

the class FuzzyMatchMeta method check.

public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
    CheckResult cr;
    if (prev != null && prev.size() > 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.StepReceivingFields", prev.size() + ""), stepMeta);
        remarks.add(cr);
        // Starting from selected fields in ...
        // Check the fields from the previous stream!
        String mainField = transMeta.environmentSubstitute(getMainStreamField());
        int idx = prev.indexOfValue(mainField);
        if (idx < 0) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.MainFieldNotFound", mainField), stepMeta);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.MainFieldFound", mainField), stepMeta);
        }
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.CouldNotFindFieldsFromPreviousSteps"), stepMeta);
        remarks.add(cr);
    }
    if (info != null && info.size() > 0) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.StepReceivingLookupData", info.size() + ""), stepMeta);
        remarks.add(cr);
        // Check the fields from the lookup stream!
        String lookupField = transMeta.environmentSubstitute(getLookupField());
        int idx = info.indexOfValue(lookupField);
        if (idx < 0) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.FieldNotFoundInLookupStream", lookupField), stepMeta);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.FieldFoundInTheLookupStream", lookupField), stepMeta);
        }
        remarks.add(cr);
        String error_message = "";
        boolean error_found = false;
        // Check the values to retrieve from the lookup stream!
        for (int i = 0; i < value.length; i++) {
            idx = info.indexOfValue(value[i]);
            if (idx < 0) {
                error_message += "\t\t" + value[i] + Const.CR;
                error_found = true;
            }
        }
        if (error_found) {
            error_message = BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.FieldsNotFoundInLookupStream2") + Const.CR + Const.CR + error_message;
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
        } else {
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.AllFieldsFoundInTheLookupStream2"), stepMeta);
        }
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.FieldsNotFoundFromInLookupSep"), stepMeta);
        remarks.add(cr);
    }
    // See if the source step is filled in!
    StreamInterface infoStream = getStepIOMeta().getInfoStreams().get(0);
    if (infoStream.getStepMeta() == null) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.SourceStepNotSelected"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.SourceStepIsSelected"), stepMeta);
        remarks.add(cr);
        // 
        if (info != null) {
            cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.SourceStepExist", infoStream.getStepname() + ""), stepMeta);
            remarks.add(cr);
        } else {
            cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.SourceStepDoesNotExist", infoStream.getStepname() + ""), stepMeta);
            remarks.add(cr);
        }
    }
    // See if we have input streams leading to this step!
    if (input.length >= 2) {
        cr = new CheckResult(CheckResult.TYPE_RESULT_OK, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.StepReceivingInfoFromInputSteps", input.length + ""), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResult.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "FuzzyMatchMeta.CheckResult.NeedAtLeast2InputStreams", Const.CR, Const.CR), stepMeta);
        remarks.add(cr);
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 3 with StreamInterface

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

the class FuzzyMatchMeta method readRep.

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);
        lookupfield = rep.getStepAttributeString(id_step, "lookupfield");
        mainstreamfield = rep.getStepAttributeString(id_step, "mainstreamfield");
        outputmatchfield = rep.getStepAttributeString(id_step, "outputmatchfield");
        outputvaluefield = rep.getStepAttributeString(id_step, "outputvaluefield");
        caseSensitive = rep.getStepAttributeBoolean(id_step, "caseSensitive");
        closervalue = rep.getStepAttributeBoolean(id_step, "closervalue");
        minimalValue = rep.getStepAttributeString(id_step, "minimalValue");
        maximalValue = rep.getStepAttributeString(id_step, "maximalValue");
        separator = rep.getStepAttributeString(id_step, "separator");
        algorithm = getAlgorithmTypeByCode(Const.NVL(rep.getStepAttributeString(id_step, "algorithm"), ""));
        int nrvalues = rep.countNrStepAttributes(id_step, "return_value_name");
        allocate(nrvalues);
        for (int i = 0; i < nrvalues; i++) {
            value[i] = rep.getStepAttributeString(id_step, i, "return_value_name");
            valueName[i] = rep.getStepAttributeString(id_step, i, "return_value_rename");
        }
    } catch (Exception e) {
        throw new KettleException(BaseMessages.getString(PKG, "FuzzyMatchMeta.Exception.UnexpecteErrorReadingStepInfoFromRepository"), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) 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 4 with StreamInterface

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

the class TransMeta method realClone.

/**
 * Perform a real clone of the transformation meta-data object, including cloning all lists and copying all values. If
 * the doClear parameter is true, the clone will be cleared of ALL values before the copy. If false, only the copied
 * fields will be cleared.
 *
 * @param doClear
 *          Whether to clear all of the clone's data before copying from the source object
 * @return a real clone of the calling object
 */
public Object realClone(boolean doClear) {
    try {
        TransMeta transMeta = (TransMeta) super.clone();
        if (doClear) {
            transMeta.clear();
        } else {
            // Clear out the things we're replacing below
            transMeta.databases = new ArrayList<>();
            transMeta.steps = new ArrayList<>();
            transMeta.hops = new ArrayList<>();
            transMeta.notes = new ArrayList<>();
            transMeta.dependencies = new ArrayList<>();
            transMeta.partitionSchemas = new ArrayList<>();
            transMeta.slaveServers = new ArrayList<>();
            transMeta.clusterSchemas = new ArrayList<>();
            transMeta.namedParams = new NamedParamsDefault();
            transMeta.stepChangeListeners = new ArrayList<>();
        }
        for (DatabaseMeta db : databases) {
            transMeta.addDatabase((DatabaseMeta) db.clone());
        }
        for (StepMeta step : steps) {
            transMeta.addStep((StepMeta) step.clone());
        }
        // PDI-15799: Step references are original yet. Set them to the clones.
        for (StepMeta step : transMeta.getSteps()) {
            final StepMetaInterface stepMetaInterface = step.getStepMetaInterface();
            if (stepMetaInterface != null) {
                final StepIOMetaInterface stepIOMeta = stepMetaInterface.getStepIOMeta();
                if (stepIOMeta != null) {
                    for (StreamInterface stream : stepIOMeta.getInfoStreams()) {
                        String streamStepName = stream.getStepname();
                        if (streamStepName != null) {
                            StepMeta streamStepMeta = transMeta.findStep(streamStepName);
                            stream.setStepMeta(streamStepMeta);
                        }
                    }
                }
            }
        }
        for (TransHopMeta hop : hops) {
            transMeta.addTransHop((TransHopMeta) hop.clone());
        }
        for (NotePadMeta note : notes) {
            transMeta.addNote((NotePadMeta) note.clone());
        }
        for (TransDependency dep : dependencies) {
            transMeta.addDependency((TransDependency) dep.clone());
        }
        for (SlaveServer slave : slaveServers) {
            transMeta.getSlaveServers().add((SlaveServer) slave.clone());
        }
        for (ClusterSchema schema : clusterSchemas) {
            transMeta.getClusterSchemas().add(schema.clone());
        }
        for (PartitionSchema schema : partitionSchemas) {
            transMeta.getPartitionSchemas().add((PartitionSchema) schema.clone());
        }
        for (String key : listParameters()) {
            transMeta.addParameterDefinition(key, getParameterDefault(key), getParameterDescription(key));
        }
        return transMeta;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : NamedParamsDefault(org.pentaho.di.core.parameters.NamedParamsDefault) PartitionSchema(org.pentaho.di.partition.PartitionSchema) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) IOException(java.io.IOException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) NotePadMeta(org.pentaho.di.core.NotePadMeta) ClusterSchema(org.pentaho.di.cluster.ClusterSchema) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 5 with StreamInterface

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

the class TransPainter method drawLine.

private void drawLine(StepMeta fs, StepMeta ts, TransHopMeta hi, boolean is_candidate) {
    int[] line = getLine(fs, ts);
    EColor col;
    ELineStyle linestyle = ELineStyle.SOLID;
    int activeLinewidth = linewidth;
    EImage arrow;
    if (is_candidate) {
        col = EColor.BLUE;
        arrow = EImage.ARROW_CANDIDATE;
    } else {
        if (hi.isEnabled()) {
            if (fs.isSendingErrorRowsToStep(ts)) {
                col = EColor.RED;
                linestyle = ELineStyle.DASH;
                activeLinewidth = linewidth + 1;
                arrow = EImage.ARROW_ERROR;
            } else {
                col = EColor.HOP_DEFAULT;
                arrow = EImage.ARROW_DEFAULT;
            }
        } else {
            col = EColor.GRAY;
            arrow = EImage.ARROW_DISABLED;
        }
    }
    if (hi.split) {
        activeLinewidth = linewidth + 2;
    }
    // Check to see if the source step is an info step for the target step.
    // 
    StepIOMetaInterface ioMeta = ts.getStepMetaInterface().getStepIOMeta();
    List<StreamInterface> infoStreams = ioMeta.getInfoStreams();
    if (!infoStreams.isEmpty()) {
        // 
        for (StreamInterface stream : infoStreams) {
            if (fs.getName().equalsIgnoreCase(stream.getStepname())) {
                // 
                if (fs.getCopies() > 1) {
                    // This is not a desirable situation, it will always end in error.
                    // As such, it's better not to give feedback on it.
                    // We do this by drawing an error icon over the hop...
                    // 
                    col = EColor.RED;
                    arrow = EImage.ARROW_ERROR;
                }
            }
        }
    }
    gc.setForeground(col);
    gc.setLineStyle(linestyle);
    gc.setLineWidth(activeLinewidth);
    drawArrow(arrow, line, hi, fs, ts);
    if (hi.split) {
        gc.setLineWidth(linewidth);
    }
    gc.setForeground(EColor.BLACK);
    gc.setBackground(EColor.BACKGROUND);
    gc.setLineStyle(ELineStyle.SOLID);
}
Also used : EImage(org.pentaho.di.core.gui.PrimitiveGCInterface.EImage) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) EColor(org.pentaho.di.core.gui.PrimitiveGCInterface.EColor) ELineStyle(org.pentaho.di.core.gui.PrimitiveGCInterface.ELineStyle) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Aggregations

StreamInterface (org.pentaho.di.trans.step.errorhandling.StreamInterface)86 KettleException (org.pentaho.di.core.exception.KettleException)31 KettleStepException (org.pentaho.di.core.exception.KettleStepException)26 StepIOMetaInterface (org.pentaho.di.trans.step.StepIOMetaInterface)26 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)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 RowMeta (org.pentaho.di.core.row.RowMeta)5