Search in sources :

Example 1 with DecimalType.createDecimalType

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

the class TestHiveIntegrationSmokeTest method testIoExplainWithPrimitiveTypes.

@Test
public void testIoExplainWithPrimitiveTypes() {
    Map<Object, Type> data = new HashMap<>();
    data.put("foo", VarcharType.createUnboundedVarcharType());
    data.put(Byte.toString((byte) (Byte.MAX_VALUE / 2)), TinyintType.TINYINT);
    data.put(Short.toString((short) (Short.MAX_VALUE / 2)), SmallintType.SMALLINT);
    data.put(Integer.toString(Integer.MAX_VALUE / 2), IntegerType.INTEGER);
    data.put(Long.toString(Long.MAX_VALUE / 2), BigintType.BIGINT);
    data.put(Boolean.TRUE.toString(), BooleanType.BOOLEAN);
    data.put("bar", CharType.createCharType(3));
    data.put("1.2345678901234578E14", DoubleType.DOUBLE);
    data.put("123456789012345678901234.567", DecimalType.createDecimalType(30, 3));
    data.put("2019-01-01", DateType.DATE);
    data.put("2019-01-01 23:22:21.123", TimestampType.TIMESTAMP);
    for (Map.Entry<Object, Type> entry : data.entrySet()) {
        @Language("SQL") String query = format("CREATE TABLE test_types_table  WITH (partitioned_by = ARRAY['my_col']) AS " + "SELECT 'foo' my_non_partition_col, CAST('%s' AS %s) my_col", entry.getKey(), entry.getValue().getDisplayName());
        assertUpdate(query, 1);
        MaterializedResult result = computeActual("EXPLAIN (TYPE IO, FORMAT JSON) SELECT * FROM test_types_table");
        assertEquals(jsonCodec(IoPlan.class).fromJson((String) getOnlyElement(result.getOnlyColumnAsSet())), new IoPlan(ImmutableSet.of(new TableColumnInfo(new CatalogSchemaTableName(catalog, "tpch", "test_types_table"), ImmutableSet.of(new ColumnConstraint("my_col", entry.getValue().getTypeSignature(), new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of(entry.getKey().toString()), EXACTLY), new FormattedMarker(Optional.of(entry.getKey().toString()), EXACTLY)))))))), Optional.empty()));
        assertUpdate("DROP TABLE test_types_table");
    }
}
Also used : HashMap(java.util.HashMap) CatalogSchemaTableName(io.prestosql.spi.connector.CatalogSchemaTableName) JoinDistributionType(io.prestosql.sql.analyzer.FeaturesConfig.JoinDistributionType) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) TimestampType(io.prestosql.spi.type.TimestampType) CharType(io.prestosql.spi.type.CharType) IntegerType(io.prestosql.spi.type.IntegerType) TinyintType(io.prestosql.spi.type.TinyintType) BooleanType(io.prestosql.spi.type.BooleanType) VarcharType(io.prestosql.spi.type.VarcharType) DecimalType(io.prestosql.spi.type.DecimalType) Type(io.prestosql.spi.type.Type) DecimalType.createDecimalType(io.prestosql.spi.type.DecimalType.createDecimalType) CharType.createCharType(io.prestosql.spi.type.CharType.createCharType) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) BigintType(io.prestosql.spi.type.BigintType) DoubleType(io.prestosql.spi.type.DoubleType) SmallintType(io.prestosql.spi.type.SmallintType) DateType(io.prestosql.spi.type.DateType) Language(org.intellij.lang.annotations.Language) FormattedDomain(io.prestosql.sql.planner.planprinter.IoPlanPrinter.FormattedDomain) ColumnConstraint(io.prestosql.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint) TableColumnInfo(io.prestosql.sql.planner.planprinter.IoPlanPrinter.IoPlan.TableColumnInfo) FormattedMarker(io.prestosql.sql.planner.planprinter.IoPlanPrinter.FormattedMarker) FormattedRange(io.prestosql.sql.planner.planprinter.IoPlanPrinter.FormattedRange) MaterializedResult(io.prestosql.testing.MaterializedResult) IoPlan(io.prestosql.sql.planner.planprinter.IoPlanPrinter.IoPlan) Map(java.util.Map) NodeTaskMap(io.prestosql.execution.NodeTaskMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(io.prestosql.tests.AbstractTestIntegrationSmokeTest)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 NodeTaskMap (io.prestosql.execution.NodeTaskMap)1 CatalogSchemaTableName (io.prestosql.spi.connector.CatalogSchemaTableName)1 BigintType (io.prestosql.spi.type.BigintType)1 BooleanType (io.prestosql.spi.type.BooleanType)1 CharType (io.prestosql.spi.type.CharType)1 CharType.createCharType (io.prestosql.spi.type.CharType.createCharType)1 DateType (io.prestosql.spi.type.DateType)1 DecimalType (io.prestosql.spi.type.DecimalType)1 DecimalType.createDecimalType (io.prestosql.spi.type.DecimalType.createDecimalType)1 DoubleType (io.prestosql.spi.type.DoubleType)1 IntegerType (io.prestosql.spi.type.IntegerType)1 SmallintType (io.prestosql.spi.type.SmallintType)1 TimestampType (io.prestosql.spi.type.TimestampType)1 TinyintType (io.prestosql.spi.type.TinyintType)1 Type (io.prestosql.spi.type.Type)1 VarcharType (io.prestosql.spi.type.VarcharType)1 VarcharType.createUnboundedVarcharType (io.prestosql.spi.type.VarcharType.createUnboundedVarcharType)1 VarcharType.createVarcharType (io.prestosql.spi.type.VarcharType.createVarcharType)1 JoinDistributionType (io.prestosql.sql.analyzer.FeaturesConfig.JoinDistributionType)1