Search in sources :

Example 1 with SqlTimestampWithTimeZone

use of io.prestosql.spi.type.SqlTimestampWithTimeZone in project hetu-core by openlookeng.

the class TestTimestampWithTimeZone method testGreatest.

@Test
public void testGreatest() {
    assertFunction("greatest(TIMESTAMP '2002-01-02 03:04:05.321 +07:09', TIMESTAMP '2001-01-02 01:04:05.321 +02:09', TIMESTAMP '2000-01-02 01:04:05.321 +02:09')", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2002, 1, 2, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
    assertFunction("greatest(TIMESTAMP '2001-01-02 03:04:05.321 +07:09', TIMESTAMP '2001-01-02 04:04:05.321 +10:09')", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(2001, 1, 2, 3, 4, 5, 321, WEIRD_ZONE).getMillis(), WEIRD_TIME_ZONE_KEY));
}
Also used : SqlTimestampWithTimeZone(io.prestosql.spi.type.SqlTimestampWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 2 with SqlTimestampWithTimeZone

use of io.prestosql.spi.type.SqlTimestampWithTimeZone in project hetu-core by openlookeng.

the class TestTimestampWithTimeZone 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));
    assertFunction("TIMESTAMP '12001-01-02 03:04:05.321 Europe/Berlin'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(12001, 1, 2, 3, 4, 5, 321, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '+12001-01-02 03:04:05.321 Europe/Berlin'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(12001, 1, 2, 3, 4, 5, 321, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
    assertFunction("TIMESTAMP '-12001-01-02 03:04:05.321 Europe/Berlin'", TIMESTAMP_WITH_TIME_ZONE, new SqlTimestampWithTimeZone(new DateTime(-12001, 1, 2, 3, 4, 5, 321, BERLIN_ZONE).getMillis(), BERLIN_TIME_ZONE_KEY));
}
Also used : SqlTimestampWithTimeZone(io.prestosql.spi.type.SqlTimestampWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 3 with SqlTimestampWithTimeZone

use of io.prestosql.spi.type.SqlTimestampWithTimeZone in project hetu-core by openlookeng.

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
    Futures.allAsList(futures).get();
}
Also used : SqlTimestampWithTimeZone(io.prestosql.spi.type.SqlTimestampWithTimeZone) SqlVarbinary(io.prestosql.spi.type.SqlVarbinary) SqlDecimal(io.prestosql.spi.type.SqlDecimal) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 4 with SqlTimestampWithTimeZone

use of io.prestosql.spi.type.SqlTimestampWithTimeZone in project hetu-core by openlookeng.

the class TestDateTimeOperators 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));
    assertFunction("INTERVAL '3' hour + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, sqlTimestampOf(2001, 1, 22, 6, 4, 5, 321));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' day", TIMESTAMP, sqlTimestampOf(2001, 1, 25, 3, 4, 5, 321));
    assertFunction("INTERVAL '3' day + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, sqlTimestampOf(2001, 1, 25, 3, 4, 5, 321));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' month", TIMESTAMP, sqlTimestampOf(2001, 4, 22, 3, 4, 5, 321));
    assertFunction("INTERVAL '3' month + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, sqlTimestampOf(2001, 4, 22, 3, 4, 5, 321));
    assertFunction("TIMESTAMP '2001-1-22 03:04:05.321' + INTERVAL '3' year", TIMESTAMP, sqlTimestampOf(2004, 1, 22, 3, 4, 5, 321));
    assertFunction("INTERVAL '3' year + TIMESTAMP '2001-1-22 03:04:05.321'", TIMESTAMP, sqlTimestampOf(2004, 1, 22, 3, 4, 5, 321));
    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(io.prestosql.spi.type.SqlTimestampWithTimeZone) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 5 with SqlTimestampWithTimeZone

use of io.prestosql.spi.type.SqlTimestampWithTimeZone in project hetu-core by openlookeng.

the class MaterializedResult method writeValue.

private static void writeValue(Type type, BlockBuilder blockBuilder, Object value) {
    if (value == null) {
        blockBuilder.appendNull();
    } else if (BIGINT.equals(type)) {
        type.writeLong(blockBuilder, ((Number) value).longValue());
    } else if (INTEGER.equals(type)) {
        type.writeLong(blockBuilder, ((Number) value).intValue());
    } else if (SMALLINT.equals(type)) {
        type.writeLong(blockBuilder, ((Number) value).shortValue());
    } else if (TINYINT.equals(type)) {
        type.writeLong(blockBuilder, ((Number) value).byteValue());
    } else if (REAL.equals(type)) {
        type.writeLong(blockBuilder, (long) floatToRawIntBits(((Number) value).floatValue()));
    } else if (DOUBLE.equals(type)) {
        type.writeDouble(blockBuilder, ((Number) value).doubleValue());
    } else if (BOOLEAN.equals(type)) {
        type.writeBoolean(blockBuilder, (Boolean) value);
    } else if (JSON.equals(type)) {
        type.writeSlice(blockBuilder, Slices.utf8Slice((String) value));
    } else if (type instanceof VarcharType) {
        type.writeSlice(blockBuilder, Slices.utf8Slice((String) value));
    } else if (type instanceof CharType) {
        type.writeSlice(blockBuilder, Slices.utf8Slice((String) value));
    } else if (VARBINARY.equals(type)) {
        type.writeSlice(blockBuilder, Slices.wrappedBuffer((byte[]) value));
    } else if (DATE.equals(type)) {
        int days = ((SqlDate) value).getDays();
        type.writeLong(blockBuilder, days);
    } else if (TIME.equals(type)) {
        SqlTime time = (SqlTime) value;
        if (time.isLegacyTimestamp()) {
            type.writeLong(blockBuilder, time.getMillisUtc());
        } else {
            type.writeLong(blockBuilder, time.getMillis());
        }
    } else if (TIME_WITH_TIME_ZONE.equals(type)) {
        long millisUtc = ((SqlTimeWithTimeZone) value).getMillisUtc();
        TimeZoneKey timeZoneKey = ((SqlTimeWithTimeZone) value).getTimeZoneKey();
        type.writeLong(blockBuilder, packDateTimeWithZone(millisUtc, timeZoneKey));
    } else if (TIMESTAMP.equals(type)) {
        long millisUtc = ((SqlTimestamp) value).getMillis();
        type.writeLong(blockBuilder, millisUtc);
    } else if (TIMESTAMP_WITH_TIME_ZONE.equals(type)) {
        long millisUtc = ((SqlTimestampWithTimeZone) value).getMillisUtc();
        TimeZoneKey timeZoneKey = ((SqlTimestampWithTimeZone) value).getTimeZoneKey();
        type.writeLong(blockBuilder, packDateTimeWithZone(millisUtc, timeZoneKey));
    } else if (ARRAY.equals(type.getTypeSignature().getBase())) {
        List<Object> list = (List<Object>) value;
        Type elementType = ((ArrayType) type).getElementType();
        BlockBuilder arrayBlockBuilder = blockBuilder.beginBlockEntry();
        for (Object element : list) {
            writeValue(elementType, arrayBlockBuilder, element);
        }
        blockBuilder.closeEntry();
    } else if (MAP.equals(type.getTypeSignature().getBase())) {
        Map<Object, Object> map = (Map<Object, Object>) value;
        Type keyType = ((MapType) type).getKeyType();
        Type valueType = ((MapType) type).getValueType();
        BlockBuilder mapBlockBuilder = blockBuilder.beginBlockEntry();
        for (Entry<Object, Object> entry : map.entrySet()) {
            writeValue(keyType, mapBlockBuilder, entry.getKey());
            writeValue(valueType, mapBlockBuilder, entry.getValue());
        }
        blockBuilder.closeEntry();
    } else if (type instanceof RowType) {
        List<Object> row = (List<Object>) value;
        List<Type> fieldTypes = type.getTypeParameters();
        BlockBuilder rowBlockBuilder = blockBuilder.beginBlockEntry();
        for (int field = 0; field < row.size(); field++) {
            writeValue(fieldTypes.get(field), rowBlockBuilder, row.get(field));
        }
        blockBuilder.closeEntry();
    } else {
        throw new IllegalArgumentException("Unsupported type " + type);
    }
}
Also used : VarcharType(io.prestosql.spi.type.VarcharType) SqlTime(io.prestosql.spi.type.SqlTime) SqlTimeWithTimeZone(io.prestosql.spi.type.SqlTimeWithTimeZone) RowType(io.prestosql.spi.type.RowType) MapType(io.prestosql.spi.type.MapType) RowType(io.prestosql.spi.type.RowType) Type(io.prestosql.spi.type.Type) ArrayType(io.prestosql.spi.type.ArrayType) CharType(io.prestosql.spi.type.CharType) MapType(io.prestosql.spi.type.MapType) VarcharType(io.prestosql.spi.type.VarcharType) SqlTimestampWithTimeZone(io.prestosql.spi.type.SqlTimestampWithTimeZone) SqlDate(io.prestosql.spi.type.SqlDate) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) CharType(io.prestosql.spi.type.CharType) TimeZoneKey(io.prestosql.spi.type.TimeZoneKey) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Aggregations

SqlTimestampWithTimeZone (io.prestosql.spi.type.SqlTimestampWithTimeZone)13 DateTime (org.joda.time.DateTime)10 Test (org.testng.annotations.Test)10 MapType (io.prestosql.spi.type.MapType)2 SqlDate (io.prestosql.spi.type.SqlDate)2 SqlDecimal (io.prestosql.spi.type.SqlDecimal)2 SqlTime (io.prestosql.spi.type.SqlTime)2 SqlTimeWithTimeZone (io.prestosql.spi.type.SqlTimeWithTimeZone)2 Type (io.prestosql.spi.type.Type)2 LocalDateTime (java.time.LocalDateTime)2 ArrayList (java.util.ArrayList)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 BlockBuilder (io.prestosql.spi.block.BlockBuilder)1 Signature (io.prestosql.spi.function.Signature)1 ArrayType (io.prestosql.spi.type.ArrayType)1 CharType (io.prestosql.spi.type.CharType)1 DecimalType.createDecimalType (io.prestosql.spi.type.DecimalType.createDecimalType)1 RowType (io.prestosql.spi.type.RowType)1