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;
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations