Search in sources :

Example 51 with ProjectNode

use of com.facebook.presto.spi.plan.ProjectNode in project presto by prestodb.

the class TestVerifyOnlyOneOutputNode method testValidateSuccessful.

@Test
public void testValidateSuccessful() {
    // random seemingly valid plan
    PlanNode root = new OutputNode(Optional.empty(), idAllocator.getNextId(), new ProjectNode(idAllocator.getNextId(), new ValuesNode(Optional.empty(), idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of()), Assignments.of()), ImmutableList.of(), ImmutableList.of());
    new VerifyOnlyOneOutputNode().validate(root, null, null, null, null, WarningCollector.NOOP);
}
Also used : ValuesNode(com.facebook.presto.spi.plan.ValuesNode) OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) PlanNode(com.facebook.presto.spi.plan.PlanNode) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Example 52 with ProjectNode

use of com.facebook.presto.spi.plan.ProjectNode in project presto by prestodb.

the class TestPinotQueryGenerator method testSimpleSelectWithTopN.

@Test
public void testSimpleSelectWithTopN() {
    pinotConfig.setPushdownTopNBrokerQueries(true);
    SessionHolder sessionHolder = new SessionHolder(pinotConfig);
    PlanBuilder planBuilder = createPlanBuilder(new SessionHolder(pinotConfig));
    TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, regionId, city, fare);
    TopNNode topNFare = topN(planBuilder, 50L, ImmutableList.of("fare"), ImmutableList.of(false), tableScanNode);
    testPinotQuery(pinotConfig, topNFare, "SELECT regionId, city, fare FROM realtimeOnly ORDER BY fare DESC LIMIT 50", sessionHolder, ImmutableMap.of());
    TopNNode topnFareAndCity = topN(planBuilder, 50L, ImmutableList.of("fare", "city"), ImmutableList.of(true, false), tableScanNode);
    testPinotQuery(pinotConfig, topnFareAndCity, "SELECT regionId, city, fare FROM realtimeOnly ORDER BY fare, city DESC LIMIT 50", sessionHolder, ImmutableMap.of());
    ProjectNode projectNode = project(planBuilder, topnFareAndCity, ImmutableList.of("regionid", "city"));
    testPinotQuery(pinotConfig, projectNode, "SELECT regionId, city FROM realtimeOnly ORDER BY fare, city DESC LIMIT 50", sessionHolder, ImmutableMap.of());
}
Also used : TableScanNode(com.facebook.presto.spi.plan.TableScanNode) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) TopNNode(com.facebook.presto.spi.plan.TopNNode) Test(org.testng.annotations.Test)

Example 53 with ProjectNode

use of com.facebook.presto.spi.plan.ProjectNode in project presto by prestodb.

the class TestPinotQueryGeneratorSql method testAggregationWithGroupBy.

@Test
public void testAggregationWithGroupBy() {
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, regionId, city, fare);
    AggregationNode aggregationNode = planBuilder.aggregation(aggregationNodeBuilder -> aggregationNodeBuilder.source(tableScanNode).singleGroupingSet(variable("city"), variable("regionid")).addAggregation(planBuilder.variable("sum_fare"), getRowExpression("sum(fare)", defaultSessionHolder)).addAggregation(planBuilder.variable("count_regionid"), getRowExpression("count(regionid)", defaultSessionHolder)));
    testPinotQuery(pinotConfig, aggregationNode, ImmutableList.of("SELECT city, regionId, sum(fare), count(regionId) FROM realtimeOnly GROUP BY city, regionId LIMIT 10000", "SELECT city, regionId, count(regionId), sum(fare) FROM realtimeOnly GROUP BY city, regionId LIMIT 10000"), defaultSessionHolder, ImmutableMap.of());
    ProjectNode project = planBuilder.project(Assignments.builder().put(variable("count_regionid"), variable("count_regionid")).put(variable("city"), variable("city")).put(variable("regionid"), variable("regionid")).put(variable("sum_fare"), variable("sum_fare")).build(), aggregationNode);
    testPinotQuery(pinotConfig, project, "SELECT city, regionId, count(regionId), sum(fare) FROM realtimeOnly GROUP BY city, regionId LIMIT 10000", defaultSessionHolder, ImmutableMap.of());
    project = planBuilder.project(Assignments.builder().put(variable("count_regionid"), variable("count_regionid")).put(variable("regionid"), variable("regionid")).put(variable("sum_fare"), variable("sum_fare")).build(), aggregationNode);
    testPinotQuery(pinotConfig, project, "SELECT city, regionId, count(regionId), sum(fare) FROM realtimeOnly GROUP BY city, regionId LIMIT 10000", defaultSessionHolder, ImmutableMap.of());
    project = planBuilder.project(Assignments.builder().put(variable("count_regionid"), variable("count_regionid")).put(variable("city"), variable("city")).put(variable("sum_fare"), variable("sum_fare")).build(), aggregationNode);
    testPinotQuery(pinotConfig, project, "SELECT city, regionId, count(regionId), sum(fare) FROM realtimeOnly GROUP BY city, regionId LIMIT 10000", defaultSessionHolder, ImmutableMap.of());
    project = planBuilder.project(Assignments.builder().put(variable("sum_fare"), variable("sum_fare")).put(variable("count_regionid"), variable("count_regionid")).build(), aggregationNode);
    testPinotQuery(pinotConfig, project, "SELECT city, regionId, sum(fare), count(regionId) FROM realtimeOnly GROUP BY city, regionId LIMIT 10000", defaultSessionHolder, ImmutableMap.of());
}
Also used : TableScanNode(com.facebook.presto.spi.plan.TableScanNode) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Aggregations

ProjectNode (com.facebook.presto.spi.plan.ProjectNode)53 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)41 Assignments (com.facebook.presto.spi.plan.Assignments)33 PlanNode (com.facebook.presto.spi.plan.PlanNode)23 RowExpression (com.facebook.presto.spi.relation.RowExpression)20 OriginalExpressionUtils.castToRowExpression (com.facebook.presto.sql.relational.OriginalExpressionUtils.castToRowExpression)19 CallExpression (com.facebook.presto.spi.relation.CallExpression)16 Expression (com.facebook.presto.sql.tree.Expression)16 ImmutableList (com.google.common.collect.ImmutableList)15 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)14 Map (java.util.Map)12 Test (org.testng.annotations.Test)12 FilterNode (com.facebook.presto.spi.plan.FilterNode)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 Cast (com.facebook.presto.sql.tree.Cast)10 SymbolReference (com.facebook.presto.sql.tree.SymbolReference)10 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)8 List (java.util.List)8 Type (com.facebook.presto.common.type.Type)7 Set (java.util.Set)7