Search in sources :

Example 1 with SqlTimestampWithTimeZone

use of com.facebook.presto.common.type.SqlTimestampWithTimeZone in project presto by prestodb.

the class TestTimestampBase method testCastToTimestampWithTimeZone.

@Test
public void testCastToTimestampWithTimeZone() {
    assertFunction("cast(TIMESTAMP '2001-1-22 03:04:05.321' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 3, 4, 5, 321, DATE_TIME_ZONE).getMillis(), TimeZone.getTimeZone(ZoneId.of(DATE_TIME_ZONE.getID()))));
    functionAssertions.assertFunctionString("cast(TIMESTAMP '2001-1-22 03:04:05.321' as timestamp with time zone)", TIMESTAMP_WITH_TIME_ZONE, "2001-01-22 03:04:05.321 " + DATE_TIME_ZONE.getID());
}
Also used : SqlTimestampWithTimeZone(com.facebook.presto.common.type.SqlTimestampWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 2 with SqlTimestampWithTimeZone

use of com.facebook.presto.common.type.SqlTimestampWithTimeZone in project presto by prestodb.

the class TestExpressionCompiler method smokedTest.

@Test
public void smokedTest() throws Exception {
    assertExecute("cast(true as boolean)", BOOLEAN, true);
    assertExecute("true", BOOLEAN, true);
    assertExecute("false", BOOLEAN, false);
    assertExecute("42", INTEGER, 42);
    assertExecute("'foo'", createVarcharType(3), "foo");
    assertExecute("4.2E0", DOUBLE, 4.2);
    assertExecute("10000000000 + 1", BIGINT, 10000000001L);
    assertExecute("4.2", createDecimalType(2, 1), new SqlDecimal(BigInteger.valueOf(42), 2, 1));
    assertExecute("DECIMAL '4.2'", createDecimalType(2, 1), new SqlDecimal(BigInteger.valueOf(42), 2, 1));
    assertExecute("X' 1 f'", VARBINARY, new SqlVarbinary(Slices.wrappedBuffer((byte) 0x1f).getBytes()));
    assertExecute("X' '", VARBINARY, new SqlVarbinary(new byte[0]));
    assertExecute("bound_integer", INTEGER, 1234);
    assertExecute("bound_long", BIGINT, 1234L);
    assertExecute("bound_string", VARCHAR, "hello");
    assertExecute("bound_double", DOUBLE, 12.34);
    assertExecute("bound_boolean", BOOLEAN, true);
    assertExecute("bound_timestamp", BIGINT, new DateTime(2001, 8, 22, 3, 4, 5, 321, UTC).getMillis());
    assertExecute("bound_pattern", VARCHAR, "%el%");
    assertExecute("bound_null_string", VARCHAR, null);
    assertExecute("bound_timestamp_with_timezone", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(1970, 1, 1, 0, 1, 0, 999, DateTimeZone.UTC).getMillis(), TimeZoneKey.getTimeZoneKey("Z")));
    assertExecute("bound_binary_literal", VARBINARY, new SqlVarbinary(new byte[] { (byte) 0xab }));
    // todo enable when null output type is supported
    // assertExecute("null", null);
    Futures.allAsList(futures).get();
}
Also used : SqlTimestampWithTimeZone(com.facebook.presto.common.type.SqlTimestampWithTimeZone) SqlVarbinary(com.facebook.presto.common.type.SqlVarbinary) SqlDecimal(com.facebook.presto.common.type.SqlDecimal) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 3 with SqlTimestampWithTimeZone

use of com.facebook.presto.common.type.SqlTimestampWithTimeZone in project presto by prestodb.

the class TestExpressionCompiler method testFunctionWithSessionCall.

@Test
public void testFunctionWithSessionCall() throws Exception {
    assertExecute("now()", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(TEST_SESSION.getStartTime(), TEST_SESSION.getTimeZoneKey()));
    assertExecute("current_timestamp", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(TEST_SESSION.getStartTime(), TEST_SESSION.getTimeZoneKey()));
    Futures.allAsList(futures).get();
}
Also used : SqlTimestampWithTimeZone(com.facebook.presto.common.type.SqlTimestampWithTimeZone) Test(org.testng.annotations.Test)

Example 4 with SqlTimestampWithTimeZone

use of com.facebook.presto.common.type.SqlTimestampWithTimeZone in project presto by prestodb.

the class TestDateTimeOperatorsBase method testTimestampPlusInterval.

@Test
public void testTimestampPlusInterval() {
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' hour", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 6, 4, 5, 321, session));
    assertFunction("INTERVAL '3' hour + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 6, 4, 5, 321, session));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' day", TIMESTAMP, sqlTimestampOf(2001, 1, 25, 3, 4, 5, 321, session));
    assertFunction("INTERVAL '3' day + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, sqlTimestampOf(2001, 1, 25, 3, 4, 5, 321, session));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' month", TIMESTAMP, sqlTimestampOf(2001, 4, 22, 3, 4, 5, 321, session));
    assertFunction("INTERVAL '3' month + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, sqlTimestampOf(2001, 4, 22, 3, 4, 5, 321, session));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' year", TIMESTAMP, sqlTimestampOf(2004, 1, 22, 3, 4, 5, 321, session));
    assertFunction("INTERVAL '3' year + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, sqlTimestampOf(2004, 1, 22, 3, 4, 5, 321, session));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' + INTERVAL '3' hour", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 6, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' hour + TIMESTAMP '2001-1-22 03:04:05.321 +05:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 22, 6, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_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, 25, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' day + TIMESTAMP '2001-1-22 03:04:05.321 +05:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 25, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_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(2001, 4, 22, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' month + TIMESTAMP '2001-1-22 03:04:05.321 +05:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 4, 22, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321 +05:09' + INTERVAL '3' year", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2004, 1, 22, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("INTERVAL '3' year + TIMESTAMP '2001-1-22 03:04:05.321 +05:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2004, 1, 22, 3, 4, 5, 321, WEIRD_TIME_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}
Also used : SqlTimestampWithTimeZone(com.facebook.presto.common.type.SqlTimestampWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 5 with SqlTimestampWithTimeZone

use of com.facebook.presto.common.type.SqlTimestampWithTimeZone in project presto by prestodb.

the class TestTimestampWithTimeZoneBase method testLiteral.

@Test
public void testLiteral() {
    assertFunction("TIMESTAMP '2001-01-02 03:04:05.321 +07:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-01-02 03:04:05 +07:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 5, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-01-02 03:04 +07:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 0, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-01-02 +07:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 0, 0, 0, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-2 3:4:5.321+07:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-2 3:4:5+07:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 5, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-2 3:4+07:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 0, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-1-2+07:09'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 0, 0, 0, 0, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-01-02 03:04:05.321 Europe/Berlin'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 5, 321, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-01-02 03:04:05 Europe/Berlin'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 5, 0, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-01-02 03:04 Europe/Berlin'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 0, 0, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '2001-01-02 Europe/Berlin'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 0, 0, 0, 0, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
}
Also used : SqlTimestampWithTimeZone(com.facebook.presto.common.type.SqlTimestampWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

SqlTimestampWithTimeZone (com.facebook.presto.common.type.SqlTimestampWithTimeZone)11 Test (org.testng.annotations.Test)9 DateTime (org.joda.time.DateTime)8 SqlDecimal (com.facebook.presto.common.type.SqlDecimal)2 BigintType (com.facebook.presto.common.type.BigintType)1 BooleanType (com.facebook.presto.common.type.BooleanType)1 CharType (com.facebook.presto.common.type.CharType)1 DecimalType (com.facebook.presto.common.type.DecimalType)1 DoubleType (com.facebook.presto.common.type.DoubleType)1 IntegerType (com.facebook.presto.common.type.IntegerType)1 RealType (com.facebook.presto.common.type.RealType)1 SmallintType (com.facebook.presto.common.type.SmallintType)1 SqlDate (com.facebook.presto.common.type.SqlDate)1 SqlTime (com.facebook.presto.common.type.SqlTime)1 SqlTimeWithTimeZone (com.facebook.presto.common.type.SqlTimeWithTimeZone)1 SqlTimestamp (com.facebook.presto.common.type.SqlTimestamp)1 SqlVarbinary (com.facebook.presto.common.type.SqlVarbinary)1 TimestampType (com.facebook.presto.common.type.TimestampType)1 TimestampWithTimeZoneType (com.facebook.presto.common.type.TimestampWithTimeZoneType)1 TinyintType (com.facebook.presto.common.type.TinyintType)1