use of org.pentaho.di.core.row.value.ValueMetaTimestamp in project pentaho-kettle by pentaho.
the class PostgreSQLDatabaseMetaTest method testSQLStatements.
@Test
public void testSQLStatements() {
assertEquals("SELECT * FROM FOO limit 1", nativeMeta.getSQLQueryFields("FOO"));
assertEquals("SELECT * FROM FOO limit 1", nativeMeta.getSQLTableExists("FOO"));
assertEquals("SELECT FOO FROM BAR limit 1", nativeMeta.getSQLColumnExists("FOO", "BAR"));
assertEquals("SELECT FOO FROM BAR limit 1", nativeMeta.getSQLQueryColumnFields("FOO", "BAR"));
assertEquals("SELECT relname AS sequence_name FROM pg_catalog.pg_statio_all_sequences", nativeMeta.getSQLListOfSequences());
assertEquals("SELECT nextval('FOO')", nativeMeta.getSQLNextSequenceValue("FOO"));
assertEquals("SELECT currval('FOO')", nativeMeta.getSQLCurrentSequenceValue("FOO"));
assertEquals("SELECT relname AS sequence_name FROM pg_catalog.pg_statio_all_sequences WHERE relname = 'foo'", nativeMeta.getSQLSequenceExists("FOO"));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR TIMESTAMP", nativeMeta.getAddColumnStatement("FOO", new ValueMetaDate("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR TIMESTAMP", nativeMeta.getAddColumnStatement("FOO", new ValueMetaTimestamp("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR CHAR(1)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR BIGINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 10, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR BIGINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 10, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR BIGINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR", 10, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR DOUBLE PRECISION", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 0, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR INTEGER", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 5, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR NUMERIC(13, 3)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 10, 3), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR NUMERIC(13, 3)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 10, 3), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR NUMERIC(25, 4)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 21, 4), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR TEXT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", nativeMeta.getMaxVARCHARLength() + 2, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR VARCHAR(15)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR BIGINT", // Bug here - invalid SQL
nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 10, -7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR NUMERIC(29, 7)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 22, 7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR DOUBLE PRECISION", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", -10, 7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR NUMERIC(12, 7)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 5, 7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR UNKNOWN", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInternetAddress("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR BIGSERIAL", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "BAR", true, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR BIGSERIAL", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 26, 8), "BAR", true, "", false));
String lineSep = System.getProperty("line.separator");
assertEquals("ALTER TABLE FOO DROP COLUMN BAR", nativeMeta.getDropColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR_KTL VARCHAR(15);" + lineSep + "UPDATE FOO SET BAR_KTL=BAR;" + lineSep + "ALTER TABLE FOO DROP COLUMN BAR;" + lineSep + "ALTER TABLE FOO RENAME BAR_KTL TO BAR;" + lineSep, nativeMeta.getModifyColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
assertEquals("ALTER TABLE FOO ADD COLUMN BAR_KTL TEXT;" + lineSep + "UPDATE FOO SET BAR_KTL=BAR;" + lineSep + "ALTER TABLE FOO DROP COLUMN BAR;" + lineSep + "ALTER TABLE FOO RENAME BAR_KTL TO BAR;" + lineSep, nativeMeta.getModifyColumnStatement("FOO", new ValueMetaString("BAR"), "", false, "", true));
// some subclass of the MSSQL meta probably ...
odbcMeta.setSupportsBooleanDataType(true);
assertEquals("ALTER TABLE FOO ADD COLUMN BAR BOOLEAN", odbcMeta.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));
odbcMeta.setSupportsBooleanDataType(false);
assertEquals("ALTER TABLE FOO ADD COLUMN BAR SMALLINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR", 4, 0), "", true, "", false));
odbcMeta.setUsername("fOoUsEr");
assertEquals("select proname " + "from pg_proc, pg_user " + "where pg_user.usesysid = pg_proc.proowner " + "and upper(pg_user.usename) = 'FOOUSER' order by proname", odbcMeta.getSQLListOfProcedures());
assertEquals("LOCK TABLE FOO , BAR IN ACCESS EXCLUSIVE MODE;" + lineSep, nativeMeta.getSQLLockTables(new String[] { "FOO", "BAR" }));
assertNull(nativeMeta.getSQLUnlockTables(new String[] { "FOO" }));
}
use of org.pentaho.di.core.row.value.ValueMetaTimestamp in project pentaho-kettle by pentaho.
the class Vertica5DatabaseMetaTest method testOverridesToVerticaDatabaseMeta.
@Test
public void testOverridesToVerticaDatabaseMeta() throws Exception {
Vertica5DatabaseMeta nativeMeta = new Vertica5DatabaseMeta();
nativeMeta.setAccessType(DatabaseMeta.TYPE_ACCESS_NATIVE);
Vertica5DatabaseMeta odbcMeta = new Vertica5DatabaseMeta();
odbcMeta.setAccessType(DatabaseMeta.TYPE_ACCESS_ODBC);
assertEquals("com.vertica.jdbc.Driver", nativeMeta.getDriverClass());
assertEquals("sun.jdbc.odbc.JdbcOdbcDriver", odbcMeta.getDriverClass());
assertFalse(nativeMeta.supportsTimeStampToDateConversion());
ResultSet resultSet = Mockito.mock(ResultSet.class);
ResultSetMetaData metaData = Mockito.mock(ResultSetMetaData.class);
Mockito.when(resultSet.getMetaData()).thenReturn(metaData);
Mockito.when(resultSet.getTimestamp(1)).thenReturn(new java.sql.Timestamp(65535));
Mockito.when(resultSet.getTime(2)).thenReturn(new java.sql.Time(1000));
Mockito.when(resultSet.getDate(3)).thenReturn(new java.sql.Date((65535 * 2)));
ValueMetaTimestamp ts = new ValueMetaTimestamp("FOO");
ts.setOriginalColumnType(java.sql.Types.TIMESTAMP);
ValueMetaDate tm = new ValueMetaDate("BAR");
tm.setOriginalColumnType(java.sql.Types.TIME);
ValueMetaDate dt = new ValueMetaDate("WIBBLE");
dt.setOriginalColumnType(java.sql.Types.DATE);
Object rtn = null;
rtn = nativeMeta.getValueFromResultSet(resultSet, ts, 0);
assertNotNull(rtn);
assertEquals("java.sql.Timestamp", rtn.getClass().getName());
rtn = nativeMeta.getValueFromResultSet(resultSet, tm, 1);
assertNotNull(rtn);
assertEquals("java.sql.Time", rtn.getClass().getName());
rtn = nativeMeta.getValueFromResultSet(resultSet, dt, 2);
assertNotNull(rtn);
assertEquals("java.sql.Date", rtn.getClass().getName());
Mockito.when(resultSet.wasNull()).thenReturn(true);
rtn = nativeMeta.getValueFromResultSet(resultSet, new ValueMetaString("WOBBLE"), 3);
assertNull(rtn);
// Verify that getDate, getTime, and getTimestamp were respectively called once
Mockito.verify(resultSet, Mockito.times(1)).getDate(Mockito.anyInt());
Mockito.verify(resultSet, Mockito.times(1)).getTime(Mockito.anyInt());
Mockito.verify(resultSet, Mockito.times(1)).getTimestamp(Mockito.anyInt());
}
use of org.pentaho.di.core.row.value.ValueMetaTimestamp in project pentaho-kettle by pentaho.
the class JaninoStepIT method createRowMetaInterface.
public RowMetaInterface createRowMetaInterface() {
RowMetaInterface rm = new RowMeta();
ValueMetaInterface[] valuesMeta = { new ValueMetaString("string"), new ValueMetaInteger("integer"), new ValueMetaNumber("number"), new ValueMetaBigNumber("bigdecimal"), new ValueMetaDate("date"), new ValueMetaBinary("binary"), new ValueMetaBoolean("bool"), new ValueMetaTimestamp("timestamp"), new ValueMetaInternetAddress("inetaddress") };
for (int i = 0; i < valuesMeta.length; i++) {
rm.addValueMeta(valuesMeta[i]);
}
return rm;
}
use of org.pentaho.di.core.row.value.ValueMetaTimestamp in project pentaho-kettle by pentaho.
the class RowGeneratorIT method createRowMetaInterface.
public RowMetaInterface createRowMetaInterface() {
RowMetaInterface rm = new RowMeta();
ValueMetaInterface[] valuesMeta = { new ValueMetaString("string"), new ValueMetaBoolean("boolean"), new ValueMetaInteger("integer"), new ValueMetaTimestamp("timestamp") };
for (int i = 0; i < valuesMeta.length; i++) {
rm.addValueMeta(valuesMeta[i]);
}
return rm;
}
use of org.pentaho.di.core.row.value.ValueMetaTimestamp in project pentaho-kettle by pentaho.
the class SortRowsIT method createTimestampData.
List<RowMetaAndData> createTimestampData() {
// Create
long time = new Date().getTime();
List<RowMetaAndData> list = new ArrayList<RowMetaAndData>();
RowMetaInterface rm = createStringRowMetaInterface();
List<ValueMetaInterface> valueMetaList = new ArrayList<ValueMetaInterface>();
valueMetaList.add(new ValueMetaTimestamp("KEY1"));
valueMetaList.add(new ValueMetaTimestamp("KEY2"));
rm.setValueMetaList(valueMetaList);
Random rand = new Random();
for (int idx = 0; idx < MAX_COUNT; idx++) {
int key1 = Math.abs(rand.nextInt() % 10000);
int key2 = Math.abs(rand.nextInt() % 10000);
Object[] r1 = new Object[] { new Timestamp(time + key1), new Timestamp(time + key2) };
list.add(new RowMetaAndData(rm, r1));
}
return list;
}
Aggregations