Search in sources :

Example 41 with ValueMetaString

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));
}
Also used : ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ByteArrayInputStream(java.io.ByteArrayInputStream) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DataInputStream(java.io.DataInputStream) Timestamp(java.sql.Timestamp) ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp)

Example 42 with ValueMetaString

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());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Random(java.util.Random) Date(java.util.Date) BigDecimal(java.math.BigDecimal) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 43 with ValueMetaString

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"));
}
Also used : ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) 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) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 44 with ValueMetaString

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);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Before(org.junit.Before)

Example 45 with ValueMetaString

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"));
}
Also used : ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) 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

ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)447 RowMeta (org.pentaho.di.core.row.RowMeta)219 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)181 Test (org.junit.Test)179 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)176 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)141 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)86 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)67 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)66 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)57 KettleException (org.pentaho.di.core.exception.KettleException)40 ArrayList (java.util.ArrayList)33 LongObjectId (org.pentaho.di.repository.LongObjectId)29 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)27 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)26 ObjectId (org.pentaho.di.repository.ObjectId)26 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)21 RowSet (org.pentaho.di.core.RowSet)18 Date (java.util.Date)17 ValueMetaBase (org.pentaho.di.core.row.value.ValueMetaBase)16