Search in sources :

Example 16 with ValueMetaBigNumber

use of org.pentaho.di.core.row.value.ValueMetaBigNumber in project pentaho-kettle by pentaho.

the class DetectLastRowStepIT method createResultRowMetaInterface.

public RowMetaInterface createResultRowMetaInterface() {
    RowMetaInterface rm = new RowMeta();
    ValueMetaInterface[] valuesMeta = { new ValueMetaString("field1"), new ValueMetaInteger("field2"), new ValueMetaNumber("field3"), new ValueMetaBoolean("field5"), new ValueMetaBigNumber("field6"), new ValueMetaBoolean("result") };
    for (int i = 0; i < valuesMeta.length; i++) {
        rm.addValueMeta(valuesMeta[i]);
    }
    return rm;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 17 with ValueMetaBigNumber

use of org.pentaho.di.core.row.value.ValueMetaBigNumber in project pentaho-kettle by pentaho.

the class FormulaIT method getTestRowMetaAndData.

List<RowMetaAndData> getTestRowMetaAndData(BigDecimal[] value) {
    List<RowMetaAndData> list = new ArrayList<RowMetaAndData>();
    Object[] row = new Object[value.length];
    RowMetaInterface rm = new RowMeta();
    for (int i = 0; i < value.length; i++) {
        rm.addValueMeta(new ValueMetaBigNumber(keys[i]));
        row[i] = value[i];
    }
    list.add(new RowMetaAndData(rm, row));
    return list;
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface)

Example 18 with ValueMetaBigNumber

use of org.pentaho.di.core.row.value.ValueMetaBigNumber in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGeneratorTest method testTypeHandlingWithAvg.

@Test
public void testTypeHandlingWithAvg() throws KettleException {
    SQL sql = new SQL("SELECT avg( intVal ), avg( numericVal ), avg( bigNumber)  FROM table");
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaInteger("intVal"));
    rowMeta.addValueMeta(new ValueMetaNumber("numericVal"));
    rowMeta.addValueMeta(new ValueMetaBigNumber("bigNumber"));
    sql.parse(rowMeta);
    SqlTransGenerator generator = new SqlTransGenerator(sql, 0);
    SelectValuesMeta meta = (SelectValuesMeta) getStepByName(generator.generateTransMeta(), "Set Conversion");
    assertThat(meta.getMeta().length, is(3));
    // Integer should be converted to TYPE_NUMBER
    assertThat(meta.getMeta()[0].getType(), is(TYPE_NUMBER));
    // Other types should be left alone ( SelectMetadataChange.getType remains TYPE_NONE )
    assertThat(meta.getMeta()[1].getType(), is(TYPE_NONE));
    assertThat(meta.getMeta()[2].getType(), is(TYPE_NONE));
}
Also used : SelectValuesMeta(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 19 with ValueMetaBigNumber

use of org.pentaho.di.core.row.value.ValueMetaBigNumber in project pentaho-kettle by pentaho.

the class Database method getQueryFieldsFromDatabaseMetaData.

public RowMetaInterface getQueryFieldsFromDatabaseMetaData() throws Exception {
    ResultSet columns = connection.getMetaData().getColumns("", "", databaseMeta.getName(), "");
    RowMetaInterface rowMeta = new RowMeta();
    while (columns.next()) {
        ValueMetaInterface valueMeta = null;
        String name = columns.getString("COLUMN_NAME");
        String type = columns.getString("SOURCE_DATA_TYPE");
        int size = columns.getInt("COLUMN_SIZE");
        if (type.equals("Integer") || type.equals("Long")) {
            valueMeta = new ValueMetaInteger();
        } else if (type.equals("BigDecimal") || type.equals("BigNumber")) {
            valueMeta = new ValueMetaBigNumber();
        } else if (type.equals("Double") || type.equals("Number")) {
            valueMeta = new ValueMetaNumber();
        } else if (type.equals("String")) {
            valueMeta = new ValueMetaString();
        } else if (type.equals("Date")) {
            valueMeta = new ValueMetaDate();
        } else if (type.equals("Boolean")) {
            valueMeta = new ValueMetaBoolean();
        } else if (type.equals("Binary")) {
            valueMeta = new ValueMetaBinary();
        } else if (type.equals("Timestamp")) {
            valueMeta = new ValueMetaTimestamp();
        } else if (type.equals("Internet Address")) {
            valueMeta = new ValueMetaInternetAddress();
        }
        if (valueMeta != null) {
            valueMeta.setName(name);
            valueMeta.setComments(name);
            valueMeta.setLength(size);
            valueMeta.setOriginalColumnTypeName(type);
            valueMeta.setConversionMask(columns.getString("SOURCE_MASK"));
            valueMeta.setDecimalSymbol(columns.getString("SOURCE_DECIMAL_SYMBOL"));
            valueMeta.setGroupingSymbol(columns.getString("SOURCE_GROUPING_SYMBOL"));
            valueMeta.setCurrencySymbol(columns.getString("SOURCE_CURRENCY_SYMBOL"));
            rowMeta.addValueMeta(valueMeta);
        } else {
            log.logBasic("Database.getQueryFields() ValueMetaInterface mapping not resolved for the column " + name);
            rowMeta = null;
            break;
        }
    }
    if (rowMeta != null && !rowMeta.isEmpty()) {
        return rowMeta;
    } else {
        throw new Exception("Error in Database.getQueryFields()");
    }
}
Also used : ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaInternetAddress(org.pentaho.di.core.row.value.ValueMetaInternetAddress) 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) ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) ResultSet(java.sql.ResultSet) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate)

Example 20 with ValueMetaBigNumber

use of org.pentaho.di.core.row.value.ValueMetaBigNumber 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 e) {
        // Oops: probably the database or JDBC doesn't support it.
        return null;
    } catch (SQLException e) {
        return null;
    } catch (Exception e) {
        return null;
    }
    return par;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) SQLException(java.sql.SQLException) 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)

Aggregations

ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)34 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)31 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)30 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)28 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)25 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)23 RowMeta (org.pentaho.di.core.row.RowMeta)21 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)18 Test (org.junit.Test)17 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)15 ValueMetaInternetAddress (org.pentaho.di.core.row.value.ValueMetaInternetAddress)14 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)13 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)13 BigDecimal (java.math.BigDecimal)6 ArrayList (java.util.ArrayList)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 KettleException (org.pentaho.di.core.exception.KettleException)4 SQLException (java.sql.SQLException)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 BatchUpdateException (java.sql.BatchUpdateException)2