Search in sources :

Example 46 with ValueMetaInterface

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

the class Formula method convertDataToTargetValueMeta.

private Object convertDataToTargetValueMeta(int i, Object formulaResult) throws KettleException {
    if (formulaResult == null) {
        return formulaResult;
    }
    ValueMetaInterface target = data.outputRowMeta.getValueMeta(i);
    ValueMetaInterface actual = ValueMetaFactory.guessValueMetaInterface(formulaResult);
    Object value = target.convertData(actual, formulaResult);
    return value;
}
Also used : ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 47 with ValueMetaInterface

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

the class RowForumulaContext method resolveReference.

/**
 * We return the content of a Value with the given name. We cache the position of the field indexes.
 *
 * @see org.jfree.formula.FormulaContext#resolveReference(java.lang.Object)
 */
public Object resolveReference(Object name) throws EvaluationException {
    if (name instanceof String) {
        ValueMetaInterface valueMeta;
        Integer idx = valueIndexMap.get(name);
        if (idx != null) {
            valueMeta = rowMeta.getValueMeta(idx.intValue());
        } else {
            int index = rowMeta.indexOfValue((String) name);
            if (index < 0) {
                ErrorValue errorValue = new LibFormulaErrorValue(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT);
                throw new EvaluationException(errorValue);
            }
            valueMeta = rowMeta.getValueMeta(index);
            idx = new Integer(index);
            valueIndexMap.put((String) name, idx);
        }
        Object valueData = rowData[idx];
        try {
            return getPrimitive(valueMeta, valueData);
        } catch (KettleValueException e) {
            throw new EvaluationException(LibFormulaErrorValue.ERROR_ARITHMETIC_VALUE);
        }
    }
    return null;
}
Also used : LibFormulaErrorValue(org.pentaho.reporting.libraries.formula.LibFormulaErrorValue) LibFormulaErrorValue(org.pentaho.reporting.libraries.formula.LibFormulaErrorValue) ErrorValue(org.pentaho.reporting.libraries.formula.ErrorValue) EvaluationException(org.pentaho.reporting.libraries.formula.EvaluationException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 48 with ValueMetaInterface

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

the class FixedInput method processRow.

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (FixedInputMeta) smi;
    data = (FixedInputData) sdi;
    if (first) {
        first = false;
        data.outputRowMeta = new RowMeta();
        meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
        // The conversion logic for when the lazy conversion is turned of is simple:
        // Pretend it's a lazy conversion object anyway and get the native type during conversion.
        // 
        data.convertRowMeta = data.outputRowMeta.clone();
        for (ValueMetaInterface valueMeta : data.convertRowMeta.getValueMetaList()) {
            valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
        }
        if (meta.isHeaderPresent()) {
            // skip this row.
            readOneRow(false);
        }
    }
    Object[] outputRowData = readOneRow(true);
    if (outputRowData == null) {
        // no more input to be expected...
        setOutputDone();
        return false;
    }
    // copy row to possible alternate rowset(s).
    putRow(data.outputRowMeta, outputRowData);
    if (checkFeedback(getLinesInput())) {
        logBasic(BaseMessages.getString(PKG, "FixedInput.Log.LineNumber", Long.toString(getLinesInput())));
    }
    return true;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) FileObject(org.apache.commons.vfs2.FileObject) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 49 with ValueMetaInterface

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

the class FixedInput method readOneRow.

/**
 * Read a single row of data from the file...
 *
 * @param doConversions
 *          if you want to do conversions, set to false for the header row.
 * @return a row of data...
 * @throws KettleException
 */
private Object[] readOneRow(boolean doConversions) throws KettleException {
    try {
        // 
        if (meta.isRunningInParallel()) {
            if (getLinesInput() >= data.rowsToRead) {
                // We're done. The rest is for the other steps in the cluster
                return null;
            }
        }
        Object[] outputRowData = RowDataUtil.allocateRowData(data.convertRowMeta.size());
        int outputIndex = 0;
        if (data.stopReading) {
            return null;
        }
        FixedFileInputField[] fieldDefinitions = meta.getFieldDefinition();
        for (int i = 0; i < fieldDefinitions.length; i++) {
            int fieldWidth = fieldDefinitions[i].getWidth();
            data.endBuffer = data.startBuffer + fieldWidth;
            if (data.endBuffer > data.bufferSize) {
                // Oops, we need to read more data...
                // Better resize this before we read other things in it...
                // 
                data.resizeByteBuffer();
                // Also read another chunk of data, now that we have the space for it...
                // Ignore EOF, there might be other stuff in the buffer.
                // 
                data.readBufferFromFile();
            }
            // 
            if (data.endBuffer > data.bufferSize) {
                // a row because we're done.
                if ((0 == i) && data.bufferSize <= 0) {
                    return null;
                }
                // This is the last record of data in the file.
                data.stopReading = true;
                // Just take what's left for the current field.
                fieldWidth = data.bufferSize;
            }
            byte[] field = new byte[fieldWidth];
            System.arraycopy(data.byteBuffer, data.startBuffer, field, 0, fieldWidth);
            if (doConversions) {
                if (meta.isLazyConversionActive()) {
                    outputRowData[outputIndex++] = field;
                } else {
                    // We're not lazy so we convert the data right here and now.
                    // The convert object uses binary storage as such we just have to ask the native type from it.
                    // That will do the actual conversion.
                    // 
                    ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(outputIndex);
                    outputRowData[outputIndex++] = sourceValueMeta.convertBinaryStringToNativeType(field);
                }
            } else {
                // nothing for the header, no conversions here.
                outputRowData[outputIndex++] = null;
            }
            // OK, onto the next field...
            // 
            data.startBuffer = data.endBuffer;
        }
        // 
        if (meta.isLineFeedPresent()) {
            data.endBuffer += 2;
            if (data.endBuffer >= data.bufferSize) {
                // Oops, we need to read more data...
                // Better resize this before we read other things in it...
                // 
                data.resizeByteBuffer();
                // Also read another chunk of data, now that we have the space for it...
                data.readBufferFromFile();
            }
            // 
            if (data.byteBuffer[data.startBuffer] == '\n' || data.byteBuffer[data.startBuffer] == '\r') {
                data.startBuffer++;
                if (data.byteBuffer[data.startBuffer] == '\n' || data.byteBuffer[data.startBuffer] == '\r') {
                    data.startBuffer++;
                }
            }
            data.endBuffer = data.startBuffer;
        }
        incrementLinesInput();
        return outputRowData;
    } catch (Exception e) {
        throw new KettleFileException("Exception reading line using NIO: " + e.toString(), e);
    }
}
Also used : KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileObject(org.apache.commons.vfs2.FileObject) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 50 with ValueMetaInterface

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

the class GetSlaveSequenceMeta method getFields.

@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    ValueMetaInterface v = new ValueMetaInteger(valuename);
    v.setOrigin(name);
    row.addValueMeta(v);
}
Also used : ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) 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