Search in sources :

Example 11 with ValueMetaTimestamp

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

the class GetVariableMetaTest method testGetValueMetaPlugin.

@Test
public void testGetValueMetaPlugin() throws KettleStepException {
    GetVariableMeta meta = new GetVariableMeta();
    meta.setDefault();
    FieldDefinition field = new FieldDefinition();
    field.setFieldName("outputField");
    field.setVariableString(String.valueOf(2000000L));
    field.setFieldType(ValueMetaInterface.TYPE_TIMESTAMP);
    meta.setFieldDefinitions(new FieldDefinition[] { field });
    RowMetaInterface rowMeta = new RowMeta();
    meta.getFields(rowMeta, "stepName", null, null, new Variables(), null, null);
    assertNotNull(rowMeta);
    assertEquals(1, rowMeta.size());
    assertEquals("outputField", rowMeta.getFieldNames()[0]);
    assertEquals(ValueMetaInterface.TYPE_TIMESTAMP, rowMeta.getValueMeta(0).getType());
    assertTrue(rowMeta.getValueMeta(0) instanceof ValueMetaTimestamp);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) RowMeta(org.pentaho.di.core.row.RowMeta) FieldDefinition(org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Test(org.junit.Test)

Example 12 with ValueMetaTimestamp

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

the class DimensionCacheTest method testCompareDateInterval.

@Test
public void testCompareDateInterval() {
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaTimestamp("DATE_FROM"));
    rowMeta.addValueMeta(new ValueMetaTimestamp("DATE_TO"));
    int[] keyIndexes = new int[] {};
    int fromDateIndex = 0;
    int toDateIndex = 1;
    DimensionCache dc = new DimensionCache(rowMeta, keyIndexes, fromDateIndex, toDateIndex);
    // (3/2/15 4:40 PM)
    long t0 = 1425300000000L;
    final Date D1 = new Timestamp(t0);
    final Date D2 = new Timestamp(t0 + 3600000L);
    final Date D3 = new Timestamp(t0 + 3600000L * 2);
    final Date D4 = new Timestamp(t0 + 3600000L * 3);
    final Date D5 = new Timestamp(t0 + 3600000L * 4);
    // [PDI-13508] NPE in DimensionCache class after update to Java 1.7u76
    // fix prevents NullPointerException in the combinations marked "NPE"
    assertCompareDateInterval(dc, null, null, null, null, 0);
    assertCompareDateInterval(dc, null, null, D1, null, -1);
    assertCompareDateInterval(dc, D2, null, null, null, 1);
    assertCompareDateInterval(dc, D2, null, D1, null, 1);
    assertCompareDateInterval(dc, D2, null, D2, null, 0);
    assertCompareDateInterval(dc, D2, null, D3, null, -1);
    // NPE
    assertCompareDateInterval(dc, D2, D4, null, null, 1);
    assertCompareDateInterval(dc, D2, D4, D1, null, 1);
    assertCompareDateInterval(dc, D2, D4, D2, null, 0);
    assertCompareDateInterval(dc, D2, D4, D3, null, 0);
    assertCompareDateInterval(dc, D2, D4, D4, null, -1);
    assertCompareDateInterval(dc, D2, D4, D5, null, -1);
    // NPE
    assertCompareDateInterval(dc, null, D4, null, null, 0);
    assertCompareDateInterval(dc, null, D4, D3, null, 0);
    // NPE
    assertCompareDateInterval(dc, null, D4, D4, null, -1);
    // NPE
    assertCompareDateInterval(dc, null, D4, D5, null, -1);
}
Also used : ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Timestamp(java.sql.Timestamp) ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) Date(java.util.Date) Test(org.junit.Test)

Example 13 with ValueMetaTimestamp

use of org.pentaho.di.core.row.value.ValueMetaTimestamp in project pentaho-cassandra-plugin by pentaho.

the class DriverCQLRowHandlerTest method testQueryRowsTimestamp.

@Test
public void testQueryRowsTimestamp() {
    Row row = mock(Row.class);
    when(row.getLong(0)).thenReturn(1L);
    when(row.getTimestamp(1)).thenReturn(new Date(1520538054000L));
    when(row.getDate(2)).thenReturn(LocalDate.fromYearMonthDay(2018, 03, 12));
    assertEquals(1L, DriverCQLRowHandler.readValue(new ValueMetaInteger("row"), row, 0));
    assertEquals(new Date(1520538054000L), DriverCQLRowHandler.readValue(new ValueMetaTimestamp("timestamp"), row, 1));
    assertEquals(LocalDate.fromYearMonthDay(2018, 03, 12), DriverCQLRowHandler.readValue(new ValueMetaDate("datestamp"), row, 2));
}
Also used : ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Row(com.datastax.driver.core.Row) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Date(java.util.Date) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) LocalDate(com.datastax.driver.core.LocalDate) Test(org.junit.Test)

Example 14 with ValueMetaTimestamp

use of org.pentaho.di.core.row.value.ValueMetaTimestamp 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 15 with ValueMetaTimestamp

use of org.pentaho.di.core.row.value.ValueMetaTimestamp 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)

Aggregations

ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)25 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)21 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)21 Test (org.junit.Test)19 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)18 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)18 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)16 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)15 ValueMetaInternetAddress (org.pentaho.di.core.row.value.ValueMetaInternetAddress)15 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)12 RowMeta (org.pentaho.di.core.row.RowMeta)7 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)7 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 ResultSet (java.sql.ResultSet)3 Timestamp (java.sql.Timestamp)3 Date (java.util.Date)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ResultSetMetaData (java.sql.ResultSetMetaData)2 SQLException (java.sql.SQLException)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2