Search in sources :

Example 16 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class TestDynamicFiltersChecker method setup.

@BeforeClass
public void setup() {
    metadata = getQueryRunner().getMetadata();
    logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata.getFunctionAndTypeManager()), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
    builder = new PlanBuilder(getQueryRunner().getDefaultSession(), new PlanNodeIdAllocator(), metadata);
    ConnectorId connectorId = getCurrentConnectorId();
    TableHandle lineitemTableHandle = new TableHandle(connectorId, new TpchTableHandle("lineitem", 1.0), TestingTransactionHandle.create(), Optional.empty());
    lineitemOrderKeyVariable = builder.variable("LINEITEM_OK", BIGINT);
    lineitemTableScanNode = builder.tableScan(lineitemTableHandle, ImmutableList.of(lineitemOrderKeyVariable), ImmutableMap.of(lineitemOrderKeyVariable, new TpchColumnHandle("orderkey", BIGINT)));
    TableHandle ordersTableHandle = new TableHandle(connectorId, new TpchTableHandle("orders", 1.0), TestingTransactionHandle.create(), Optional.empty());
    ordersOrderKeyVariable = builder.variable("ORDERS_OK", BIGINT);
    ordersTableScanNode = builder.tableScan(ordersTableHandle, ImmutableList.of(ordersOrderKeyVariable), ImmutableMap.of(ordersOrderKeyVariable, new TpchColumnHandle("orderkey", BIGINT)));
}
Also used : RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) LogicalRowExpressions(com.facebook.presto.expressions.LogicalRowExpressions) TableHandle(com.facebook.presto.spi.TableHandle) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) ConnectorId(com.facebook.presto.spi.ConnectorId) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) BeforeClass(org.testng.annotations.BeforeClass)

Example 17 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class TestValidateStreamingAggregations method validatePlan.

private void validatePlan(Function<PlanBuilder, PlanNode> planProvider) {
    PlanBuilder builder = new PlanBuilder(TEST_SESSION, idAllocator, metadata);
    PlanNode planNode = planProvider.apply(builder);
    TypeProvider types = builder.getTypes();
    getQueryRunner().inTransaction(session -> {
        // metadata.getCatalogHandle() registers the catalog for the transaction
        session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog));
        new ValidateStreamingAggregations().validate(planNode, session, metadata, sqlParser, types, WarningCollector.NOOP);
        return null;
    });
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)

Example 18 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class TestValidateAggregationsWithDefaultValues method setup.

@BeforeClass
public void setup() {
    metadata = getQueryRunner().getMetadata();
    builder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), metadata);
    ConnectorId connectorId = getCurrentConnectorId();
    TpchTableHandle nationTpchTableHandle = new TpchTableHandle("nation", 1.0);
    TableHandle nationTableHandle = new TableHandle(connectorId, nationTpchTableHandle, TestingTransactionHandle.create(), Optional.of(new TpchTableLayoutHandle(nationTpchTableHandle, TupleDomain.all())));
    TpchColumnHandle nationkeyColumnHandle = new TpchColumnHandle("nationkey", BIGINT);
    variable = builder.variable("nationkey");
    tableScanNode = builder.tableScan(nationTableHandle, ImmutableList.of(variable), ImmutableMap.of(variable, nationkeyColumnHandle));
}
Also used : PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) TableHandle(com.facebook.presto.spi.TableHandle) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) TpchTableLayoutHandle(com.facebook.presto.tpch.TpchTableLayoutHandle) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) ConnectorId(com.facebook.presto.spi.ConnectorId) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) BeforeClass(org.testng.annotations.BeforeClass)

Example 19 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class TestValidateStreamingJoins method validatePlan.

private void validatePlan(Function<PlanBuilder, PlanNode> planProvider) {
    PlanBuilder builder = new PlanBuilder(TEST_SESSION, idAllocator, metadata);
    PlanNode planNode = planProvider.apply(builder);
    TypeProvider types = builder.getTypes();
    getQueryRunner().inTransaction(testSession, session -> {
        session.getCatalog().ifPresent(catalog -> metadata.getCatalogHandle(session, catalog));
        new ValidateStreamingJoins().validate(planNode, session, metadata, sqlParser, types, WarningCollector.NOOP);
        return null;
    });
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)

Example 20 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.

the class TestPinotPlanOptimizer method testDateFieldCompareToTimestampLiteralPredicatePushdown.

@Test
public void testDateFieldCompareToTimestampLiteralPredicatePushdown() {
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    FilterNode filter = filter(planBuilder, tableScan(planBuilder, pinotTable, regionId, city, fare, daysSinceEpoch), getRowExpression("dayssinceepoch <  TIMESTAMP '2014-01-31 00:00:00 UTC'", defaultSessionHolder));
    PlanNode originalPlan = limit(planBuilder, 50L, filter);
    PlanNode optimized = getOptimizedPlan(planBuilder, originalPlan);
    assertPlanMatch(optimized, PinotTableScanMatcher.match(pinotTable, Optional.of("SELECT regionId, city, fare, daysSinceEpoch FROM hybrid WHERE \\(dayssinceepoch < 16101\\) LIMIT 50"), Optional.of(false), originalPlan.getOutputVariables(), useSqlSyntax()), typeProvider);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) FilterNode(com.facebook.presto.spi.plan.FilterNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Aggregations

PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)70 Test (org.testng.annotations.Test)56 PlanNode (com.facebook.presto.spi.plan.PlanNode)41 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)31 TableScanNode (com.facebook.presto.spi.plan.TableScanNode)25 ImmutableList (com.google.common.collect.ImmutableList)23 ImmutableMap (com.google.common.collect.ImmutableMap)23 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)21 TopNNode (com.facebook.presto.spi.plan.TopNNode)20 Map (java.util.Map)19 Function (java.util.function.Function)19 Assert.assertEquals (org.testng.Assert.assertEquals)19 Ordering (com.facebook.presto.spi.plan.Ordering)18 OrderingScheme (com.facebook.presto.spi.plan.OrderingScheme)18 ProjectNode (com.facebook.presto.spi.plan.ProjectNode)18 Optional (java.util.Optional)18 BiConsumer (java.util.function.BiConsumer)18 Collectors (java.util.stream.Collectors)18 PinotColumnHandle (com.facebook.presto.pinot.PinotColumnHandle)16 SortOrder (com.facebook.presto.common.block.SortOrder)15