use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.
the class TableInputMeta method getFields.
public void getFields(RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
if (databaseMeta == null) {
// TODO: throw an exception here
return;
}
boolean param = false;
Database db = getDatabase();
// keep track of it for canceling purposes...
super.databases = new Database[] { db };
// First try without connecting to the database... (can be S L O W)
String sNewSQL = sql;
if (isVariableReplacementActive()) {
sNewSQL = db.environmentSubstitute(sql);
if (space != null) {
sNewSQL = space.environmentSubstitute(sNewSQL);
}
}
RowMetaInterface add = null;
try {
add = db.getQueryFields(sNewSQL, param);
} catch (KettleDatabaseException dbe) {
throw new KettleStepException("Unable to get queryfields for SQL: " + Const.CR + sNewSQL, dbe);
}
if (add != null) {
for (int i = 0; i < add.size(); i++) {
ValueMetaInterface v = add.getValueMeta(i);
v.setOrigin(origin);
}
row.addRowMeta(add);
} else {
try {
db.connect();
RowMetaInterface paramRowMeta = null;
Object[] paramData = null;
StreamInterface infoStream = getStepIOMeta().getInfoStreams().get(0);
if (!Utils.isEmpty(infoStream.getStepname())) {
param = true;
if (info.length >= 0 && info[0] != null) {
paramRowMeta = info[0];
paramData = RowDataUtil.allocateRowData(paramRowMeta.size());
}
}
add = db.getQueryFields(sNewSQL, param, paramRowMeta, paramData);
if (add == null) {
return;
}
for (int i = 0; i < add.size(); i++) {
ValueMetaInterface v = add.getValueMeta(i);
v.setOrigin(origin);
}
row.addRowMeta(add);
} catch (KettleException ke) {
throw new KettleStepException("Unable to get queryfields for SQL: " + Const.CR + sNewSQL, ke);
} finally {
db.disconnect();
}
}
if (isLazyConversionActive()) {
for (int i = 0; i < row.size(); i++) {
ValueMetaInterface v = row.getValueMeta(i);
try {
if (v.getType() == ValueMetaInterface.TYPE_STRING) {
ValueMetaInterface storageMeta = ValueMetaFactory.cloneValueMeta(v);
storageMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_NORMAL);
v.setStorageMetadata(storageMeta);
v.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
}
} catch (KettlePluginException e) {
throw new KettleStepException("Unable to clone meta for lazy conversion: " + Const.CR + v, e);
}
}
}
}
use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.
the class TableInputMeta method saveRep.
public void saveRep(Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step) throws KettleException {
try {
rep.saveDatabaseMetaStepAttribute(id_transformation, id_step, "id_connection", databaseMeta);
rep.saveStepAttribute(id_transformation, id_step, "sql", sql);
rep.saveStepAttribute(id_transformation, id_step, "limit", rowLimit);
StreamInterface infoStream = getStepIOMeta().getInfoStreams().get(0);
rep.saveStepAttribute(id_transformation, id_step, "lookup", infoStream.getStepname());
rep.saveStepAttribute(id_transformation, id_step, "execute_each_row", executeEachInputRow);
rep.saveStepAttribute(id_transformation, id_step, "variables_active", variableReplacementActive);
rep.saveStepAttribute(id_transformation, id_step, "lazy_conversion_active", lazyConversionActive);
// Also, save the step-database relationship!
if (databaseMeta != null) {
rep.insertStepDatabase(id_transformation, id_step, databaseMeta.getObjectId());
}
} catch (Exception e) {
throw new KettleException("Unable to save step information to the repository for id_step=" + id_step, e);
}
}
use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.
the class TableInputMeta method getStepIOMeta.
/**
* Returns the Input/Output metadata for this step. The generator step only produces output, does not accept input!
*/
public StepIOMetaInterface getStepIOMeta() {
if (ioMeta == null) {
ioMeta = new StepIOMeta(true, true, false, false, false, false);
StreamInterface stream = new Stream(StreamType.INFO, null, BaseMessages.getString(PKG, "TableInputMeta.InfoStream.Description"), StreamIcon.INFO, null);
ioMeta.addStream(stream);
}
return ioMeta;
}
use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.
the class TableInputMeta 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 (databaseMeta != null) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, "Connection exists", stepMeta);
remarks.add(cr);
Database db = new Database(loggingObject, databaseMeta);
db.shareVariablesWith(transMeta);
// keep track of it for canceling purposes...
super.databases = new Database[] { db };
try {
db.connect();
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, "Connection to database OK", stepMeta);
remarks.add(cr);
if (sql != null && sql.length() != 0) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, "SQL statement is entered", stepMeta);
remarks.add(cr);
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, "SQL statement is missing.", stepMeta);
remarks.add(cr);
}
} catch (KettleException e) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, "An error occurred: " + e.getMessage(), stepMeta);
remarks.add(cr);
} finally {
db.disconnect();
}
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, "Please select or create a connection to use", stepMeta);
remarks.add(cr);
}
// See if we have an informative step...
StreamInterface infoStream = getStepIOMeta().getInfoStreams().get(0);
if (!Utils.isEmpty(infoStream.getStepname())) {
boolean found = false;
for (int i = 0; i < input.length; i++) {
if (infoStream.getStepname().equalsIgnoreCase(input[i])) {
found = true;
}
}
if (found) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, "Previous step to read info from [" + infoStream.getStepname() + "] is found.", stepMeta);
remarks.add(cr);
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, "Previous step to read info from [" + infoStream.getStepname() + "] is not found.", stepMeta);
remarks.add(cr);
}
// Count the number of ? in the SQL string:
int count = 0;
for (int i = 0; i < sql.length(); i++) {
char c = sql.charAt(i);
if (c == '\'') {
// skip to next quote!
do {
i++;
c = sql.charAt(i);
} while (c != '\'');
}
if (c == '?') {
count++;
}
}
// Verify with the number of informative fields...
if (info != null) {
if (count == info.size()) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, "This step is expecting and receiving " + info.size() + " fields of input from the previous step.", stepMeta);
remarks.add(cr);
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, "This step is receiving " + info.size() + " but not the expected " + count + " fields of input from the previous step.", stepMeta);
remarks.add(cr);
}
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, "Input step name is not recognized!", stepMeta);
remarks.add(cr);
}
} else {
if (input.length > 0) {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, "Step is not expecting info from input steps.", stepMeta);
remarks.add(cr);
} else {
cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, "No input expected, no input provided.", stepMeta);
remarks.add(cr);
}
}
}
use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.
the class Validator method readSourceValuesFromInfoSteps.
void readSourceValuesFromInfoSteps() throws KettleStepException {
Map<String, Integer> inputStepWasProcessed = new HashMap<>();
for (int i = 0; i < meta.getValidations().size(); i++) {
Validation field = meta.getValidations().get(i);
List<StreamInterface> streams = meta.getStepIOMeta().getInfoStreams();
//
if (field.isSourcingValues()) {
if (streams.get(i).getStepMeta() == null) {
throw new KettleStepException("There is no valid source step specified for the allowed values of validation [" + field.getName() + "]");
}
if (Utils.isEmpty(field.getSourcingField())) {
throw new KettleStepException("There is no valid source field specified for the allowed values of validation [" + field.getName() + "]");
}
// Still here : OK, read the data from the specified step...
// The data is stored in data.listValues[i] and data.constantsMeta
//
String stepName = streams.get(i).getStepname();
if (inputStepWasProcessed.containsKey(stepName)) {
// step was processed for other StreamInterface
data.listValues[i] = data.listValues[inputStepWasProcessed.get(stepName)];
data.constantsMeta[i] = data.constantsMeta[inputStepWasProcessed.get(stepName)];
continue;
}
RowSet allowedRowSet = findInputRowSet(stepName);
int fieldIndex = -1;
List<Object> allowedValues = new ArrayList<Object>();
Object[] allowedRowData = getRowFrom(allowedRowSet);
while (allowedRowData != null) {
RowMetaInterface allowedRowMeta = allowedRowSet.getRowMeta();
if (fieldIndex < 0) {
fieldIndex = allowedRowMeta.indexOfValue(field.getSourcingField());
if (fieldIndex < 0) {
throw new KettleStepException("Source field [" + field.getSourcingField() + "] is not found in the source row data");
}
data.constantsMeta[i] = allowedRowMeta.getValueMeta(fieldIndex);
}
Object allowedValue = allowedRowData[fieldIndex];
if (allowedValue != null) {
allowedValues.add(allowedValue);
}
// Grab another row too...
//
allowedRowData = getRowFrom(allowedRowSet);
}
// Set the list values in the data block...
//
data.listValues[i] = allowedValues.toArray(new Object[allowedValues.size()]);
inputStepWasProcessed.put(stepName, i);
}
}
}
Aggregations