use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.
the class MergeRowsMeta method getFields.
@Override
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
//
if (info != null) {
boolean found = false;
for (int i = 0; i < info.length && !found; i++) {
if (info[i] != null) {
r.mergeRowMeta(info[i], name);
found = true;
}
}
}
if (Utils.isEmpty(flagField)) {
throw new KettleStepException(BaseMessages.getString(PKG, "MergeRowsMeta.Exception.FlagFieldNotSpecified"));
}
ValueMetaInterface flagFieldValue = new ValueMetaString(flagField);
flagFieldValue.setOrigin(name);
r.addValueMeta(flagFieldValue);
}
use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.
the class MondrianHelper method createRectangularOutput.
/**
* Outputs one row per tuple on the rows axis.
*
* @throws KettleDatabaseException
* in case some or other error occurs
*/
public void createRectangularOutput() throws KettleDatabaseException {
final Axis[] axes = result.getAxes();
if (axes.length != 2) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "MondrianInputErrorOnlyTabular"));
}
headings = new ArrayList<>();
rows = new ArrayList<>();
final Axis rowsAxis = axes[1];
final Axis columnsAxis = axes[0];
int rowOrdinal = -1;
int[] coords = { 0, 0 };
for (Position rowPos : rowsAxis.getPositions()) {
++rowOrdinal;
coords[1] = rowOrdinal;
if (rowOrdinal == 0) {
// First headings are for the members on the rows axis.
for (Member rowMember : rowPos) {
headings.add(rowMember.getHierarchy().getUniqueName());
}
// concatenate the unique names.
for (Position columnPos : columnsAxis.getPositions()) {
String heading = "";
for (Member columnMember : columnPos) {
if (!heading.equals("")) {
heading += ", ";
}
heading += columnMember.getUniqueName();
}
headings.add(heading);
}
}
List<Object> rowValues = new ArrayList<>();
// The first row values describe the members on the rows axis.
for (Member rowMember : rowPos) {
rowValues.add(rowMember.getUniqueName());
}
// NOTE: Could also output all properties of each cell.
for (int columnOrdinal = 0; columnOrdinal < columnsAxis.getPositions().size(); ++columnOrdinal) {
coords[0] = columnOrdinal;
final Cell cell = result.getCell(coords);
rowValues.add(cell.getValue());
}
rows.add(rowValues);
}
outputRowMeta = new RowMeta();
// column, keep scanning until we find one line that has an actual value
if (rows.size() > 0) {
int columnCount = rows.get(0).size();
HashMap<Integer, ValueMetaInterface> valueMetaHash = new HashMap<>();
for (int i = 0; i < rows.size(); i++) {
List<Object> rowValues = rows.get(i);
for (int c = 0; c < rowValues.size(); c++) {
if (valueMetaHash.containsKey(new Integer(c))) {
// we have this value already
continue;
}
Object valueData = rowValues.get(c);
if (valueData == null) {
// skip this row and look for the metadata in a new one
continue;
}
String valueName = headings.get(c);
ValueMetaInterface valueMeta;
if (valueData instanceof String) {
valueMeta = new ValueMetaString(valueName);
} else if (valueData instanceof Date) {
valueMeta = new ValueMetaDate(valueName);
} else if (valueData instanceof Boolean) {
valueMeta = new ValueMetaBoolean(valueName);
} else if (valueData instanceof Integer) {
valueMeta = new ValueMetaInteger(valueName);
valueData = Long.valueOf(((Integer) valueData).longValue());
} else if (valueData instanceof Short) {
valueMeta = new ValueMetaInteger(valueName);
valueData = Long.valueOf(((Short) valueData).longValue());
} else if (valueData instanceof Byte) {
valueMeta = new ValueMetaInteger(valueName);
valueData = Long.valueOf(((Byte) valueData).longValue());
} else if (valueData instanceof Long) {
valueMeta = new ValueMetaInteger(valueName);
} else if (valueData instanceof Double) {
valueMeta = new ValueMetaNumber(valueName);
} else if (valueData instanceof Float) {
valueMeta = new ValueMetaNumber(valueName);
valueData = Double.valueOf(((Float) valueData).doubleValue());
} else if (valueData instanceof BigDecimal) {
valueMeta = new ValueMetaBigNumber(valueName);
} else {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "MondrianInputErrorUnhandledType", valueData.getClass().toString()));
}
valueMetaHash.put(c, valueMeta);
}
if (valueMetaHash.size() == columnCount) {
// we're done
break;
}
}
// Build the list of valueMetas
List<ValueMetaInterface> valueMetaList = new ArrayList<>();
for (int c = 0; c < columnCount; c++) {
if (valueMetaHash.containsKey(new Integer(c))) {
valueMetaList.add(valueMetaHash.get(new Integer(c)));
} else {
// If the entire column is null, assume the missing data as String.
// Irrelevant, anyway
ValueMetaInterface valueMeta = new ValueMetaString(headings.get(c));
valueMetaList.add(valueMeta);
}
}
outputRowMeta.setValueMetaList(valueMetaList);
}
// Now that we painstakingly found the meta data that comes out of the
// Mondrian database, cache it please...
//
DBCacheEntry cacheEntry = new DBCacheEntry(databaseMeta.getName(), queryString);
DBCache.getInstance().put(cacheEntry, outputRowMeta);
}
use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.
the class NullIf method processRow.
@Override
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
meta = (NullIfMeta) smi;
data = (NullIfData) sdi;
// Get one row from one of the rowsets...
Object[] r = getRow();
if (r == null) {
// no more input to be expected...
setOutputDone();
return false;
}
if (first) {
first = false;
data.outputRowMeta = getInputRowMeta().clone();
int fieldsLength = meta.getFields().length;
data.keynr = new int[fieldsLength];
data.nullValue = new Object[fieldsLength];
data.nullValueMeta = new ValueMetaInterface[fieldsLength];
for (int i = 0; i < fieldsLength; i++) {
data.keynr[i] = data.outputRowMeta.indexOfValue(meta.getFields()[i].getFieldName());
if (data.keynr[i] < 0) {
logError(BaseMessages.getString(PKG, "NullIf.Log.CouldNotFindFieldInRow", meta.getFields()[i].getFieldName()));
setErrors(1);
stopAll();
return false;
}
data.nullValueMeta[i] = data.outputRowMeta.getValueMeta(data.keynr[i]);
// convert from input string entered by the user
ValueMetaString vms = new ValueMetaString();
vms.setConversionMask(data.nullValueMeta[i].getConversionMask());
data.nullValue[i] = data.nullValueMeta[i].convertData(vms, meta.getFields()[i].getFieldValue());
}
}
if (log.isRowLevel()) {
logRowlevel(BaseMessages.getString(PKG, "NullIf.Log.ConvertFieldValuesToNullForRow") + data.outputRowMeta.getString(r));
}
for (int i = 0; i < meta.getFields().length; i++) {
Object field = r[data.keynr[i]];
if (field != null && data.nullValueMeta[i].compare(field, data.nullValue[i]) == 0) {
// OK, this value needs to be set to NULL
r[data.keynr[i]] = null;
}
}
// Just one row!
putRow(data.outputRowMeta, r);
return true;
}
use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.
the class LDIFInputMeta method getFields.
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
int i;
for (i = 0; i < inputFields.length; i++) {
LDIFInputField field = inputFields[i];
int type = field.getType();
if (type == ValueMetaInterface.TYPE_NONE) {
type = ValueMetaInterface.TYPE_STRING;
}
try {
ValueMetaInterface v = ValueMetaFactory.createValueMeta(space.environmentSubstitute(field.getName()), type);
v.setLength(field.getLength(), field.getPrecision());
v.setOrigin(name);
r.addValueMeta(v);
} catch (Exception e) {
throw new KettleStepException(e);
}
}
if (includeFilename) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(filenameField));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeRowNumber) {
ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeContentType) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(contentTypeField));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeDN) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(DNField));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getShortFileNameField() != null && getShortFileNameField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getShortFileNameField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getExtensionField() != null && getExtensionField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getExtensionField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getPathField() != null && getPathField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getPathField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getSizeField() != null && getSizeField().length() > 0) {
ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(getSizeField()));
v.setOrigin(name);
v.setLength(9);
r.addValueMeta(v);
}
if (isHiddenField() != null && isHiddenField().length() > 0) {
ValueMetaInterface v = new ValueMetaBoolean(space.environmentSubstitute(isHiddenField()));
v.setOrigin(name);
r.addValueMeta(v);
}
if (getLastModificationDateField() != null && getLastModificationDateField().length() > 0) {
ValueMetaInterface v = new ValueMetaDate(space.environmentSubstitute(getLastModificationDateField()));
v.setOrigin(name);
r.addValueMeta(v);
}
if (getUriField() != null && getUriField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getUriField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getRootUriField() != null && getRootUriField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getRootUriField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
}
use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.
the class LoadFileInputMeta method getFields.
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
if (!getIsInFields()) {
r.clear();
}
int i;
for (i = 0; i < inputFields.length; i++) {
LoadFileInputField field = inputFields[i];
int type = field.getType();
switch(field.getElementType()) {
case LoadFileInputField.ELEMENT_TYPE_FILECONTENT:
if (type == ValueMetaInterface.TYPE_NONE) {
type = ValueMetaInterface.TYPE_STRING;
}
break;
case LoadFileInputField.ELEMENT_TYPE_FILESIZE:
if (type == ValueMetaInterface.TYPE_NONE) {
type = ValueMetaInterface.TYPE_INTEGER;
}
break;
default:
break;
}
try {
ValueMetaInterface v = ValueMetaFactory.createValueMeta(space.environmentSubstitute(field.getName()), type);
v.setLength(field.getLength());
v.setPrecision(field.getPrecision());
v.setConversionMask(field.getFormat());
v.setCurrencySymbol(field.getCurrencySymbol());
v.setDecimalSymbol(field.getDecimalSymbol());
v.setGroupingSymbol(field.getGroupSymbol());
v.setTrimType(field.getTrimType());
v.setOrigin(name);
r.addValueMeta(v);
} catch (Exception e) {
throw new KettleStepException(e);
}
}
if (includeFilename) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(filenameField));
v.setLength(250);
v.setPrecision(-1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeRowNumber) {
ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getShortFileNameField() != null && getShortFileNameField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getShortFileNameField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getExtensionField() != null && getExtensionField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getExtensionField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getPathField() != null && getPathField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getPathField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (isHiddenField() != null && isHiddenField().length() > 0) {
ValueMetaInterface v = new ValueMetaBoolean(space.environmentSubstitute(isHiddenField()));
v.setOrigin(name);
r.addValueMeta(v);
}
if (getLastModificationDateField() != null && getLastModificationDateField().length() > 0) {
ValueMetaInterface v = new ValueMetaDate(space.environmentSubstitute(getLastModificationDateField()));
v.setOrigin(name);
r.addValueMeta(v);
}
if (getUriField() != null && getUriField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getUriField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getRootUriField() != null && getRootUriField().length() > 0) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getRootUriField()));
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
}
Aggregations