use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.
the class RowTest method makeTestExtractDataWithTimestampConversion.
private void makeTestExtractDataWithTimestampConversion(RowMetaInterface rowMeta, String str, Date date, Timestamp constTimestamp) throws KettleEOFException, KettleFileException, IOException {
Object[] rowData = new Object[] { str, date };
byte[] result = RowMeta.extractData(rowMeta, rowData);
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(result));
String extractedString = (String) new ValueMetaString().readData(stream);
Timestamp time = (Timestamp) new ValueMetaTimestamp().readData(stream);
stream.close();
assertTrue(str.equals(extractedString));
assertTrue(constTimestamp.equals(time));
}
use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.
the class ValueMetaAndDataTest method testConstructors.
@Test
public void testConstructors() throws KettleValueException {
ValueMetaAndData result;
result = new ValueMetaAndData(new ValueMetaString("ValueStringName"), "testValue1");
assertNotNull(result);
assertEquals(ValueMetaInterface.TYPE_STRING, result.getValueMeta().getType());
assertEquals("ValueStringName", result.getValueMeta().getName());
assertEquals("testValue1", result.getValueData());
result = new ValueMetaAndData("StringName", "testValue2");
assertNotNull(result);
assertEquals(ValueMetaInterface.TYPE_STRING, result.getValueMeta().getType());
assertEquals("StringName", result.getValueMeta().getName());
assertEquals("testValue2", result.getValueData());
result = new ValueMetaAndData("NumberName", Double.valueOf("123.45"));
assertNotNull(result);
assertEquals(ValueMetaInterface.TYPE_NUMBER, result.getValueMeta().getType());
assertEquals("NumberName", result.getValueMeta().getName());
assertEquals(Double.valueOf("123.45"), result.getValueData());
result = new ValueMetaAndData("IntegerName", Long.valueOf(234));
assertNotNull(result);
assertEquals(ValueMetaInterface.TYPE_INTEGER, result.getValueMeta().getType());
assertEquals("IntegerName", result.getValueMeta().getName());
assertEquals(Long.valueOf(234), result.getValueData());
Date testDate = Calendar.getInstance().getTime();
result = new ValueMetaAndData("DateName", testDate);
assertNotNull(result);
assertEquals(ValueMetaInterface.TYPE_DATE, result.getValueMeta().getType());
assertEquals("DateName", result.getValueMeta().getName());
assertEquals(testDate, result.getValueData());
result = new ValueMetaAndData("BigNumberName", new BigDecimal("123456789.987654321"));
assertNotNull(result);
assertEquals(ValueMetaInterface.TYPE_BIGNUMBER, result.getValueMeta().getType());
assertEquals("BigNumberName", result.getValueMeta().getName());
assertEquals(new BigDecimal("123456789.987654321"), result.getValueData());
result = new ValueMetaAndData("BooleanName", Boolean.TRUE);
assertNotNull(result);
assertEquals(ValueMetaInterface.TYPE_BOOLEAN, result.getValueMeta().getType());
assertEquals("BooleanName", result.getValueMeta().getName());
assertEquals(Boolean.TRUE, result.getValueData());
byte[] testBytes = new byte[50];
new Random().nextBytes(testBytes);
result = new ValueMetaAndData("BinaryName", testBytes);
assertNotNull(result);
assertEquals(ValueMetaInterface.TYPE_BINARY, result.getValueMeta().getType());
assertEquals("BinaryName", result.getValueMeta().getName());
assertArrayEquals(testBytes, (byte[]) result.getValueData());
result = new ValueMetaAndData("SerializableName", new StringBuilder("serializable test"));
assertNotNull(result);
assertEquals(ValueMetaInterface.TYPE_SERIALIZABLE, result.getValueMeta().getType());
assertEquals("SerializableName", result.getValueMeta().getName());
assertTrue(result.getValueData() instanceof StringBuilder);
assertEquals("serializable test", result.getValueData().toString());
}
use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.
the class RowMetaAndDataTest method testEmptyValues.
@Test
public void testEmptyValues() throws Exception {
RowMeta rowsMetaEmpty = new RowMeta();
rowsMetaEmpty.addValueMeta(new ValueMetaString("str"));
rowsMetaEmpty.addValueMeta(new ValueMetaBoolean("bool"));
rowsMetaEmpty.addValueMeta(new ValueMetaInteger("int"));
rowsMetaEmpty.addValueMeta(new ValueMetaNumber("num"));
rowsMetaEmpty.addValueMeta(new ValueMetaBigNumber("bignum"));
rowsMetaEmpty.addValueMeta(new ValueMetaBinary("bin"));
rowsMetaEmpty.addValueMeta(new ValueMetaDate("date"));
rowsMetaEmpty.addValueMeta(new ValueMetaTimestamp("timestamp"));
rowsMetaEmpty.addValueMeta(new ValueMetaInternetAddress("inet"));
row = new RowMetaAndData(rowsMetaEmpty, null, null, null, null, null, null, null, null, null);
assertTrue(row.isEmptyValue("str"));
assertTrue(row.isEmptyValue("bool"));
assertTrue(row.isEmptyValue("int"));
assertTrue(row.isEmptyValue("num"));
assertTrue(row.isEmptyValue("bignum"));
assertTrue(row.isEmptyValue("bin"));
assertTrue(row.isEmptyValue("date"));
assertTrue(row.isEmptyValue("timestamp"));
assertTrue(row.isEmptyValue("inet"));
}
use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.
the class RowMetaAndDataTest method prepare.
@Before
public void prepare() throws Exception {
rowsMeta = new RowMeta();
ValueMetaInterface valueMetaString = new ValueMetaString("str");
rowsMeta.addValueMeta(valueMetaString);
ValueMetaInterface valueMetaBoolean = new ValueMetaBoolean("bool");
rowsMeta.addValueMeta(valueMetaBoolean);
ValueMetaInterface valueMetaInteger = new ValueMetaInteger("int");
rowsMeta.addValueMeta(valueMetaInteger);
}
use of org.pentaho.di.core.row.value.ValueMetaString in project pentaho-kettle by pentaho.
the class DerbyDatabaseMetaTest method testSQLStatements.
@Test
public void testSQLStatements() {
assertEquals("DELETE FROM FOO", nativeMeta.getTruncateTableStatement("FOO"));
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 CHAR(1)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BIGINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 10, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BIGINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 10, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BIGINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR", 10, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR SMALLINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 0, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR INTEGER", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 5, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR FLOAT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 10, 3), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR FLOAT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 10, 3), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR DECIMAL(21, 4)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 21, 4), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR CLOB", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", nativeMeta.getMaxVARCHARLength() + 2, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BLOB", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBinary("BAR", nativeMeta.getMaxVARCHARLength() + 2, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BLOB", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBinary("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BLOB", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBinary("BAR", 200, 0), "", 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 FLOAT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 10, -7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR DECIMAL(22, 7)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 22, 7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR FLOAT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", -10, 7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR FLOAT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 5, 7), "", 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 GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "BAR", true, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BIGINT NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 0, INCREMENT BY 1)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 26, 8), "BAR", true, "", false));
String lineSep = System.getProperty("line.separator");
assertEquals("ALTER TABLE FOO DROP BAR" + lineSep, nativeMeta.getDropColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
assertEquals("ALTER TABLE FOO ALTER BAR VARCHAR(15)", nativeMeta.getModifyColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
assertEquals("insert into FOO(FOOVERSION) values (1)", nativeMeta.getSQLInsertAutoIncUnknownDimensionRow("FOO", "FOOKEY", "FOOVERSION"));
}
Aggregations