Search in sources :

Example 56 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class CubeInputMeta method getFields.

public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    GZIPInputStream fis = null;
    DataInputStream dis = null;
    try {
        InputStream is = KettleVFS.getInputStream(space.environmentSubstitute(filename), space);
        fis = new GZIPInputStream(is);
        dis = new DataInputStream(fis);
        RowMetaInterface add = new RowMeta(dis);
        for (int i = 0; i < add.size(); i++) {
            add.getValueMeta(i).setOrigin(name);
        }
        r.mergeRowMeta(add);
    } catch (KettleFileException kfe) {
        throw new KettleStepException(BaseMessages.getString(PKG, "CubeInputMeta.Exception.UnableToReadMetaData"), kfe);
    } catch (IOException e) {
        throw new KettleStepException(BaseMessages.getString(PKG, "CubeInputMeta.Exception.ErrorOpeningOrReadingCubeFile"), e);
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
            if (dis != null) {
                dis.close();
            }
        } catch (IOException ioe) {
            throw new KettleStepException(BaseMessages.getString(PKG, "CubeInputMeta.Exception.UnableToCloseCubeFile"), ioe);
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) DataInputStream(java.io.DataInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 57 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class DatabaseJoin method lookupValues.

private synchronized void lookupValues(RowMetaInterface rowMeta, Object[] rowData) throws KettleException {
    if (first) {
        first = false;
        data.outputRowMeta = rowMeta.clone();
        meta.getFields(data.outputRowMeta, getStepname(), new RowMetaInterface[] { meta.getTableFields() }, null, this, repository, metaStore);
        data.lookupRowMeta = new RowMeta();
        if (log.isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "DatabaseJoin.Log.CheckingRow") + rowMeta.getString(rowData));
        }
        data.keynrs = new int[meta.getParameterField().length];
        for (int i = 0; i < meta.getParameterField().length; i++) {
            data.keynrs[i] = rowMeta.indexOfValue(meta.getParameterField()[i]);
            if (data.keynrs[i] < 0) {
                throw new KettleStepException(BaseMessages.getString(PKG, "DatabaseJoin.Exception.FieldNotFound", meta.getParameterField()[i]));
            }
            data.lookupRowMeta.addValueMeta(rowMeta.getValueMeta(data.keynrs[i]).clone());
        }
    }
    // Construct the parameters row...
    Object[] lookupRowData = new Object[data.lookupRowMeta.size()];
    for (int i = 0; i < data.keynrs.length; i++) {
        lookupRowData[i] = rowData[data.keynrs[i]];
    }
    // Set the values on the prepared statement (for faster exec.)
    ResultSet rs = data.db.openQuery(data.pstmt, data.lookupRowMeta, lookupRowData);
    // Get a row from the database...
    // 
    Object[] add = data.db.getRow(rs);
    RowMetaInterface addMeta = data.db.getReturnRowMeta();
    incrementLinesInput();
    int counter = 0;
    while (add != null && (meta.getRowLimit() == 0 || counter < meta.getRowLimit())) {
        counter++;
        Object[] newRow = RowDataUtil.resizeArray(rowData, data.outputRowMeta.size());
        int newIndex = rowMeta.size();
        for (int i = 0; i < addMeta.size(); i++) {
            newRow[newIndex++] = add[i];
        }
        // we have to clone, otherwise we only get the last new value
        putRow(data.outputRowMeta, data.outputRowMeta.cloneRow(newRow));
        if (log.isRowLevel()) {
            logRowlevel(BaseMessages.getString(PKG, "DatabaseJoin.Log.PutoutRow") + data.outputRowMeta.getString(newRow));
        }
        // Get a new row
        if (meta.getRowLimit() == 0 || counter < meta.getRowLimit()) {
            add = data.db.getRow(rs);
            incrementLinesInput();
        }
    }
    // Nothing found? Perhaps we have to put something out after all?
    if (counter == 0 && meta.isOuterJoin()) {
        if (data.notfound == null) {
            // Just return null values for all values...
            // 
            data.notfound = new Object[data.db.getReturnRowMeta().size()];
        }
        Object[] newRow = RowDataUtil.resizeArray(rowData, data.outputRowMeta.size());
        int newIndex = rowMeta.size();
        for (int i = 0; i < data.notfound.length; i++) {
            newRow[newIndex++] = data.notfound[i];
        }
        putRow(data.outputRowMeta, newRow);
    }
    data.db.closeQuery(rs);
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) ResultSet(java.sql.ResultSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface)

Example 58 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class DatabaseLookupMeta method getFields.

@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    if (Utils.isEmpty(info) || info[0] == null) {
        // null or length 0 : no info from database
        for (int i = 0; i < getReturnValueNewName().length; i++) {
            try {
                ValueMetaInterface v = ValueMetaFactory.createValueMeta(getReturnValueNewName()[i], getReturnValueDefaultType()[i]);
                v.setOrigin(name);
                row.addValueMeta(v);
            } catch (Exception e) {
                throw new KettleStepException(e);
            }
        }
    } else {
        for (int i = 0; i < returnValueNewName.length; i++) {
            ValueMetaInterface v = info[0].searchValueMeta(returnValueField[i]);
            if (v != null) {
                // avoid renaming other value meta - PDI-9844
                ValueMetaInterface copy = v.clone();
                copy.setName(returnValueNewName[i]);
                copy.setOrigin(name);
                row.addValueMeta(copy);
            }
        }
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 59 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class DataGridMeta method getFields.

@Override
public void getFields(RowMetaInterface rowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    for (int i = 0; i < fieldName.length; i++) {
        try {
            if (!Utils.isEmpty(fieldName[i])) {
                int type = ValueMetaFactory.getIdForValueMeta(fieldType[i]);
                if (type == ValueMetaInterface.TYPE_NONE) {
                    type = ValueMetaInterface.TYPE_STRING;
                }
                ValueMetaInterface v = ValueMetaFactory.createValueMeta(fieldName[i], type);
                v.setLength(fieldLength[i]);
                v.setPrecision(fieldPrecision[i]);
                v.setOrigin(name);
                v.setConversionMask(fieldFormat[i]);
                v.setCurrencySymbol(currency[i]);
                v.setGroupingSymbol(group[i]);
                v.setDecimalSymbol(decimal[i]);
                rowMeta.addValueMeta(v);
            }
        } catch (Exception e) {
            throw new KettleStepException("Unable to create value of type " + fieldType[i], e);
        }
    }
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) 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)

Example 60 with KettleStepException

use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.

the class DBProc method runProc.

private Object[] runProc(RowMetaInterface rowMeta, Object[] rowData) throws KettleException {
    if (first) {
        first = false;
        // get the RowMeta for the output
        // 
        data.outputMeta = data.inputRowMeta.clone();
        meta.getFields(data.outputMeta, getStepname(), null, null, this, repository, metaStore);
        data.argnrs = new int[meta.getArgument().length];
        for (int i = 0; i < meta.getArgument().length; i++) {
            if (!meta.getArgumentDirection()[i].equalsIgnoreCase("OUT")) {
                // IN or INOUT
                data.argnrs[i] = rowMeta.indexOfValue(meta.getArgument()[i]);
                if (data.argnrs[i] < 0) {
                    logError(BaseMessages.getString(PKG, "DBProc.Log.ErrorFindingField") + meta.getArgument()[i] + "]");
                    throw new KettleStepException(BaseMessages.getString(PKG, "DBProc.Exception.CouldnotFindField", meta.getArgument()[i]));
                }
            } else {
                data.argnrs[i] = -1;
            }
        }
        data.db.setProcLookup(environmentSubstitute(meta.getProcedure()), meta.getArgument(), meta.getArgumentDirection(), meta.getArgumentType(), meta.getResultName(), meta.getResultType());
    }
    Object[] outputRowData = RowDataUtil.resizeArray(rowData, data.outputMeta.size());
    int outputIndex = rowMeta.size();
    data.db.setProcValues(rowMeta, rowData, data.argnrs, meta.getArgumentDirection(), !Utils.isEmpty(meta.getResultName()));
    RowMetaAndData add = data.db.callProcedure(meta.getArgument(), meta.getArgumentDirection(), meta.getArgumentType(), meta.getResultName(), meta.getResultType());
    int addIndex = 0;
    // Function return?
    if (!Utils.isEmpty(meta.getResultName())) {
        // first is the function return
        outputRowData[outputIndex++] = add.getData()[addIndex++];
    }
    // 
    for (int i = 0; i < data.argnrs.length; i++) {
        if (meta.getArgumentDirection()[i].equalsIgnoreCase("OUT")) {
            // add
            outputRowData[outputIndex++] = add.getData()[addIndex++];
        } else if (meta.getArgumentDirection()[i].equalsIgnoreCase("INOUT")) {
            // replace
            outputRowData[data.argnrs[i]] = add.getData()[addIndex];
            addIndex++;
        }
    // IN not taken
    }
    return outputRowData;
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData)

Aggregations

KettleStepException (org.pentaho.di.core.exception.KettleStepException)235 KettleException (org.pentaho.di.core.exception.KettleException)139 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)103 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)97 RowMeta (org.pentaho.di.core.row.RowMeta)51 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)44 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)27 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)27 KettleValueException (org.pentaho.di.core.exception.KettleValueException)26 IOException (java.io.IOException)23 RowAdapter (org.pentaho.di.trans.step.RowAdapter)21 ArrayList (java.util.ArrayList)20 StepMeta (org.pentaho.di.trans.step.StepMeta)19 RowSet (org.pentaho.di.core.RowSet)18 Database (org.pentaho.di.core.database.Database)15 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)13 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)13 FormAttachment (org.eclipse.swt.layout.FormAttachment)12 FormData (org.eclipse.swt.layout.FormData)12 Button (org.eclipse.swt.widgets.Button)12