use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-kettle by pentaho.
the class Database method getParameterMetaData.
public RowMetaInterface getParameterMetaData(PreparedStatement ps) {
RowMetaInterface par = new RowMeta();
try {
ParameterMetaData pmd = ps.getParameterMetaData();
for (int i = 1; i <= pmd.getParameterCount(); i++) {
String name = "par" + i;
int sqltype = pmd.getParameterType(i);
int length = pmd.getPrecision(i);
int precision = pmd.getScale(i);
ValueMetaInterface val;
switch(sqltype) {
case java.sql.Types.CHAR:
case java.sql.Types.VARCHAR:
val = new ValueMetaString(name);
break;
case java.sql.Types.BIGINT:
case java.sql.Types.INTEGER:
case java.sql.Types.NUMERIC:
case java.sql.Types.SMALLINT:
case java.sql.Types.TINYINT:
val = new ValueMetaInteger(name);
break;
case java.sql.Types.DECIMAL:
case java.sql.Types.DOUBLE:
case java.sql.Types.FLOAT:
case java.sql.Types.REAL:
val = new ValueMetaNumber(name);
break;
case java.sql.Types.DATE:
case java.sql.Types.TIME:
case java.sql.Types.TIMESTAMP:
val = new ValueMetaDate(name);
break;
case java.sql.Types.BOOLEAN:
case java.sql.Types.BIT:
val = new ValueMetaBoolean(name);
break;
default:
val = new ValueMetaNone(name);
break;
}
if (val.isNumeric() && (length > 18 || precision > 18)) {
val = new ValueMetaBigNumber(name);
}
par.addValueMeta(val);
}
} catch (AbstractMethodError | Exception e) {
return null;
}
return par;
}
use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-kettle by pentaho.
the class JobExecutorMeta method getFields.
@Override
public void getFields(RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
row.clear();
if (nextStep != null && resultRowsTargetStepMeta != null && nextStep.equals(resultRowsTargetStepMeta)) {
for (int i = 0; i < resultRowsField.length; i++) {
ValueMetaInterface value;
try {
value = ValueMetaFactory.createValueMeta(resultRowsField[i], resultRowsType[i], resultRowsLength[i], resultRowsPrecision[i]);
} catch (KettlePluginException e) {
value = new ValueMetaNone(resultRowsField[i]);
value.setLength(resultRowsLength[i], resultRowsPrecision[i]);
}
row.addValueMeta(value);
}
} else if (nextStep != null && resultFilesTargetStepMeta != null && nextStep.equals(resultFilesTargetStepMeta)) {
if (!Utils.isEmpty(resultFilesFileNameField)) {
ValueMetaInterface value = new ValueMetaString("filename", 255, 0);
row.addValueMeta(value);
}
} else if (nextStep != null && executionResultTargetStepMeta != null && nextStep.equals(executionResultTargetStepMeta)) {
if (!Utils.isEmpty(executionTimeField)) {
ValueMetaInterface value = new ValueMetaInteger(executionTimeField, 15, 0);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionResultField)) {
ValueMetaInterface value = new ValueMetaBoolean(executionResultField);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionNrErrorsField)) {
ValueMetaInterface value = new ValueMetaInteger(executionNrErrorsField, 9, 0);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionLinesReadField)) {
ValueMetaInterface value = new ValueMetaInteger(executionLinesReadField, 9, 0);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionLinesWrittenField)) {
ValueMetaInterface value = new ValueMetaInteger(executionLinesWrittenField, 9, 0);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionLinesInputField)) {
ValueMetaInterface value = new ValueMetaInteger(executionLinesInputField, 9, 0);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionLinesOutputField)) {
ValueMetaInterface value = new ValueMetaInteger(executionLinesOutputField, 9, 0);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionLinesRejectedField)) {
ValueMetaInterface value = new ValueMetaInteger(executionLinesRejectedField, 9, 0);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionLinesUpdatedField)) {
ValueMetaInterface value = new ValueMetaInteger(executionLinesUpdatedField, 9, 0);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionLinesDeletedField)) {
ValueMetaInterface value = new ValueMetaInteger(executionLinesDeletedField, 9, 0);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionFilesRetrievedField)) {
ValueMetaInterface value = new ValueMetaInteger(executionFilesRetrievedField, 9, 0);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionExitStatusField)) {
ValueMetaInterface value = new ValueMetaInteger(executionExitStatusField, 3, 0);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionLogTextField)) {
ValueMetaInterface value = new ValueMetaString(executionLogTextField);
value.setLargeTextField(true);
row.addValueMeta(value);
}
if (!Utils.isEmpty(executionLogChannelIdField)) {
ValueMetaInterface value = new ValueMetaString(executionLogChannelIdField, 50, 0);
row.addValueMeta(value);
}
}
}
use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-kettle by pentaho.
the class GroupByMeta method getFields.
@Override
public void getFields(RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) {
// re-assemble a new row of metadata
//
RowMetaInterface fields = new RowMeta();
if (!passAllRows) {
//
for (int i = 0; i < groupField.length; i++) {
ValueMetaInterface valueMeta = rowMeta.searchValueMeta(groupField[i]);
if (valueMeta != null) {
fields.addValueMeta(valueMeta);
}
}
} else {
// Add all the original fields from the incoming row meta
//
fields.addRowMeta(rowMeta);
}
//
for (int i = 0; i < subjectField.length; i++) {
ValueMetaInterface subj = rowMeta.searchValueMeta(subjectField[i]);
if (subj != null || aggregateType[i] == TYPE_GROUP_COUNT_ANY) {
String valueName = aggregateField[i];
int valueType = ValueMetaInterface.TYPE_NONE;
int length = -1;
int precision = -1;
switch(aggregateType[i]) {
case TYPE_GROUP_SUM:
case TYPE_GROUP_AVERAGE:
case TYPE_GROUP_CUMULATIVE_SUM:
case TYPE_GROUP_CUMULATIVE_AVERAGE:
case TYPE_GROUP_FIRST:
case TYPE_GROUP_LAST:
case TYPE_GROUP_FIRST_INCL_NULL:
case TYPE_GROUP_LAST_INCL_NULL:
case TYPE_GROUP_MIN:
case TYPE_GROUP_MAX:
valueType = subj.getType();
break;
case TYPE_GROUP_COUNT_DISTINCT:
case TYPE_GROUP_COUNT_ANY:
case TYPE_GROUP_COUNT_ALL:
valueType = ValueMetaInterface.TYPE_INTEGER;
break;
case TYPE_GROUP_CONCAT_COMMA:
valueType = ValueMetaInterface.TYPE_STRING;
break;
case TYPE_GROUP_STANDARD_DEVIATION:
case TYPE_GROUP_MEDIAN:
case TYPE_GROUP_STANDARD_DEVIATION_SAMPLE:
case TYPE_GROUP_PERCENTILE:
case TYPE_GROUP_PERCENTILE_NEAREST_RANK:
valueType = ValueMetaInterface.TYPE_NUMBER;
break;
case TYPE_GROUP_CONCAT_STRING:
valueType = ValueMetaInterface.TYPE_STRING;
break;
default:
break;
}
//
if (aggregateType[i] == TYPE_GROUP_CUMULATIVE_AVERAGE && valueType == ValueMetaInterface.TYPE_INTEGER) {
valueType = ValueMetaInterface.TYPE_NUMBER;
precision = -1;
length = -1;
} else if (aggregateType[i] == TYPE_GROUP_COUNT_ALL || aggregateType[i] == TYPE_GROUP_COUNT_DISTINCT || aggregateType[i] == TYPE_GROUP_COUNT_ANY) {
length = ValueMetaInterface.DEFAULT_INTEGER_LENGTH;
precision = 0;
} else if (aggregateType[i] == TYPE_GROUP_SUM && valueType != ValueMetaInterface.TYPE_INTEGER && valueType != ValueMetaInterface.TYPE_NUMBER && valueType != ValueMetaInterface.TYPE_BIGNUMBER) {
// If it ain't numeric, we change it to Number
//
valueType = ValueMetaInterface.TYPE_NUMBER;
precision = -1;
length = -1;
}
if (valueType != ValueMetaInterface.TYPE_NONE) {
ValueMetaInterface v;
try {
v = ValueMetaFactory.createValueMeta(valueName, valueType);
} catch (KettlePluginException e) {
v = new ValueMetaNone(valueName);
}
v.setOrigin(origin);
v.setLength(length, precision);
if (subj != null) {
v.setConversionMask(subj.getConversionMask());
}
fields.addValueMeta(v);
}
}
}
if (passAllRows) {
// If we pass all rows, we can add a line nr in the group...
if (addingLineNrInGroup && !Utils.isEmpty(lineNrInGroupField)) {
ValueMetaInterface lineNr = new ValueMetaInteger(lineNrInGroupField);
lineNr.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
lineNr.setOrigin(origin);
fields.addValueMeta(lineNr);
}
}
// Now that we have all the fields we want, we should clear the original row and replace the values...
//
rowMeta.clear();
rowMeta.addRowMeta(fields);
}
Aggregations