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);
}
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);
}
}
}
}
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);
}
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;
}
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;
}
Aggregations