Search in sources :

Example 81 with ValueMetaDate

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

the class ValueDateUtilTest method shouldCalculateDateWorkingDiff_JUL.

@Test
public void shouldCalculateDateWorkingDiff_JUL() throws KettleValueException {
    ValueMetaInterface metaA = new ValueMetaDate();
    ValueMetaInterface metaB = new ValueMetaDate();
    Calendar startDate = Calendar.getInstance();
    Calendar endDate = Calendar.getInstance();
    // 2009-07-01 00:00:00
    startDate.setTimeInMillis(1246406400000L);
    // 2009-07-31 00:00:00
    endDate.setTimeInMillis(1248998400000L);
    Object workingDayOfJUL = ValueDataUtil.DateWorkingDiff(metaA, endDate.getTime(), metaB, startDate.getTime());
    assertEquals("Working days count in JUL ", 23L, workingDayOfJUL);
}
Also used : Calendar(java.util.Calendar) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 82 with ValueMetaDate

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

the class ValueDateUtilTest method shouldCalculateDateWorkingDiff_SEP.

@Test
public void shouldCalculateDateWorkingDiff_SEP() throws KettleValueException {
    ValueMetaInterface metaA = new ValueMetaDate();
    ValueMetaInterface metaB = new ValueMetaDate();
    Calendar startDate = Calendar.getInstance();
    Calendar endDate = Calendar.getInstance();
    // 2009-09-01 00:00:00
    startDate.setTimeInMillis(1251763200000L);
    // 2009-09-30 00:00:00
    endDate.setTimeInMillis(1254268800000L);
    Object workingDayOfSEP = ValueDataUtil.DateWorkingDiff(metaA, endDate.getTime(), metaB, startDate.getTime());
    assertEquals("Working days count in SEP ", 22L, workingDayOfSEP);
}
Also used : Calendar(java.util.Calendar) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 83 with ValueMetaDate

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

the class ValueDateUtilTest method shouldCalculateHourOfDayUsingLocalTimeZoneIfPropertyIsSet.

@Test
public void shouldCalculateHourOfDayUsingLocalTimeZoneIfPropertyIsSet() 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 offsetLocal = (long) TimeZone.getDefault().getRawOffset() / 3600000;
    System.setProperty(Const.KETTLE_COMPATIBILITY_CALCULATION_TIMEZONE_DECOMPOSITION, "true");
    Object hourOfDayLocal = ValueDataUtil.hourOfDay(valueMetaDate, date.getTime());
    assertEquals(8L + offsetLocal, hourOfDayLocal);
}
Also used : Calendar(java.util.Calendar) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 84 with ValueMetaDate

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

the class ValueDateUtilTest method shouldCalculateDateWorkingDiff_OCT.

@Test
public void shouldCalculateDateWorkingDiff_OCT() throws KettleValueException {
    ValueMetaInterface metaA = new ValueMetaDate();
    ValueMetaInterface metaB = new ValueMetaDate();
    Calendar startDate = Calendar.getInstance();
    Calendar endDate = Calendar.getInstance();
    // 2009-10-01 00:00:00
    startDate.setTimeInMillis(1254355200000L);
    // 2009-10-31 00:00:00
    endDate.setTimeInMillis(1256947200000L);
    Object workingDayOfOCT = ValueDataUtil.DateWorkingDiff(metaA, endDate.getTime(), metaB, startDate.getTime());
    assertEquals("Working days count in OCT ", 22L, workingDayOfOCT);
}
Also used : Calendar(java.util.Calendar) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 85 with ValueMetaDate

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

the class MemoryGroupByAggregationTest method testDefault.

@Test
public void testDefault() throws Exception {
    addColumn(new ValueMetaInteger("intg"), 0L, 1L, 1L, 10L);
    addColumn(new ValueMetaInteger("nul"));
    addColumn(new ValueMetaInteger("mix1"), -1L, 2L);
    addColumn(new ValueMetaInteger("mix2"), null, 7L);
    addColumn(new ValueMetaNumber("mix3"), -1.0, 2.5);
    addColumn(new ValueMetaDate("date1"), new Date(1L), new Date(2L));
    RowMetaAndData output = runStep();
    assertThat(output.getInteger("intg_min"), is(0L));
    assertThat(output.getInteger("intg_max"), is(10L));
    assertThat(output.getInteger("intg_sum"), is(12L));
    assertThat(output.getInteger("intg_ave"), is(3L));
    assertThat(output.getInteger("intg_count"), is(4L));
    assertThat(output.getInteger("intg_count_any"), is(4L));
    assertThat(output.getInteger("intg_count_distinct"), is(3L));
    assertThat(output.getInteger("nul_min"), nullValue());
    assertThat(output.getInteger("nul_max"), nullValue());
    assertThat(output.getInteger("nul_sum"), nullValue());
    assertThat(output.getInteger("nul_ave"), nullValue());
    assertThat(output.getInteger("nul_count"), is(0L));
    assertThat(output.getInteger("nul_count_any"), is(4L));
    assertThat(output.getInteger("nul_count_distinct"), is(0L));
    assertThat(output.getInteger("mix1_max"), is(2L));
    assertThat(output.getInteger("mix1_min"), is(-1L));
    assertThat(output.getInteger("mix1_sum"), is(1L));
    assertThat(output.getInteger("mix1_ave"), is(0L));
    assertThat(output.getInteger("mix1_count"), is(2L));
    assertThat(output.getInteger("mix1_count_any"), is(4L));
    assertThat(output.getInteger("mix1_count_distinct"), is(2L));
    assertThat(output.getInteger("mix2_max"), is(7L));
    assertThat(output.getInteger("mix2_min"), is(7L));
    assertThat(output.getInteger("mix2_sum"), is(7L));
    assertThat(output.getNumber("mix2_ave", Double.NaN), is(7.0));
    assertThat(output.getInteger("mix2_count"), is(1L));
    assertThat(output.getInteger("mix2_count_any"), is(4L));
    assertThat(output.getInteger("mix2_count_distinct"), is(1L));
    assertThat(output.getNumber("mix3_max", Double.NaN), is(2.5));
    assertThat(output.getNumber("mix3_min", Double.NaN), is(-1.0));
    assertThat(output.getNumber("mix3_sum", Double.NaN), is(1.5));
    assertThat(output.getNumber("mix3_ave", Double.NaN), is(0.75));
    assertThat(output.getInteger("mix3_count"), is(2L));
    assertThat(output.getInteger("mix3_count_any"), is(4L));
    assertThat(output.getInteger("mix3_count_distinct"), is(2L));
    assertThat(output.getNumber("date1_min", Double.NaN), is(1.0));
    assertThat(output.getNumber("date1_max", Double.NaN), is(2.0));
    assertThat(output.getNumber("date1_sum", Double.NaN), is(3.0));
    assertThat(output.getNumber("date1_ave", Double.NaN), is(1.5));
    assertThat(output.getInteger("date1_count"), is(2L));
    assertThat(output.getInteger("date1_count_any"), is(4L));
    assertThat(output.getInteger("date1_count_distinct"), is(2L));
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Date(java.util.Date) 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