Search in sources :

Example 91 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class DataGrid method processRow.

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    if (data.linesWritten >= meta.getDataLines().size()) {
        // no more rows to be written
        setOutputDone();
        return false;
    }
    if (first) {
        // The output meta is the original input meta + the
        // additional constant fields.
        first = false;
        data.linesWritten = 0;
        data.outputRowMeta = new RowMeta();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
        // Use these metadata values to convert data...
        // 
        data.convertMeta = data.outputRowMeta.cloneToType(ValueMetaInterface.TYPE_STRING);
    }
    Object[] outputRowData = RowDataUtil.allocateRowData(data.outputRowMeta.size());
    List<String> outputLine = meta.getDataLines().get(data.linesWritten);
    for (int i = 0; i < data.outputRowMeta.size(); i++) {
        if (meta.isSetEmptyString()[i]) {
            // Set empty string
            outputRowData[i] = StringUtil.EMPTY_STRING;
        } else {
            ValueMetaInterface valueMeta = data.outputRowMeta.getValueMeta(i);
            ValueMetaInterface convertMeta = data.convertMeta.getValueMeta(i);
            String valueData = outputLine.get(i);
            if (valueData != null && valueMeta.isNull(valueData)) {
                valueData = null;
            }
            outputRowData[i] = valueMeta.convertDataFromString(valueData, convertMeta, null, null, 0);
        }
    }
    putRow(data.outputRowMeta, outputRowData);
    data.linesWritten++;
    if (log.isRowLevel()) {
        log.logRowlevel(toString(), BaseMessages.getString(PKG, "DataGrid.Log.Wrote.Row", Long.toString(getLinesWritten()), data.outputRowMeta.getString(outputRowData)));
    }
    if (checkFeedback(getLinesWritten())) {
        if (log.isBasic()) {
            logBasic(BaseMessages.getString(PKG, "DataGrid.Log.LineNr", Long.toString(getLinesWritten())));
        }
    }
    return true;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 92 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class DBProc method processRow.

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (DBProcMeta) smi;
    data = (DBProcData) sdi;
    boolean sendToErrorRow = false;
    String errorMessage = null;
    // A procedure/function could also have no input at all
    // However, we would still need to know how many times it gets executed.
    // In short: the procedure gets executed once for every input row.
    // 
    Object[] r;
    if (data.readsRows) {
        // Get row from input rowset & set row busy!
        r = getRow();
        if (r == null) {
            // no more input to be expected...
            setOutputDone();
            return false;
        }
        data.inputRowMeta = getInputRowMeta();
    } else {
        // empty row
        r = new Object[] {};
        incrementLinesRead();
        // empty row metadata too
        data.inputRowMeta = new RowMeta();
        // make it drop out of the loop at the next entrance to this method
        data.readsRows = true;
    }
    try {
        // add new values to the row in rowset[0].
        Object[] outputRowData = runProc(data.inputRowMeta, r);
        // copy row to output rowset(s);
        putRow(data.outputMeta, outputRowData);
        if (checkFeedback(getLinesRead())) {
            if (log.isBasic()) {
                logBasic(BaseMessages.getString(PKG, "DBProc.LineNumber") + getLinesRead());
            }
        }
    } catch (KettleException e) {
        if (getStepMeta().isDoingErrorHandling()) {
            sendToErrorRow = true;
            errorMessage = e.toString();
            // CHE: Read the chained SQL exceptions and add them
            // to the errorMessage
            SQLException nextSQLExOnChain = null;
            if ((e.getCause() != null) && (e.getCause() instanceof SQLException)) {
                nextSQLExOnChain = ((SQLException) e.getCause()).getNextException();
                while (nextSQLExOnChain != null) {
                    errorMessage = errorMessage + nextSQLExOnChain.getMessage() + Const.CR;
                    nextSQLExOnChain = nextSQLExOnChain.getNextException();
                }
            }
        } else {
            logError(BaseMessages.getString(PKG, "DBProc.ErrorInStepRunning") + e.getMessage());
            setErrors(1);
            stopAll();
            // signal end to receiver(s)
            setOutputDone();
            return false;
        }
        if (sendToErrorRow) {
            // Simply add this row to the error row
            putError(getInputRowMeta(), r, 1, errorMessage, null, "DBP001");
        }
    }
    return true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMeta(org.pentaho.di.core.row.RowMeta) SQLException(java.sql.SQLException)

Example 93 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class GetFileNames method init.

public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
    meta = (GetFileNamesMeta) smi;
    data = (GetFileNamesData) sdi;
    if (super.init(smi, sdi)) {
        // Set Embedded NamedCluter MetatStore Provider Key so that it can be passed to VFS
        if (getTransMeta().getNamedClusterEmbedManager() != null) {
            getTransMeta().getNamedClusterEmbedManager().passEmbeddedMetastoreKey(this, getTransMeta().getEmbeddedMetastoreProviderKey());
        }
        try {
            // Create the output row meta-data
            data.outputRowMeta = new RowMeta();
            // get the
            meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
            // metadata
            // populated
            data.nrStepFields = data.outputRowMeta.size();
            if (!meta.isFileField()) {
                data.files = meta.getFileList(this);
                data.filessize = data.files.nrOfFiles();
                handleMissingFiles();
            } else {
                data.filessize = 0;
            }
        } catch (Exception e) {
            logError("Error initializing step: " + e.toString());
            logError(Const.getStackTracker(e));
            return false;
        }
        data.rownr = 1L;
        data.filenr = 0;
        data.totalpreviousfields = 0;
        return true;
    }
    return false;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) KettleStepException(org.pentaho.di.core.exception.KettleStepException)

Example 94 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class GetFilesRowsCount method init.

public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
    meta = (GetFilesRowsCountMeta) smi;
    data = (GetFilesRowsCountData) sdi;
    if (super.init(smi, sdi)) {
        // Set Embedded NamedCluter MetatStore Provider Key so that it can be passed to VFS
        if (getTransMeta().getNamedClusterEmbedManager() != null) {
            getTransMeta().getNamedClusterEmbedManager().passEmbeddedMetastoreKey(this, getTransMeta().getEmbeddedMetastoreProviderKey());
        }
        if ((meta.getRowSeparatorFormat().equals("CUSTOM")) && (Utils.isEmpty(meta.getRowSeparator()))) {
            logError(BaseMessages.getString(PKG, "GetFilesRowsCount.Error.NoSeparator.Title"), BaseMessages.getString(PKG, "GetFilesRowsCount.Error.NoSeparator.Msg"));
            setErrors(1);
            stopAll();
        } else {
            // Checking for 'LF' for backwards compatibility.
            if (meta.getRowSeparatorFormat().equals("CARRIAGERETURN") || meta.getRowSeparatorFormat().equals("LF")) {
                data.separator = '\r';
                if (isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "GetFilesRowsCount.Log.Separator.Title"), BaseMessages.getString(PKG, "GetFilesRowsCount.Log.Separatoris.Infos") + " \\n");
                }
            } else if (meta.getRowSeparatorFormat().equals("LINEFEED") || meta.getRowSeparatorFormat().equals("CR")) {
                // Checking for 'CR' for backwards compatibility.
                data.separator = '\n';
                if (isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "GetFilesRowsCount.Log.Separator.Title"), BaseMessages.getString(PKG, "GetFilesRowsCount.Log.Separatoris.Infos") + " \\r");
                }
            } else if (meta.getRowSeparatorFormat().equals("TAB")) {
                data.separator = '\t';
                if (isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "GetFilesRowsCount.Log.Separator.Title"), BaseMessages.getString(PKG, "GetFilesRowsCount.Log.Separatoris.Infos") + " \\t");
                }
            } else if (meta.getRowSeparatorFormat().equals("CRLF")) {
                if (isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "GetFilesRowsCount.Log.Separator.Title"), BaseMessages.getString(PKG, "GetFilesRowsCount.Log.Separatoris.Infos") + " \\r\\n");
                }
            } else {
                data.separator = environmentSubstitute(meta.getRowSeparator()).charAt(0);
                if (isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "GetFilesRowsCount.Log.Separator.Title"), BaseMessages.getString(PKG, "GetFilesRowsCount.Log.Separatoris.Infos") + " " + data.separator);
                }
            }
        }
        if (!meta.isFileField()) {
            data.files = meta.getFiles(this);
            if (data.files == null || data.files.nrOfFiles() == 0) {
                logError(BaseMessages.getString(PKG, "GetFilesRowsCount.Log.NoFiles"));
                return false;
            }
            try {
                // Create the output row meta-data
                data.outputRowMeta = new RowMeta();
                // get the
                meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
            // metadata
            // populated
            } catch (Exception e) {
                logError("Error initializing step: " + e.toString());
                logError(Const.getStackTracker(e));
                return false;
            }
        }
        data.rownr = 0;
        data.filenr = 0;
        data.totalpreviousfields = 0;
        return true;
    }
    return false;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) KettleException(org.pentaho.di.core.exception.KettleException)

Example 95 with RowMeta

use of org.pentaho.di.core.row.RowMeta in project pentaho-kettle by pentaho.

the class GetTableNames method init.

public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
    meta = (GetTableNamesMeta) smi;
    data = (GetTableNamesData) sdi;
    if (super.init(smi, sdi)) {
        if (Utils.isEmpty(meta.getTablenameFieldName())) {
            logError(BaseMessages.getString(PKG, "GetTableNames.Error.TablenameFieldNameMissing"));
            return false;
        }
        String realSchemaName = environmentSubstitute(meta.getSchemaName());
        if (!Utils.isEmpty(realSchemaName)) {
            data.realSchemaName = realSchemaName;
        }
        data.realTableNameFieldName = environmentSubstitute(meta.getTablenameFieldName());
        data.realObjectTypeFieldName = environmentSubstitute(meta.getObjectTypeFieldName());
        data.realIsSystemObjectFieldName = environmentSubstitute(meta.isSystemObjectFieldName());
        data.realSQLCreationFieldName = environmentSubstitute(meta.getSQLCreationFieldName());
        if (!meta.isIncludeCatalog() && !meta.isIncludeSchema() && !meta.isIncludeTable() && !meta.isIncludeView() && !meta.isIncludeProcedure() && !meta.isIncludeSynonym()) {
            logError(BaseMessages.getString(PKG, "GetTableNames.Error.includeAtLeastOneType"));
            return false;
        }
        try {
            // Create the output row meta-data
            data.outputRowMeta = new RowMeta();
            // get the
            meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
        // metadata
        // populated
        } catch (Exception e) {
            logError("Error initializing step: " + e.toString());
            logError(Const.getStackTracker(e));
            return false;
        }
        data.db = new Database(this, meta.getDatabase());
        data.db.shareVariablesWith(this);
        try {
            if (getTransMeta().isUsingUniqueConnections()) {
                synchronized (getTrans()) {
                    data.db.connect(getTrans().getTransactionId(), getPartitionID());
                }
            } else {
                data.db.connect(getPartitionID());
            }
            if (log.isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "GetTableNames.Log.ConnectedToDB"));
            }
            return true;
        } catch (KettleException e) {
            logError(BaseMessages.getString(PKG, "GetTableNames.Log.DBException") + e.getMessage());
            if (data.db != null) {
                data.db.disconnect();
            }
        }
    }
    return false;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMeta(org.pentaho.di.core.row.RowMeta) Database(org.pentaho.di.core.database.Database) KettleException(org.pentaho.di.core.exception.KettleException)

Aggregations

RowMeta (org.pentaho.di.core.row.RowMeta)540 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)280 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)249 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)209 Test (org.junit.Test)174 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)135 KettleException (org.pentaho.di.core.exception.KettleException)112 ArrayList (java.util.ArrayList)68 KettleStepException (org.pentaho.di.core.exception.KettleStepException)56 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)52 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)44 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)41 RowSet (org.pentaho.di.core.RowSet)34 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)27 ValueMetaBase (org.pentaho.di.core.row.value.ValueMetaBase)26 SQLException (java.sql.SQLException)24 FileObject (org.apache.commons.vfs2.FileObject)24 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)23 StepMeta (org.pentaho.di.trans.step.StepMeta)23 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)23