Search in sources :

Example 1 with ColumnConstraint

use of com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint in project presto by prestodb.

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");
    ImmutableSet.Builder<ColumnConstraint> expectedConstraints = ImmutableSet.builder();
    expectedConstraints.add(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))))));
    expectedConstraints.add(new ColumnConstraint("processing", BOOLEAN.getTypeSignature(), new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of("false"), EXACTLY), new FormattedMarker(Optional.of("false"), EXACTLY))))));
    assertEquals(jsonCodec(IOPlan.class).fromJson((String) getOnlyElement(result.getOnlyColumnAsSet())), new IOPlan(ImmutableSet.of(new TableColumnInfo(new CatalogSchemaTableName(catalog, "tpch", "test_orders"), expectedConstraints.build())), Optional.of(new CatalogSchemaTableName(catalog, "tpch", "test_orders"))));
    assertUpdate("DROP TABLE test_orders");
    // Test IO explain with large number of discrete components where Domain::simplify comes into play.
    computeActual("CREATE TABLE test_orders WITH (partitioned_by = ARRAY['orderkey']) AS select custkey, orderkey FROM orders where orderkey < 200");
    expectedConstraints = ImmutableSet.builder();
    expectedConstraints.add(new ColumnConstraint("orderkey", BIGINT.getTypeSignature(), new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of("1"), EXACTLY), new FormattedMarker(Optional.of("199"), EXACTLY))))));
    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"), expectedConstraints.build())), Optional.of(new CatalogSchemaTableName(catalog, "tpch", "test_orders"))));
    assertUpdate("DROP TABLE test_orders");
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) FormattedDomain(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.FormattedDomain) ColumnConstraint(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint) FormattedMarker(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.FormattedMarker) TableColumnInfo(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.IOPlan.TableColumnInfo) FormattedRange(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.FormattedRange) MaterializedResult(com.facebook.presto.testing.MaterializedResult) IOPlan(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.IOPlan) CatalogSchemaTableName(com.facebook.presto.spi.CatalogSchemaTableName) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)

Example 2 with ColumnConstraint

use of com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint in project presto by prestodb.

the class TestLocalQueries method testIOExplain.

@Test
public void testIOExplain() {
    String query = "SELECT * FROM orders";
    MaterializedResult result = computeActual("EXPLAIN (TYPE IO, FORMAT JSON) " + query);
    TableColumnInfo input = new TableColumnInfo(new CatalogSchemaTableName("local", "sf0.01", "orders"), ImmutableSet.of(new ColumnConstraint("orderstatus", createVarcharType(1).getTypeSignature(), new FormattedDomain(false, ImmutableSet.of(new FormattedRange(new FormattedMarker(Optional.of("F"), EXACTLY), new FormattedMarker(Optional.of("F"), EXACTLY)), new FormattedRange(new FormattedMarker(Optional.of("O"), EXACTLY), new FormattedMarker(Optional.of("O"), EXACTLY)), new FormattedRange(new FormattedMarker(Optional.of("P"), EXACTLY), new FormattedMarker(Optional.of("P"), EXACTLY)))))));
    assertEquals(jsonCodec(IOPlan.class).fromJson((String) getOnlyElement(result.getOnlyColumnAsSet())), new IOPlan(ImmutableSet.of(input), Optional.empty()));
}
Also used : FormattedDomain(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.FormattedDomain) ColumnConstraint(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint) TableColumnInfo(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.IOPlan.TableColumnInfo) FormattedMarker(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.FormattedMarker) FormattedRange(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.FormattedRange) MaterializedResult(com.facebook.presto.testing.MaterializedResult) CatalogSchemaTableName(com.facebook.presto.spi.CatalogSchemaTableName) IOPlan(com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.IOPlan) Test(org.testng.annotations.Test)

Aggregations

CatalogSchemaTableName (com.facebook.presto.spi.CatalogSchemaTableName)2 ColumnConstraint (com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.ColumnConstraint)2 FormattedDomain (com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.FormattedDomain)2 FormattedMarker (com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.FormattedMarker)2 FormattedRange (com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.FormattedRange)2 IOPlan (com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.IOPlan)2 TableColumnInfo (com.facebook.presto.sql.planner.planPrinter.IOPlanPrinter.IOPlan.TableColumnInfo)2 MaterializedResult (com.facebook.presto.testing.MaterializedResult)2 Test (org.testng.annotations.Test)2 AbstractTestIntegrationSmokeTest (com.facebook.presto.tests.AbstractTestIntegrationSmokeTest)1 ImmutableSet (com.google.common.collect.ImmutableSet)1