use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.
the class TransMeta method getStepFields.
/**
* Returns the fields that are emitted by a certain step.
*
* @param stepMeta
* The step to be queried.
* @param targetStep
* the target step
* @param monitor
* The progress monitor for progress dialog. (null if not used!)
* @return A row containing the fields emitted.
* @throws KettleStepException
* the kettle step exception
*/
public RowMetaInterface getStepFields(StepMeta stepMeta, StepMeta targetStep, ProgressMonitorListener monitor) throws KettleStepException {
RowMetaInterface row = new RowMeta();
if (stepMeta == null) {
return row;
}
String fromToCacheEntry = stepMeta.getName() + (targetStep != null ? ("-" + targetStep.getName()) : "");
RowMetaInterface rowMeta = stepsFieldsCache.get(fromToCacheEntry);
if (rowMeta != null) {
return rowMeta;
}
//
if (targetStep != null && stepMeta.isSendingErrorRowsToStep(targetStep)) {
// The error rows are the same as the input rows for
// the step but with the selected error fields added
//
row = getPrevStepFields(stepMeta);
// Add to this the error fields...
StepErrorMeta stepErrorMeta = stepMeta.getStepErrorMeta();
row.addRowMeta(stepErrorMeta.getErrorFields());
// Store this row in the cache
//
stepsFieldsCache.put(fromToCacheEntry, row);
return row;
}
// Resume the regular program...
List<StepMeta> prevSteps = findPreviousSteps(stepMeta, false);
int nrPrevious = prevSteps.size();
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.FromStepALookingAtPreviousStep", stepMeta.getName(), String.valueOf(nrPrevious)));
}
for (int i = 0; i < prevSteps.size(); i++) {
StepMeta prevStepMeta = prevSteps.get(i);
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.CheckingStepTask.Title", prevStepMeta.getName()));
}
RowMetaInterface add = getStepFields(prevStepMeta, stepMeta, monitor);
if (add == null) {
add = new RowMeta();
}
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.FoundFieldsToAdd") + add.toString());
}
if (i == 0) {
row.addRowMeta(add);
} else {
// See if the add fields are not already in the row
for (int x = 0; x < add.size(); x++) {
ValueMetaInterface v = add.getValueMeta(x);
ValueMetaInterface s = row.searchValueMeta(v.getName());
if (s == null) {
row.addValueMeta(v);
}
}
}
}
if (nrPrevious == 0 && stepMeta.getRemoteInputSteps().size() > 0) {
//
for (RemoteStep remoteStep : stepMeta.getRemoteInputSteps()) {
RowMetaInterface inputFields = remoteStep.getRowMeta();
for (ValueMetaInterface inputField : inputFields.getValueMetaList()) {
if (row.searchValueMeta(inputField.getName()) == null) {
row.addValueMeta(inputField);
}
}
}
}
// Finally, see if we need to add/modify/delete fields with this step "name"
rowMeta = getThisStepFields(stepMeta, targetStep, row, monitor);
// Store this row in the cache
//
stepsFieldsCache.put(fromToCacheEntry, rowMeta);
return rowMeta;
}
use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.
the class TransExecutorMeta method addFieldToRow.
protected void addFieldToRow(RowMetaInterface row, String fieldName, int type, int length, int precision) throws KettleStepException {
if (!Utils.isEmpty(fieldName)) {
try {
ValueMetaInterface value = ValueMetaFactory.createValueMeta(fieldName, type, length, precision);
value.setOrigin(getParentStepMeta().getName());
row.addValueMeta(value);
} catch (KettlePluginException e) {
throw new KettleStepException(BaseMessages.getString(PKG, "TransExecutorMeta.ValueMetaInterfaceCreation", fieldName), e);
}
}
}
use of org.pentaho.di.core.row.ValueMetaInterface 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;
}
if (cachedRowMetaActive) {
row.addRowMeta(cachedRowMeta);
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) {
attachOrigin(add, 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;
}
attachOrigin(add, 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.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.
the class TableInputMeta method analyseImpact.
@Override
public void analyseImpact(List<DatabaseImpact> impact, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, Repository repository, IMetaStore metaStore) throws KettleStepException {
// if ( stepMeta.getName().equalsIgnoreCase( "cdc_cust" ) ) {
// System.out.println( "HERE!" );
// }
// Find the lookupfields...
RowMetaInterface out = new RowMeta();
// TODO: this builds, but does it work in all cases.
getFields(out, stepMeta.getName(), new RowMetaInterface[] { info }, null, transMeta, repository, metaStore);
if (out != null) {
for (int i = 0; i < out.size(); i++) {
ValueMetaInterface outvalue = out.getValueMeta(i);
DatabaseImpact ii = new DatabaseImpact(DatabaseImpact.TYPE_IMPACT_READ, transMeta.getName(), stepMeta.getName(), databaseMeta.getDatabaseName(), "", outvalue.getName(), outvalue.getName(), stepMeta.getName(), sql, "read from one or more database tables via SQL statement");
impact.add(ii);
}
}
}
use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.
the class TextFileInputMeta method getFields.
@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
if (!isPassingThruFields()) {
// all incoming fields are not transmitted !
row.clear();
} else {
if (info != null) {
boolean found = false;
for (int i = 0; i < info.length && !found; i++) {
if (info[i] != null) {
row.mergeRowMeta(info[i]);
found = true;
}
}
}
}
for (int i = 0; i < inputFields.length; i++) {
TextFileInputField field = inputFields[i];
int type = field.getType();
if (type == ValueMetaInterface.TYPE_NONE) {
type = ValueMetaInterface.TYPE_STRING;
}
try {
ValueMetaInterface v = ValueMetaFactory.createValueMeta(field.getName(), type);
v.setLength(field.getLength());
v.setPrecision(field.getPrecision());
v.setOrigin(name);
v.setConversionMask(field.getFormat());
v.setDecimalSymbol(field.getDecimalSymbol());
v.setGroupingSymbol(field.getGroupSymbol());
v.setCurrencySymbol(field.getCurrencySymbol());
v.setDateFormatLenient(dateFormatLenient);
v.setDateFormatLocale(dateFormatLocale);
v.setTrimType(field.getTrimType());
row.addValueMeta(v);
} catch (Exception e) {
throw new KettleStepException(e);
}
}
if (errorIgnored) {
if (errorCountField != null && errorCountField.length() > 0) {
ValueMetaInterface v = new ValueMetaInteger(errorCountField);
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
row.addValueMeta(v);
}
if (errorFieldsField != null && errorFieldsField.length() > 0) {
ValueMetaInterface v = new ValueMetaString(errorFieldsField);
v.setOrigin(name);
row.addValueMeta(v);
}
if (errorTextField != null && errorTextField.length() > 0) {
ValueMetaInterface v = new ValueMetaString(errorTextField);
v.setOrigin(name);
row.addValueMeta(v);
}
}
if (includeFilename) {
ValueMetaInterface v = new ValueMetaString(filenameField);
v.setLength(100);
v.setOrigin(name);
row.addValueMeta(v);
}
if (includeRowNumber) {
ValueMetaInterface v = new ValueMetaInteger(rowNumberField);
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
row.addValueMeta(v);
}
if (getShortFileNameField() != null && getShortFileNameField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getShortFileNameField()));
v.setLength(100, -1);
v.setOrigin(name);
row.addValueMeta(v);
}
if (getExtensionField() != null && getExtensionField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getExtensionField()));
v.setLength(100, -1);
v.setOrigin(name);
row.addValueMeta(v);
}
if (getPathField() != null && getPathField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getPathField()));
v.setLength(100, -1);
v.setOrigin(name);
row.addValueMeta(v);
}
if (getSizeField() != null && getSizeField().length() > 0) {
ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(getSizeField()));
v.setOrigin(name);
v.setLength(9);
row.addValueMeta(v);
}
if (isHiddenField() != null && isHiddenField().length() > 0) {
ValueMetaInterface v = new ValueMetaBoolean(space.environmentSubstitute(isHiddenField()));
v.setOrigin(name);
row.addValueMeta(v);
}
if (getLastModificationDateField() != null && getLastModificationDateField().length() > 0) {
ValueMetaInterface v = new ValueMetaDate(space.environmentSubstitute(getLastModificationDateField()));
v.setOrigin(name);
row.addValueMeta(v);
}
if (getUriField() != null && getUriField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getUriField()));
v.setLength(100, -1);
v.setOrigin(name);
row.addValueMeta(v);
}
if (getRootUriField() != null && getRootUriField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(getRootUriField());
v.setLength(100, -1);
v.setOrigin(name);
row.addValueMeta(v);
}
}
Aggregations