Search in sources :

Example 96 with ValueMetaInterface

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;
}
Also used : RemoteStep(org.pentaho.di.trans.step.RemoteStep) RowMeta(org.pentaho.di.core.row.RowMeta) StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 97 with ValueMetaInterface

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);
        }
    }
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 98 with ValueMetaInterface

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);
            }
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Database(org.pentaho.di.core.database.Database) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 99 with ValueMetaInterface

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);
        }
    }
}
Also used : DatabaseImpact(org.pentaho.di.trans.DatabaseImpact) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 100 with ValueMetaInterface

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);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)908 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)345 KettleException (org.pentaho.di.core.exception.KettleException)269 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)243 RowMeta (org.pentaho.di.core.row.RowMeta)232 Test (org.junit.Test)212 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)146 KettleStepException (org.pentaho.di.core.exception.KettleStepException)120 ArrayList (java.util.ArrayList)111 TableItem (org.eclipse.swt.widgets.TableItem)78 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)76 KettleValueException (org.pentaho.di.core.exception.KettleValueException)58 FileObject (org.apache.commons.vfs2.FileObject)55 Date (java.util.Date)49 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)48 StepMeta (org.pentaho.di.trans.step.StepMeta)47 Database (org.pentaho.di.core.database.Database)46 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)46 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)44 TableItemInsertListener (org.pentaho.di.ui.trans.step.TableItemInsertListener)43