Search in sources :

Example 1 with ColumnConstraint

use of io.prestosql.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint 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)

Example 2 with ColumnConstraint

use of io.prestosql.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint in project hetu-core by openlookeng.

the class TestHiveIntegrationSmokeTest method assertConstraints.

private void assertConstraints(@Language("SQL") String query, Set<ColumnConstraint> expected) {
    MaterializedResult result = computeActual("EXPLAIN (TYPE IO, FORMAT JSON) " + query);
    Set<ColumnConstraint> constraints = jsonCodec(IoPlan.class).fromJson((String) getOnlyElement(result.getOnlyColumnAsSet())).getInputTableColumnInfos().stream().findFirst().get().getColumnConstraints();
    assertEquals(constraints, expected);
}
Also used : ColumnConstraint(io.prestosql.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint) MaterializedResult(io.prestosql.testing.MaterializedResult)

Example 3 with ColumnConstraint

use of io.prestosql.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint in project hetu-core by openlookeng.

the class TestHiveIntegrationSmokeTest method testIOExplain.

@Test
public void testIOExplain() {
    // Test IO explain with small number of discrete components.
    computeActual("CREATE TABLE test_orders WITH (partitioned_by = ARRAY['orderkey', 'processing']) AS select custkey, orderkey, orderstatus = 'P' processing FROM orders where orderkey < 3");
    MaterializedResult result = computeActual("EXPLAIN (TYPE IO, FORMAT JSON) INSERT INTO test_orders SELECT custkey, orderkey, processing FROM test_orders where custkey <= 10");
    assertEquals(jsonCodec(IoPlan.class).fromJson((String) getOnlyElement(result.getOnlyColumnAsSet())), new IoPlan(ImmutableSet.of(new TableColumnInfo(new CatalogSchemaTableName(catalog, "tpch", "test_orders"), ImmutableSet.of(new ColumnConstraint("orderkey", BIGINT.getTypeSignature(), new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of("1"), EXACTLY), new FormattedMarker(Optional.of("1"), EXACTLY)), new FormattedRange(new FormattedMarker(Optional.of("2"), EXACTLY), new FormattedMarker(Optional.of("2"), EXACTLY))))), new ColumnConstraint("processing", BOOLEAN.getTypeSignature(), new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of("false"), EXACTLY), new FormattedMarker(Optional.of("false"), EXACTLY)))))))), Optional.of(new CatalogSchemaTableName(catalog, "tpch", "test_orders"))));
    assertUpdate("DROP TABLE test_orders");
    // Test IO explain with large number of discrete components where Domain::simpify comes into play.
    computeActual("CREATE TABLE test_orders WITH (partitioned_by = ARRAY['orderkey']) AS select custkey, orderkey FROM orders where orderkey < 200");
    result = computeActual("EXPLAIN (TYPE IO, FORMAT JSON) INSERT INTO test_orders SELECT custkey, orderkey + 10 FROM test_orders where custkey <= 10");
    assertEquals(jsonCodec(IoPlan.class).fromJson((String) getOnlyElement(result.getOnlyColumnAsSet())), new IoPlan(ImmutableSet.of(new TableColumnInfo(new CatalogSchemaTableName(catalog, "tpch", "test_orders"), ImmutableSet.of(new ColumnConstraint("orderkey", BIGINT.getTypeSignature(), new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of("1"), EXACTLY), new FormattedMarker(Optional.of("199"), EXACTLY)))))))), Optional.of(new CatalogSchemaTableName(catalog, "tpch", "test_orders"))));
    assertUpdate("DROP TABLE test_orders");
}
Also used : 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) CatalogSchemaTableName(io.prestosql.spi.connector.CatalogSchemaTableName) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(io.prestosql.tests.AbstractTestIntegrationSmokeTest)

Example 4 with ColumnConstraint

use of io.prestosql.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint in project hetu-core by openlookeng.

the class TestHiveIntegrationSmokeTest method testPartitionPruning.

@Test
public void testPartitionPruning() {
    assertUpdate("CREATE TABLE test_partition_pruning (v bigint, k varchar) WITH (partitioned_by = array['k'])");
    assertUpdate("INSERT INTO test_partition_pruning (v, k) VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'e')", 4);
    try {
        String query = "SELECT * FROM test_partition_pruning WHERE k = 'a'";
        assertQuery(query, "VALUES (1, 'a')");
        assertConstraints(query, ImmutableSet.of(new ColumnConstraint("k", VARCHAR.getTypeSignature(), new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of("a"), EXACTLY), new FormattedMarker(Optional.of("a"), EXACTLY)))))));
        query = "SELECT * FROM test_partition_pruning WHERE k IN ('a', 'b')";
        assertQuery(query, "VALUES (1, 'a'), (2, 'b')");
        assertConstraints(query, ImmutableSet.of(new ColumnConstraint("k", VARCHAR.getTypeSignature(), new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of("a"), EXACTLY), new FormattedMarker(Optional.of("a"), EXACTLY)), new FormattedRange(new FormattedMarker(Optional.of("b"), EXACTLY), new FormattedMarker(Optional.of("b"), EXACTLY)))))));
        query = "SELECT * FROM test_partition_pruning WHERE k >= 'b'";
        assertQuery(query, "VALUES (2, 'b'), (3, 'c'), (4, 'e')");
        assertConstraints(query, ImmutableSet.of(new ColumnConstraint("k", VARCHAR.getTypeSignature(), new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of("b"), EXACTLY), new FormattedMarker(Optional.of("b"), EXACTLY)), new FormattedRange(new FormattedMarker(Optional.of("c"), EXACTLY), new FormattedMarker(Optional.of("c"), EXACTLY)), new FormattedRange(new FormattedMarker(Optional.of("e"), EXACTLY), new FormattedMarker(Optional.of("e"), EXACTLY)))))));
        query = "SELECT * FROM (" + "    SELECT * " + "    FROM test_partition_pruning " + "    WHERE v IN (1, 2, 4) " + ") t " + "WHERE t.k >= 'b'";
        assertQuery(query, "VALUES (2, 'b'), (4, 'e')");
        assertConstraints(query, ImmutableSet.of(new ColumnConstraint("k", VARCHAR.getTypeSignature(), new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of("b"), EXACTLY), new FormattedMarker(Optional.of("b"), EXACTLY)), new FormattedRange(new FormattedMarker(Optional.of("c"), EXACTLY), new FormattedMarker(Optional.of("c"), EXACTLY)), new FormattedRange(new FormattedMarker(Optional.of("e"), EXACTLY), new FormattedMarker(Optional.of("e"), EXACTLY)))))));
    } finally {
        assertUpdate("DROP TABLE test_partition_pruning");
    }
}
Also used : FormattedDomain(io.prestosql.sql.planner.planprinter.IoPlanPrinter.FormattedDomain) ColumnConstraint(io.prestosql.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint) FormattedMarker(io.prestosql.sql.planner.planprinter.IoPlanPrinter.FormattedMarker) FormattedRange(io.prestosql.sql.planner.planprinter.IoPlanPrinter.FormattedRange) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(io.prestosql.tests.AbstractTestIntegrationSmokeTest)

Aggregations

ColumnConstraint (io.prestosql.sql.planner.planprinter.IoPlanPrinter.ColumnConstraint)4 FormattedDomain (io.prestosql.sql.planner.planprinter.IoPlanPrinter.FormattedDomain)3 FormattedMarker (io.prestosql.sql.planner.planprinter.IoPlanPrinter.FormattedMarker)3 FormattedRange (io.prestosql.sql.planner.planprinter.IoPlanPrinter.FormattedRange)3 MaterializedResult (io.prestosql.testing.MaterializedResult)3 AbstractTestIntegrationSmokeTest (io.prestosql.tests.AbstractTestIntegrationSmokeTest)3 Test (org.testng.annotations.Test)3 CatalogSchemaTableName (io.prestosql.spi.connector.CatalogSchemaTableName)2 IoPlan (io.prestosql.sql.planner.planprinter.IoPlanPrinter.IoPlan)2 TableColumnInfo (io.prestosql.sql.planner.planprinter.IoPlanPrinter.IoPlan.TableColumnInfo)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 NodeTaskMap (io.prestosql.execution.NodeTaskMap)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