Search in sources :

Example 56 with ValueMetaNumber

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

the class KettleDatabaseRepositoryConnectionDelegate method insertStepAttribute.

public synchronized ObjectId insertStepAttribute(ObjectId id_transformation, ObjectId id_step, long nr, String code, double value_num, String value_str) throws KettleException {
    ObjectId id = getNextStepAttributeID();
    RowMetaAndData table = new RowMetaAndData();
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP_ATTRIBUTE), id);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_TRANSFORMATION), id_transformation);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_ID_STEP), id_step);
    table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_NR), new Long(nr));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_CODE), code);
    table.addValue(new ValueMetaNumber(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_VALUE_NUM), new Double(value_num));
    table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_STEP_ATTRIBUTE_VALUE_STR), value_str);
    if (psStepAttributesInsert == null) {
        String sql = database.getInsertStatement(KettleDatabaseRepository.TABLE_R_STEP_ATTRIBUTE, table.getRowMeta());
        psStepAttributesInsert = database.prepareSQL(sql);
    }
    database.setValues(table, psStepAttributesInsert);
    database.insertRow(psStepAttributesInsert, useBatchProcessing);
    if (log.isDebug()) {
        log.logDebug("saved attribute [" + code + "]");
    }
    return id;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 57 with ValueMetaNumber

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

the class ValueMetaTest method testNumberToStringToNumber.

@Test
public void testNumberToStringToNumber() throws Exception {
    ValueMetaInterface numValueMeta = new ValueMetaNumber("i");
    numValueMeta.setConversionMask(null);
    numValueMeta.setLength(7, 3);
    numValueMeta.setDecimalSymbol(",");
    numValueMeta.setGroupingSymbol(".");
    Double originalValue = new Double(123.456);
    String string = numValueMeta.getString(originalValue);
    assertEquals(" 0123,456", string);
    ValueMetaInterface strValueMeta = new ValueMeta("str", ValueMetaInterface.TYPE_STRING);
    strValueMeta.setConversionMetadata(numValueMeta);
    Double x = (Double) strValueMeta.convertDataUsingConversionMetaData(string);
    assertEquals(originalValue, x);
}
Also used : ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Test(org.junit.Test)

Example 58 with ValueMetaNumber

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

the class CacheDatabaseMetaTest method testSQLStatements.

@Test
public void testSQLStatements() {
    assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR VARCHAR(15) ) ", cdm.getAddColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR TIMESTAMP ) ", cdm.getAddColumnStatement("FOO", new ValueMetaDate("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR TIMESTAMP ) ", cdm.getAddColumnStatement("FOO", new ValueMetaTimestamp("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR CHAR(1) ) ", cdm.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR INT ) ", cdm.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 0, 0), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR DOUBLE ) ", // I believe this is a bug!
    cdm.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR DOUBLE ) ", cdm.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 10, -7), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR DOUBLE ) ", cdm.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", -10, 7), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR DECIMAL(5, 7) ) ", cdm.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 5, 7), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR  UNKNOWN ) ", cdm.getAddColumnStatement("FOO", new ValueMetaInternetAddress("BAR"), "", false, "", false));
    String lineSep = System.getProperty("line.separator");
    assertEquals("ALTER TABLE FOO DROP COLUMN BAR" + lineSep, cdm.getDropColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
    assertEquals("ALTER TABLE FOO ALTER COLUMN BAR VARCHAR(15)", cdm.getModifyColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
}
Also used : ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaInternetAddress(org.pentaho.di.core.row.value.ValueMetaInternetAddress) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 59 with ValueMetaNumber

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

the class DatabaseTest method testGetQueryFieldsFallback.

@Test
public void testGetQueryFieldsFallback() throws Exception {
    when(rsMetaData.getColumnCount()).thenReturn(1);
    when(rsMetaData.getColumnName(1)).thenReturn(columnName);
    when(rsMetaData.getColumnLabel(1)).thenReturn(columnName);
    when(rsMetaData.getColumnType(1)).thenReturn(Types.DECIMAL);
    when(ps.executeQuery()).thenReturn(rs);
    when(meta.stripCR(anyString())).thenReturn(sql);
    when(meta.getDatabaseInterface()).thenReturn(new MySQLDatabaseMeta());
    when(conn.prepareStatement(sql)).thenReturn(ps);
    when(rs.getMetaData()).thenReturn(rsMetaData);
    Database db = new Database(log, meta);
    db.setConnection(conn);
    RowMetaInterface rowMetaInterface = db.getQueryFieldsFallback(sql, false, null, null);
    assertEquals(rowMetaInterface.size(), 1);
    assertEquals(rowMetaInterface.getValueMeta(0).getName(), columnName);
    assertTrue(rowMetaInterface.getValueMeta(0) instanceof ValueMetaNumber);
}
Also used : ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Test(org.junit.Test)

Example 60 with ValueMetaNumber

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

the class Exasol4DatabaseMetaTest method testSQLStatements.

@Test
public void testSQLStatements() {
    assertEquals(" WHERE ROWNUM <= 15", nativeMeta.getLimitClause(15));
    assertEquals("SELECT /*+FIRST_ROWS*/ * FROM FOO WHERE 1=0", nativeMeta.getSQLQueryFields("FOO"));
    assertEquals("SELECT /*+FIRST_ROWS*/ * FROM FOO WHERE 1=0", nativeMeta.getSQLTableExists("FOO"));
    assertEquals("SELECT /*+FIRST_ROWS*/ FOO FROM BAR WHERE 1=0", nativeMeta.getSQLQueryColumnFields("FOO", "BAR"));
    assertEquals("SELECT /*+FIRST_ROWS*/ FOO FROM BAR WHERE 1=0", nativeMeta.getSQLColumnExists("FOO", "BAR"));
    String lineSep = System.getProperty("line.separator");
    assertEquals("ALTER TABLE FOO DROP COLUMN BAR" + lineSep, nativeMeta.getDropColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
    assertEquals("ALTER TABLE FOO ADD ( BAR TIMESTAMP ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaDate("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR TIMESTAMP ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaTimestamp("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR BOOLEAN ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL(15) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 15, 0), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL(15) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 15, 0), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL(15, 5) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 15, 5), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL(15, 5) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 15, 5), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR INTEGER ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR VARCHAR(15) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR VARCHAR(2000000) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", nativeMeta.getMaxVARCHARLength() + 15, 0), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR UNKNOWN ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInternetAddress("BAR"), "", false, "", false));
    assertEquals("ALTER TABLE FOO ADD ( BAR BIGINT NOT NULL PRIMARY KEY ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "BAR", false, "", false));
}
Also used : ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) ValueMetaInternetAddress(org.pentaho.di.core.row.value.ValueMetaInternetAddress) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Aggregations

ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)95 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)75 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)52 Test (org.junit.Test)51 RowMeta (org.pentaho.di.core.row.RowMeta)39 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)34 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)34 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)32 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)30 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)25 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)20 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)16 ValueMetaInternetAddress (org.pentaho.di.core.row.value.ValueMetaInternetAddress)15 KettleException (org.pentaho.di.core.exception.KettleException)12 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)11 KettleStepException (org.pentaho.di.core.exception.KettleStepException)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 RowSet (org.pentaho.di.core.RowSet)6 RowAdapter (org.pentaho.di.trans.step.RowAdapter)6