use of org.pentaho.di.core.row.value.ValueMetaInteger 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.ValueMetaInteger in project pentaho-kettle by pentaho.
the class LDAPInputMeta method getFields.
@Override
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++) {
LDAPInputField 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 (includeRowNumber) {
ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
r.addValueMeta(v);
}
}
use of org.pentaho.di.core.row.value.ValueMetaInteger 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.ValueMetaInteger 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);
}
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class CheckSumMeta method getFields.
@Override
public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
// Output field (String)
if (!Utils.isEmpty(resultfieldName)) {
ValueMetaInterface v = null;
if (checksumtype.equals(TYPE_CRC32) || checksumtype.equals(TYPE_ADLER32)) {
v = new ValueMetaInteger(space.environmentSubstitute(resultfieldName));
} else {
switch(resultType) {
case result_TYPE_BINARY:
v = new ValueMetaBinary(space.environmentSubstitute(resultfieldName));
break;
default:
v = new ValueMetaString(space.environmentSubstitute(resultfieldName));
break;
}
}
v.setOrigin(name);
inputRowMeta.addValueMeta(v);
}
}
Aggregations