Search in sources :

Example 1 with SqlTimestamp

use of com.facebook.presto.spi.type.SqlTimestamp in project presto by prestodb.

the class TestExpressionCompiler method testTryCast.

@Test
public void testTryCast() throws Exception {
    assertExecute("try_cast(null as integer)", INTEGER, null);
    assertExecute("try_cast('123' as integer)", INTEGER, 123);
    assertExecute("try_cast(null as bigint)", BIGINT, null);
    assertExecute("try_cast('123' as bigint)", BIGINT, 123L);
    assertExecute("try_cast('foo' as varchar)", VARCHAR, "foo");
    assertExecute("try_cast('foo' as bigint)", BIGINT, null);
    assertExecute("try_cast('foo' as integer)", INTEGER, null);
    assertExecute("try_cast('2001-08-22' as timestamp)", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 8, 22, 0, 0, 0, 0, UTC).getMillis(), UTC_KEY));
    assertExecute("try_cast(bound_string as bigint)", BIGINT, null);
    assertExecute("try_cast(cast(null as varchar) as bigint)", BIGINT, null);
    assertExecute("try_cast(bound_long / 13  as bigint)", BIGINT, 94L);
    assertExecute("coalesce(try_cast('123' as bigint), 456)", BIGINT, 123L);
    assertExecute("coalesce(try_cast('foo' as bigint), 456)", BIGINT, 456L);
    assertExecute("concat('foo', cast('bar' as varchar))", VARCHAR, "foobar");
    assertExecute("try_cast(try_cast(123 as varchar) as bigint)", BIGINT, 123L);
    assertExecute("try_cast('foo' as varchar) || try_cast('bar' as varchar)", VARCHAR, "foobar");
    Futures.allAsList(futures).get();
}
Also used : SqlTimestamp(com.facebook.presto.spi.type.SqlTimestamp) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 2 with SqlTimestamp

use of com.facebook.presto.spi.type.SqlTimestamp in project presto by prestodb.

the class TestRowOperators method testRowToJson.

@Test
public void testRowToJson() throws Exception {
    assertFunction("CAST(ROW(1, 2) AS JSON)", JSON, "[1,2]");
    assertFunction("CAST(CAST(ROW(1, 2) AS ROW(a BIGINT, b BIGINT)) AS JSON)", JSON, "[1,2]");
    assertFunction("CAST(ROW(1, NULL) AS JSON)", JSON, "[1,null]");
    assertFunction("CAST(ROW(1, CAST(NULL AS INTEGER)) AS JSON)", JSON, "[1,null]");
    assertFunction("CAST(ROW(1, 2.0) AS JSON)", JSON, "[1,2.0]");
    assertFunction("CAST(ROW(1.0, 2.5) AS JSON)", JSON, "[1.0,2.5]");
    assertFunction("CAST(ROW(1.0, 'kittens') AS JSON)", JSON, "[1.0,\"kittens\"]");
    assertFunction("CAST(ROW(TRUE, FALSE) AS JSON)", JSON, "[true,false]");
    assertFunction("CAST(ROW(from_unixtime(1)) AS JSON)", JSON, "[\"" + new SqlTimestamp(1000, TEST_SESSION.getTimeZoneKey()) + "\"]");
    assertFunction("CAST(ROW(FALSE, ARRAY [1, 2], MAP(ARRAY[1, 3], ARRAY[2.0, 4.0])) AS JSON)", JSON, "[false,[1,2],{\"1\":2.0,\"3\":4.0}]");
}
Also used : SqlTimestamp(com.facebook.presto.spi.type.SqlTimestamp) Test(org.testng.annotations.Test)

Example 3 with SqlTimestamp

use of com.facebook.presto.spi.type.SqlTimestamp in project presto by prestodb.

the class TestTimestamp method testGreatest.

@Test
public void testGreatest() throws Exception {
    assertFunction("greatest(TIMESTAMP '2013-03-30 01:05', TIMESTAMP '2012-03-30 01:05')", TIMESTAMP, new SqlTimestamp(new DateTime(2013, 3, 30, 1, 5, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("greatest(TIMESTAMP '2013-03-30 01:05', TIMESTAMP '2012-03-30 01:05', TIMESTAMP '2012-05-01 01:05')", TIMESTAMP, new SqlTimestamp(new DateTime(2013, 3, 30, 1, 5, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
}
Also used : SqlTimestamp(com.facebook.presto.spi.type.SqlTimestamp) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 4 with SqlTimestamp

use of com.facebook.presto.spi.type.SqlTimestamp in project presto by prestodb.

the class TestTimestamp method testLiteral.

@Test
public void testLiteral() {
    assertFunction("TIMESTAMP '2013-03-30 01:05'", TIMESTAMP, new SqlTimestamp(new DateTime(2013, 3, 30, 1, 5, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2013-03-30 02:05'", TIMESTAMP, new SqlTimestamp(new DateTime(2013, 3, 30, 2, 5, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2013-03-30 03:05'", TIMESTAMP, new SqlTimestamp(new DateTime(2013, 3, 30, 3, 5, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-01-22 03:04:05.321'", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 22, 3, 4, 5, 321, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-01-22 03:04:05'", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 22, 3, 4, 5, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-01-22 03:04'", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 22, 3, 4, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-01-22'", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 22, 0, 0, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-2 3:4:5.321'", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 2, 3, 4, 5, 321, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-2 3:4:5'", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 2, 3, 4, 5, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-2 3:4'", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 2, 3, 4, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-2'", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 2, 0, 0, 0, 0, DATE_TIME_ZONE).getMillis(), TIME_ZONE_KEY));
}
Also used : SqlTimestamp(com.facebook.presto.spi.type.SqlTimestamp) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 5 with SqlTimestamp

use of com.facebook.presto.spi.type.SqlTimestamp in project presto by prestodb.

the class TestDateTimeOperators method testTimestampMinusInterval.

@Test
public void testTimestampMinusInterval() {
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' - INTERVAL '3' day", TIMESTAMP, new SqlTimestamp(new DateTime(2001, 1, 19, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' - INTERVAL '3' day", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 19, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' - INTERVAL '3' month", TIMESTAMP, new SqlTimestamp(new DateTime(2000, 10, 22, 3, 4, 5, 321, TIME_ZONE).getMillis(), TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' - INTERVAL '3' month", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2000, 10, 22, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}
Also used : SqlTimestampWithTimeZone(com.facebook.presto.spi.type.SqlTimestampWithTimeZone) SqlTimestamp(com.facebook.presto.spi.type.SqlTimestamp) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

SqlTimestamp (com.facebook.presto.spi.type.SqlTimestamp)15 Test (org.testng.annotations.Test)11 DateTime (org.joda.time.DateTime)9 SqlDate (com.facebook.presto.spi.type.SqlDate)3 SqlTimestampWithTimeZone (com.facebook.presto.spi.type.SqlTimestampWithTimeZone)3 Date (java.sql.Date)2 Timestamp (java.sql.Timestamp)2 ArrayList (java.util.ArrayList)2 PrimitiveObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector)2 PrimitiveCategory (org.apache.hadoop.hive.serde2.objectinspector.PrimitiveObjectInspector.PrimitiveCategory)2 PrestoException (com.facebook.presto.spi.PrestoException)1 SqlDecimal (com.facebook.presto.spi.type.SqlDecimal)1 SqlTime (com.facebook.presto.spi.type.SqlTime)1 SqlTimeWithTimeZone (com.facebook.presto.spi.type.SqlTimeWithTimeZone)1 SqlVarbinary (com.facebook.presto.spi.type.SqlVarbinary)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Time (java.sql.Time)1 LocalDate (java.time.LocalDate)1 ZonedDateTime (java.time.ZonedDateTime)1