Search in sources :

Example 61 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class FuzzyMatch method lookupValues.

private Object[] lookupValues(RowMetaInterface rowMeta, Object[] row) throws KettleException {
    if (first) {
        first = false;
        data.outputRowMeta = getInputRowMeta().clone();
        meta.getFields(data.outputRowMeta, getStepname(), new RowMetaInterface[] { data.infoMeta }, null, this, repository, metaStore);
        // Check lookup field
        data.indexOfMainField = getInputRowMeta().indexOfValue(environmentSubstitute(meta.getMainStreamField()));
        if (data.indexOfMainField < 0) {
            // The field is unreachable !
            throw new KettleException(BaseMessages.getString(PKG, "FuzzyMatch.Exception.CouldnotFindMainField", meta.getMainStreamField()));
        }
    }
    Object[] add = null;
    if (row[data.indexOfMainField] == null) {
        add = buildEmptyRow();
    } else {
        try {
            add = getFromCache(row);
        } catch (Exception e) {
            throw new KettleStepException(e);
        }
    }
    return RowDataUtil.addRowData(row, rowMeta.size(), add);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Example 62 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class FuzzyMatchMeta method getFields.

public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // Add match field
    ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getOutputMatchField()));
    v.setOrigin(name);
    v.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
    inputRowMeta.addValueMeta(v);
    String mainField = space.environmentSubstitute(getOutputValueField());
    if (!Utils.isEmpty(mainField) && isGetCloserValue()) {
        switch(getAlgorithmType()) {
            case FuzzyMatchMeta.OPERATION_TYPE_DAMERAU_LEVENSHTEIN:
            case FuzzyMatchMeta.OPERATION_TYPE_LEVENSHTEIN:
                v = new ValueMetaInteger(mainField);
                v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH);
                break;
            case FuzzyMatchMeta.OPERATION_TYPE_JARO:
            case FuzzyMatchMeta.OPERATION_TYPE_JARO_WINKLER:
            case FuzzyMatchMeta.OPERATION_TYPE_PAIR_SIMILARITY:
                v = new ValueMetaNumber(mainField);
                break;
            default:
                // Phonetic algorithms
                v = new ValueMetaString(mainField);
                break;
        }
        v.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
        v.setOrigin(name);
        inputRowMeta.addValueMeta(v);
    }
    boolean activateAdditionalFields = isGetCloserValue() || (getAlgorithmType() == FuzzyMatchMeta.OPERATION_TYPE_DOUBLE_METAPHONE) || (getAlgorithmType() == FuzzyMatchMeta.OPERATION_TYPE_SOUNDEX) || (getAlgorithmType() == FuzzyMatchMeta.OPERATION_TYPE_REFINED_SOUNDEX) || (getAlgorithmType() == FuzzyMatchMeta.OPERATION_TYPE_METAPHONE);
    if (activateAdditionalFields) {
        if (info != null && info.length == 1 && info[0] != null) {
            for (int i = 0; i < valueName.length; i++) {
                v = info[0].searchValueMeta(value[i]);
                if (v != null) {
                    // Configuration error/missing resources...
                    v.setName(valueName[i]);
                    v.setOrigin(name);
                    // Only normal storage goes into the cache
                    v.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
                    inputRowMeta.addValueMeta(v);
                } else {
                    throw new KettleStepException(BaseMessages.getString(PKG, "FuzzyMatchMeta.Exception.ReturnValueCanNotBeFound", value[i]));
                }
            }
        } else {
            for (int i = 0; i < valueName.length; i++) {
                v = new ValueMetaString(valueName[i]);
                v.setOrigin(name);
                inputRowMeta.addValueMeta(v);
            }
        }
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 63 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class GetVariableMeta method getFields.

@Override
public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // Determine the maximum length...
    // 
    int length = -1;
    for (int i = 0; i < fieldDefinitions.length; i++) {
        String variableString = fieldDefinitions[i].getVariableString();
        if (variableString != null) {
            String string = space.environmentSubstitute(variableString);
            if (string.length() > length) {
                length = string.length();
            }
        }
    }
    RowMetaInterface row = new RowMeta();
    for (int i = 0; i < fieldDefinitions.length; i++) {
        ValueMetaInterface v;
        try {
            v = ValueMetaFactory.createValueMeta(fieldDefinitions[i].getFieldName(), fieldDefinitions[i].getFieldType());
        } catch (KettlePluginException e) {
            throw new KettleStepException(e);
        }
        int fieldLength = fieldDefinitions[i].getFieldLength();
        if (fieldLength < 0) {
            v.setLength(length);
        } else {
            v.setLength(fieldLength);
        }
        int fieldPrecision = fieldDefinitions[i].getFieldPrecision();
        if (fieldPrecision >= 0) {
            v.setPrecision(fieldPrecision);
        }
        v.setConversionMask(fieldDefinitions[i].getFieldFormat());
        v.setGroupingSymbol(fieldDefinitions[i].getGroup());
        v.setDecimalSymbol(fieldDefinitions[i].getDecimal());
        v.setCurrencySymbol(fieldDefinitions[i].getCurrency());
        v.setTrimType(fieldDefinitions[i].getTrimType());
        v.setOrigin(name);
        row.addValueMeta(v);
    }
    inputRowMeta.mergeRowMeta(row, name);
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 64 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class GPBulkLoaderMeta method getSQLStatements.

@Override
public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // default: nothing to do!
    SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null);
    if (databaseMeta != null) {
        if (prev != null && prev.size() > 0) {
            // Copy the row
            RowMetaInterface tableFields = new RowMeta();
            // Now change the field names
            for (int i = 0; i < fieldTable.length; i++) {
                ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);
                if (v != null) {
                    ValueMetaInterface tableField = v.clone();
                    tableField.setName(fieldTable[i]);
                    tableFields.addValueMeta(tableField);
                } else {
                    throw new KettleStepException("Unable to find field [" + fieldStream[i] + "] in the input rows");
                }
            }
            if (!Utils.isEmpty(tableName)) {
                Database db = new Database(loggingObject, databaseMeta);
                db.shareVariablesWith(transMeta);
                try {
                    db.connect();
                    String schemaTable = databaseMeta.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
                    String sql = db.getDDL(schemaTable, tableFields, null, false, null, true);
                    if (sql.length() == 0) {
                        retval.setSQL(null);
                    } else {
                        retval.setSQL(sql);
                    }
                } catch (KettleException e) {
                    retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.ErrorOccurred") + e.getMessage());
                }
            } else {
                retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection"));
            }
        } else {
            retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NotReceivingAnyFields"));
        }
    } else {
        retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NoConnectionDefined"));
    }
    return retval;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) SQLStatement(org.pentaho.di.core.SQLStatement) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 65 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class GPLoadMeta method getSQLStatements.

public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // default: nothing to do!
    SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null);
    if (databaseMeta != null) {
        if (prev != null && prev.size() > 0) {
            // Copy the row
            RowMetaInterface tableFields = new RowMeta();
            // Now change the field names
            for (int i = 0; i < fieldTable.length; i++) {
                ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);
                if (v != null) {
                    ValueMetaInterface tableField = v.clone();
                    tableField.setName(fieldTable[i]);
                    tableFields.addValueMeta(tableField);
                } else {
                    throw new KettleStepException("Unable to find field [" + fieldStream[i] + "] in the input rows");
                }
            }
            if (!Utils.isEmpty(tableName)) {
                Database db = new Database(loggingObject, databaseMeta);
                db.shareVariablesWith(transMeta);
                try {
                    db.connect();
                    String schemaTable = databaseMeta.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
                    String sql = db.getDDL(schemaTable, tableFields, null, false, null, true);
                    if (sql.length() == 0) {
                        retval.setSQL(null);
                    } else {
                        retval.setSQL(sql);
                    }
                } catch (KettleException e) {
                    retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.ErrorOccurred") + e.getMessage());
                }
            } else {
                retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.NoTableDefinedOnConnection"));
            }
        } else {
            retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.NotReceivingAnyFields"));
        }
    } else {
        retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.NoConnectionDefined"));
    }
    return retval;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) SQLStatement(org.pentaho.di.core.SQLStatement) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

KettleStepException (org.pentaho.di.core.exception.KettleStepException)235 KettleException (org.pentaho.di.core.exception.KettleException)139 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)103 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)97 RowMeta (org.pentaho.di.core.row.RowMeta)51 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)44 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)27 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)27 KettleValueException (org.pentaho.di.core.exception.KettleValueException)26 IOException (java.io.IOException)23 RowAdapter (org.pentaho.di.trans.step.RowAdapter)21 ArrayList (java.util.ArrayList)20 StepMeta (org.pentaho.di.trans.step.StepMeta)19 RowSet (org.pentaho.di.core.RowSet)18 Database (org.pentaho.di.core.database.Database)15 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)13 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)13 FormAttachment (org.eclipse.swt.layout.FormAttachment)12 FormData (org.eclipse.swt.layout.FormData)12 Button (org.eclipse.swt.widgets.Button)12