Search in sources :

Example 6 with ValueMetaDate

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

the class NetezzaDatabaseMetaTest method testGetFieldDefinition.

@Test
public void testGetFieldDefinition() {
    assertEquals("FOO date", nativeMeta.getFieldDefinition(new ValueMetaDate("FOO"), null, null, false, true, false));
    assertEquals("boolean", nativeMeta.getFieldDefinition(new ValueMetaBoolean("FOO"), null, null, false, false, false));
    assertEquals("", nativeMeta.getFieldDefinition(new ValueMetaInteger("FOO", 0, 0), null, null, false, false, false));
    assertEquals("byteint", nativeMeta.getFieldDefinition(new ValueMetaNumber("FOO", 1, 0), null, null, false, false, false));
    assertEquals("byteint", nativeMeta.getFieldDefinition(new ValueMetaBigNumber("FOO", 2, 0), null, null, false, false, false));
    assertEquals("smallint", nativeMeta.getFieldDefinition(new ValueMetaInteger("FOO", 3, 0), null, null, false, false, false));
    assertEquals("smallint", nativeMeta.getFieldDefinition(new ValueMetaInteger("FOO", 4, 0), null, null, false, false, false));
    for (int i = 5; i < 10; i++) {
        assertEquals("integer", nativeMeta.getFieldDefinition(new ValueMetaInteger("FOO", i, 0), null, null, false, false, false));
    }
    assertEquals("bigint", nativeMeta.getFieldDefinition(new ValueMetaInteger("FOO", 10, 0), null, null, false, false, false));
    assertEquals("", nativeMeta.getFieldDefinition(new ValueMetaNumber("FOO", -22, 3), null, null, false, false, false));
    assertEquals("", nativeMeta.getFieldDefinition(new ValueMetaNumber("FOO", 0, 3), null, null, false, false, false));
    assertEquals("real", // pretty sure this is a bug ...
    nativeMeta.getFieldDefinition(new ValueMetaNumber("FOO", 1, 3), null, null, false, false, false));
    assertEquals("real", // pretty sure this is a bug ...
    nativeMeta.getFieldDefinition(new ValueMetaNumber("FOO", 2, 3), null, null, false, false, false));
    for (int i = 3; i < 9; i++) {
        assertEquals("real", nativeMeta.getFieldDefinition(new ValueMetaNumber("FOO", i, 3), null, null, false, false, false));
    }
    for (int i = 10; i < 18; i++) {
        assertEquals("double", nativeMeta.getFieldDefinition(new ValueMetaNumber("FOO", i, 3), null, null, false, false, false));
    }
    assertEquals("numeric(18, 3)", nativeMeta.getFieldDefinition(new ValueMetaNumber("FOO", 18, 3), null, null, false, false, false));
    assertEquals("numeric(19)", nativeMeta.getFieldDefinition(new ValueMetaNumber("FOO", 19, -12), null, null, false, false, false));
    assertEquals("varchar(32767)", nativeMeta.getFieldDefinition(new ValueMetaString("FOO", (NetezzaDatabaseMeta.MAX_CHAR_LEN + 2), 0), null, null, false, false, false));
    assertEquals("varchar(10)", nativeMeta.getFieldDefinition(new ValueMetaString("FOO", 10, 0), null, null, false, false, false));
    assertEquals(" UNKNOWN", nativeMeta.getFieldDefinition(new ValueMetaBinary("FOO", 10, 0), null, null, false, false, false));
    String lineSep = System.getProperty("line.separator");
    assertEquals(" UNKNOWN" + lineSep, nativeMeta.getFieldDefinition(new ValueMetaBinary("FOO", 10, 0), null, null, false, false, true));
}
Also used : 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) 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)

Example 7 with ValueMetaDate

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

the class RowMetaTest method testRowMetaInitializingFromXmlNode.

@Test
public void testRowMetaInitializingFromXmlNode() throws Exception {
    String testXmlNode = null;
    try (InputStream in = RowMetaTest.class.getResourceAsStream("rowMetaNode.xml")) {
        testXmlNode = IOUtils.toString(in);
    }
    Document xmlDoc = XMLHandler.loadXMLString(testXmlNode);
    RowMeta rowMeta = spy(new RowMeta(xmlDoc.getFirstChild()));
    assertEquals(2, rowMeta.getValueMetaList().size());
    ValueMetaInterface valueMeta = rowMeta.getValueMeta(0);
    assertTrue(valueMeta instanceof ValueMetaDate);
    assertEquals("testDate", valueMeta.getName());
    assertNull(valueMeta.getConversionMask());
    valueMeta = rowMeta.getValueMeta(1);
    assertTrue(valueMeta instanceof ValueMetaTimestamp);
    assertEquals("testTimestamp", valueMeta.getName());
    assertEquals("yyyy/MM/dd HH:mm:ss.000000000", valueMeta.getConversionMask());
}
Also used : ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) InputStream(java.io.InputStream) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Document(org.w3c.dom.Document) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 8 with ValueMetaDate

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

the class ValueDateUtilTest method shouldCalculateDateWorkingDiff_AUG.

@Test
public void shouldCalculateDateWorkingDiff_AUG() throws KettleValueException {
    ValueMetaInterface metaA = new ValueMetaDate();
    ValueMetaInterface metaB = new ValueMetaDate();
    Calendar startDate = Calendar.getInstance();
    Calendar endDate = Calendar.getInstance();
    // 2009-08-01 00:00:00
    startDate.setTimeInMillis(1249084800000L);
    // 2009-08-31 00:00:00
    endDate.setTimeInMillis(1251676800000L);
    Object workingDayOfAUG = ValueDataUtil.DateWorkingDiff(metaA, endDate.getTime(), metaB, startDate.getTime());
    assertEquals("Working days count in AUG ", 21L, workingDayOfAUG);
}
Also used : Calendar(java.util.Calendar) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 9 with ValueMetaDate

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

the class ValueDateUtilTest method shouldCalculateDateWorkingDiff_NOV.

@Test
public void shouldCalculateDateWorkingDiff_NOV() throws KettleValueException {
    ValueMetaInterface metaA = new ValueMetaDate();
    ValueMetaInterface metaB = new ValueMetaDate();
    Calendar startDate = Calendar.getInstance();
    Calendar endDate = Calendar.getInstance();
    // 2009-11-01 00:00:00
    startDate.setTimeInMillis(1257033600000L);
    // 2009-11-30 00:00:00
    endDate.setTimeInMillis(1259539200000L);
    Object workingDayOfNOV = ValueDataUtil.DateWorkingDiff(metaA, endDate.getTime(), metaB, startDate.getTime());
    assertEquals("Working days count in NOV ", 21L, workingDayOfNOV);
}
Also used : Calendar(java.util.Calendar) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 10 with ValueMetaDate

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

the class ValueDateUtilTest method shouldCalculateHourOfDayUsingValueMetasTimeZoneByDefault.

@Test
public void shouldCalculateHourOfDayUsingValueMetasTimeZoneByDefault() throws KettleValueException {
    Calendar date = Calendar.getInstance();
    // 2016-07-01 08:00:00 UTC
    date.setTimeInMillis(1454313600000L);
    ValueMetaInterface valueMetaDate = new ValueMetaDate();
    // UTC +1
    valueMetaDate.setDateFormatTimeZone(TimeZone.getTimeZone("CET"));
    long offsetCET = (long) TimeZone.getTimeZone("CET").getRawOffset() / 3600000;
    Object hourOfDayCET = ValueDataUtil.hourOfDay(valueMetaDate, date.getTime());
    assertEquals(8L + offsetCET, hourOfDayCET);
}
Also used : Calendar(java.util.Calendar) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Aggregations

ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)104 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)63 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)59 Test (org.junit.Test)50 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)44 RowMeta (org.pentaho.di.core.row.RowMeta)43 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)34 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)33 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)25 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)23 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)21 Calendar (java.util.Calendar)17 Date (java.util.Date)17 KettleException (org.pentaho.di.core.exception.KettleException)15 ValueMetaInternetAddress (org.pentaho.di.core.row.value.ValueMetaInternetAddress)15 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)14 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)13 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)10 KettleStepException (org.pentaho.di.core.exception.KettleStepException)10 SQLException (java.sql.SQLException)8