@Override public SqlDate getExpectedValue(int start, int length) { if (length == 0) { return null; } return new SqlDate(start + length - 1); }
private static SqlDate intToSqlDate(Integer input) { if (input == null) { return null; } return new SqlDate(input); } }
@Override public SqlDate getExpectedValue(int start, int length) { if (length == 0) { return null; } return new SqlDate(start + length - 1); }
@Override public Object getObjectValue(ConnectorSession session, Block block, int position) { if (block.isNull(position)) { return null; } int days = block.getInt(position, 0); return new SqlDate(days); }
private static SqlDate toDate(DateTime dateTime) { return new SqlDate((int) TimeUnit.MILLISECONDS.toDays(dateTime.getMillis())); } }
private static SqlDate toDate(DateTime dateTime) { return new SqlDate((int) TimeUnit.MILLISECONDS.toDays(dateTime.getMillis())); } }
private static SqlDate toDate(DateTime dateDate) { long millis = dateDate.getMillis(); return new SqlDate(toIntExact(MILLISECONDS.toDays(millis))); }
@Test public void testLeast() { int days = (int) TimeUnit.MILLISECONDS.toDays(new DateTime(2012, 5, 23, 0, 0, UTC).getMillis()); assertFunction("least(DATE '2013-03-30', DATE '2012-05-23')", DATE, new SqlDate(days)); assertFunction("least(DATE '2013-03-30', DATE '2012-05-23', DATE '2012-06-01')", DATE, new SqlDate(days)); }
@Test public void testCastToDate() { long millis = new DateTime(2001, 1, 22, 0, 0, UTC).getMillis(); assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as date)", DATE, new SqlDate((int) TimeUnit.MILLISECONDS.toDays(millis))); }
@Test public void testCastToDate() { long millis = new DateTime(2001, 1, 22, 0, 0, UTC).getMillis(); assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321' as date)", DATE, new SqlDate((int) TimeUnit.MILLISECONDS.toDays(millis))); }
@Test public void testCastToDate() { long millis = new DateTime(2001, 1, 22, 0, 0, UTC).getMillis(); assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321 +07:09' as date)", DATE, new SqlDate((int) TimeUnit.MILLISECONDS.toDays(millis))); }
@Test public void testLiteral() { long millis = new DateTime(2001, 1, 22, 0, 0, UTC).getMillis(); assertFunction("DATE '2001-1-22'", DATE, new SqlDate((int) TimeUnit.MILLISECONDS.toDays(millis))); }
@Test public void testLeast() { int days = (int) TimeUnit.MILLISECONDS.toDays(new DateTime(2012, 5, 23, 0, 0, UTC).getMillis()); assertFunction("least(DATE '2013-03-30', DATE '2012-05-23')", DATE, new SqlDate(days)); assertFunction("least(DATE '2013-03-30', DATE '2012-05-23', DATE '2012-06-01')", DATE, new SqlDate(days)); }
@Test public void testCastToDate() { long millis = new DateTime(2001, 1, 22, 0, 0, UTC).getMillis(); assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321' as date)", DATE, new SqlDate((int) TimeUnit.MILLISECONDS.toDays(millis))); }
@Test public void testGreatest() { int days = (int) TimeUnit.MILLISECONDS.toDays(new DateTime(2013, 3, 30, 0, 0, UTC).getMillis()); assertFunction("greatest(DATE '2013-03-30', DATE '2012-05-23')", DATE, new SqlDate(days)); assertFunction("greatest(DATE '2013-03-30', DATE '2012-05-23', DATE '2012-06-01')", DATE, new SqlDate(days)); }
private void assertDate(String projection, int year, int month, int day) { assertFunction( projection, DateType.DATE, new SqlDate(toIntExact(LocalDate.of(year, month, day).toEpochDay()))); }
private static SqlDate sqlDate(int year, int month, int day) { DateTime date = new DateTime(year, month, day, 0, 0, 0, 0, UTC); return new SqlDate(Days.daysBetween(EPOCH, date).getDays()); }
@Test public void testCurrentDate() { // current date is the time at midnight in the session time zone assertFunction("CURRENT_DATE", DateType.DATE, new SqlDate(toIntExact(epochDaysInZone(TIME_ZONE_KEY, session.getStartTime())))); }
@Test public void testDate() { InternalAggregationFunction varcharAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation( new Signature("array_agg", AGGREGATE, parseTypeSignature("array(date)"), parseTypeSignature(StandardTypes.DATE))); assertAggregation( varcharAgg, Arrays.asList(new SqlDate(1), new SqlDate(2), new SqlDate(4)), createTypedLongsBlock(DATE, ImmutableList.of(1L, 2L, 4L))); }
@Test public void testCurrentDate() { // current date is the time at midnight in the session time zone assertFunction("CURRENT_DATE", DateType.DATE, new SqlDate(toIntExact(epochDaysInZone(TIME_ZONE_KEY, session.getStartTime())))); }