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);
}
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);
}
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));
}
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()");
}
}
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));
}
Aggregations