Search in sources :

Example 16 with ValueMetaNone

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;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) Savepoint(java.sql.Savepoint) KettleValueException(org.pentaho.di.core.exception.KettleValueException) BatchUpdateException(java.sql.BatchUpdateException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) KettleDatabaseBatchException(org.pentaho.di.core.exception.KettleDatabaseBatchException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) ParameterMetaData(java.sql.ParameterMetaData)

Example 17 with ValueMetaNone

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);
        }
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 18 with ValueMetaNone

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);
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

ValueMetaNone (org.pentaho.di.core.row.value.ValueMetaNone)18 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)17 RowMeta (org.pentaho.di.core.row.RowMeta)12 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)10 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)10 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)6 KettleException (org.pentaho.di.core.exception.KettleException)5 ArrayList (java.util.ArrayList)4 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)4 FileObject (org.apache.commons.vfs2.FileObject)3 TableItem (org.eclipse.swt.widgets.TableItem)3 SourceToTargetMapping (org.pentaho.di.core.SourceToTargetMapping)3 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)3 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)3 EnterMappingDialog (org.pentaho.di.ui.core.dialog.EnterMappingDialog)3 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)3 List (java.util.List)2 Map (java.util.Map)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2