use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.
the class TestPinotQueryGenerator method testDistinctCountPushdownWithVariableSuffix.
@Test
public void testDistinctCountPushdownWithVariableSuffix() {
Map<VariableReferenceExpression, PinotColumnHandle> columnHandleMap = ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "regionid_33", regionId.getDataType()), regionId);
PlanNode justScan = buildPlan(planBuilder -> tableScan(planBuilder, pinotTable, columnHandleMap));
PlanNode markDistinct = buildPlan(planBuilder -> markDistinct(planBuilder, variable("regionid$distinct_62"), ImmutableList.of(variable("regionid")), justScan));
PlanNode aggregate = buildPlan(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(markDistinct).addAggregation(planBuilder.variable("count(regionid_33)"), getRowExpression("count(regionid_33)", defaultSessionHolder), Optional.empty(), Optional.empty(), false, Optional.of(variable("regionid$distinct_62"))).globalGrouping()));
testPinotQuery(new PinotConfig().setAllowMultipleAggregations(true), planBuilder -> planBuilder.limit(10, aggregate), "SELECT DISTINCTCOUNT(regionId) FROM realtimeOnly");
}
use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.
the class TestPinotQueryGeneratorSql method testDefaultNoTopNPushdown.
@Test
public void testDefaultNoTopNPushdown() {
PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, city, fare);
AggregationNode aggregationNode = planBuilder.aggregation(aggregationNodeBuilder -> aggregationNodeBuilder.source(tableScanNode).singleGroupingSet(variable("city")).addAggregation(planBuilder.variable("sum_fare"), getRowExpression("sum(fare)", defaultSessionHolder)));
pinotConfig.setPushdownTopNBrokerQueries(false);
TopNNode topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), aggregationNode, 1000, new OrderingScheme(ImmutableList.of(new Ordering(variable("sum_fare"), SortOrder.ASC_NULLS_FIRST))), TopNNode.Step.SINGLE);
Optional<PinotQueryGenerator.PinotQueryGeneratorResult> generatedQuery = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution).generate(topN, defaultSessionHolder.getConnectorSession());
assertFalse(generatedQuery.isPresent());
SessionHolder sessionHolder = new SessionHolder(pinotConfig);
testPinotQuery(pinotConfig, aggregationNode, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city LIMIT 10000", sessionHolder, ImmutableMap.of());
}
use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.
the class TestPinotQueryGeneratorSql method testAggregationWithOrderByPushDownInTopN.
@Override
@Test
public void testAggregationWithOrderByPushDownInTopN() {
pinotConfig.setPushdownTopNBrokerQueries(true);
SessionHolder sessionHolder = new SessionHolder(pinotConfig);
PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, city, fare);
AggregationNode aggregationNode = planBuilder.aggregation(aggregationNodeBuilder -> aggregationNodeBuilder.source(tableScanNode).singleGroupingSet(variable("city")).addAggregation(planBuilder.variable("sum_fare"), getRowExpression("sum(fare)", defaultSessionHolder)));
testPinotQuery(pinotConfig, aggregationNode, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city LIMIT 10000", sessionHolder, ImmutableMap.of());
TopNNode topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), aggregationNode, 50L, new OrderingScheme(ImmutableList.of(new Ordering(variable("city"), SortOrder.DESC_NULLS_FIRST))), TopNNode.Step.SINGLE);
testPinotQuery(pinotConfig, topN, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city ORDER BY city DESC LIMIT 50", sessionHolder, ImmutableMap.of());
topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), aggregationNode, 1000L, new OrderingScheme(ImmutableList.of(new Ordering(variable("sum_fare"), SortOrder.ASC_NULLS_FIRST))), TopNNode.Step.SINGLE);
testPinotQuery(pinotConfig, topN, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city ORDER BY sum(fare) LIMIT 1000", sessionHolder, ImmutableMap.of());
topN = new TopNNode(Optional.empty(), planBuilder.getIdAllocator().getNextId(), aggregationNode, 1000L, new OrderingScheme(ImmutableList.of(new Ordering(variable("sum_fare"), SortOrder.ASC_NULLS_FIRST))), TopNNode.Step.SINGLE);
testPinotQuery(pinotConfig, topN, "SELECT city, sum(fare) FROM realtimeOnly GROUP BY city ORDER BY sum(fare) LIMIT 1000", sessionHolder, ImmutableMap.of());
}
use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.
the class TestPinotQueryGeneratorSql method testSelectionWithOrderBy.
@Test
public void testSelectionWithOrderBy() {
pinotConfig.setPushdownTopNBrokerQueries(true);
PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
TableScanNode tableScanNode = tableScan(planBuilder, pinotTable, regionId, city, fare);
SessionHolder sessionHolder = new SessionHolder(pinotConfig);
testPinotQuery(pinotConfig, topN(planBuilder, 50L, ImmutableList.of("fare"), ImmutableList.of(false), tableScanNode), "SELECT regionId, city, fare FROM realtimeOnly ORDER BY fare DESC LIMIT 50", sessionHolder, ImmutableMap.of());
testPinotQuery(pinotConfig, topN(planBuilder, 50L, ImmutableList.of("fare", "city"), ImmutableList.of(true, false), tableScanNode), "SELECT regionId, city, fare FROM realtimeOnly ORDER BY fare, city DESC LIMIT 50", sessionHolder, ImmutableMap.of());
testPinotQuery(pinotConfig, topN(planBuilder, 50L, ImmutableList.of("city", "fare"), ImmutableList.of(false, true), tableScanNode), "SELECT regionId, city, fare FROM realtimeOnly ORDER BY city DESC, fare LIMIT 50", sessionHolder, ImmutableMap.of());
TopNNode topNNode = topN(planBuilder, 50L, ImmutableList.of("fare", "city"), ImmutableList.of(true, false), tableScanNode);
testPinotQuery(pinotConfig, project(planBuilder, topNNode, ImmutableList.of("regionid", "city")), "SELECT regionId, city FROM realtimeOnly ORDER BY fare, city DESC LIMIT 50", sessionHolder, ImmutableMap.of());
tableScanNode = tableScan(planBuilder, pinotTable, fare, city, regionId);
testPinotQuery(pinotConfig, topN(planBuilder, 500L, ImmutableList.of("fare"), ImmutableList.of(false), tableScanNode), "SELECT fare, city, regionId FROM realtimeOnly ORDER BY fare DESC LIMIT 500", sessionHolder, ImmutableMap.of());
testPinotQuery(pinotConfig, topN(planBuilder, 5000L, ImmutableList.of("fare", "city"), ImmutableList.of(true, false), tableScanNode), "SELECT fare, city, regionId FROM realtimeOnly ORDER BY fare, city DESC LIMIT 5000", sessionHolder, ImmutableMap.of());
}
use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder in project presto by prestodb.
the class TestRemoveUnsupportedDynamicFilters 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)));
}
Aggregations