use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class TestPinotQueryBase method project.
protected ProjectNode project(PlanBuilder planBuilder, PlanNode source, List<String> columnNames) {
Map<String, VariableReferenceExpression> incomingColumns = source.getOutputVariables().stream().collect(toMap(VariableReferenceExpression::getName, identity()));
Assignments.Builder assignmentsBuilder = Assignments.builder();
columnNames.forEach(columnName -> {
VariableReferenceExpression variable = requireNonNull(incomingColumns.get(columnName), "Couldn't find the incoming column " + columnName);
assignmentsBuilder.put(variable, variable);
});
return planBuilder.project(assignmentsBuilder.build(), source);
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class TestPinotQueryBase method tableScan.
protected TableScanNode tableScan(PlanBuilder planBuilder, PinotTableHandle connectorTableHandle, Map<VariableReferenceExpression, PinotColumnHandle> columnHandles) {
List<VariableReferenceExpression> variables = ImmutableList.copyOf(columnHandles.keySet());
ImmutableMap.Builder<VariableReferenceExpression, ColumnHandle> assignments = ImmutableMap.builder();
for (VariableReferenceExpression variable : columnHandles.keySet()) {
assignments.put(variable, columnHandles.get(variable));
}
TableHandle tableHandle = new TableHandle(pinotConnectorId, connectorTableHandle, TestingTransactionHandle.create(), Optional.empty());
return planBuilder.tableScan(tableHandle, variables, assignments.build());
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class TestPinotPlanOptimizerSql method testDistinctLimitPushdown.
@Test
public void testDistinctLimitPushdown() {
PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
PlanNode originalPlan = distinctLimit(planBuilder, ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "regionid", BIGINT)), 50L, tableScan(planBuilder, pinotTable, regionId));
PlanNode optimized = getOptimizedPlan(planBuilder, originalPlan);
assertPlanMatch(optimized, PinotTableScanMatcher.match(pinotTable, Optional.of("SELECT regionId FROM hybrid GROUP BY regionId LIMIT 50"), Optional.of(false), originalPlan.getOutputVariables(), useSqlSyntax()), typeProvider);
planBuilder = createPlanBuilder(defaultSessionHolder);
originalPlan = distinctLimit(planBuilder, ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "regionid", BIGINT), new VariableReferenceExpression(Optional.empty(), "city", VARCHAR)), 50L, tableScan(planBuilder, pinotTable, regionId, city));
optimized = getOptimizedPlan(planBuilder, originalPlan);
assertPlanMatch(optimized, PinotTableScanMatcher.match(pinotTable, Optional.of("SELECT regionId, city FROM hybrid GROUP BY regionId, city LIMIT 50"), Optional.of(false), originalPlan.getOutputVariables(), useSqlSyntax()), typeProvider);
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class TestPinotQueryGenerator method testDistinctLimitPushdown.
@Test
public void testDistinctLimitPushdown() {
PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
DistinctLimitNode distinctLimitNode = distinctLimit(planBuilder, ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "regionid", BIGINT)), 50L, tableScan(planBuilder, pinotTable, regionId));
testPinotQuery(pinotConfig, distinctLimitNode, String.format("SELECT %s FROM realtimeOnly GROUP BY regionId %s 50", getExpectedDistinctOutput("regionId"), getGroupByLimitKey()), defaultSessionHolder, ImmutableMap.of());
planBuilder = createPlanBuilder(defaultSessionHolder);
distinctLimitNode = distinctLimit(planBuilder, ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "regionid", BIGINT), new VariableReferenceExpression(Optional.empty(), "city", VARCHAR)), 50L, tableScan(planBuilder, pinotTable, regionId, city));
testPinotQuery(pinotConfig, distinctLimitNode, String.format("SELECT %s FROM realtimeOnly GROUP BY regionId, city %s 50", getExpectedDistinctOutput("regionId, city"), getGroupByLimitKey()), defaultSessionHolder, ImmutableMap.of());
}
use of com.facebook.presto.spi.relation.VariableReferenceExpression in project presto by prestodb.
the class TestPinotQueryGenerator method testAggWithUDFInGroupBy.
@Test
public void testAggWithUDFInGroupBy() {
LinkedHashMap<String, String> aggProjection = new LinkedHashMap<>();
aggProjection.put("date", "date_trunc('day', cast(from_unixtime(secondssinceepoch - 50) AS TIMESTAMP))");
PlanNode justDate = buildPlan(planBuilder -> project(planBuilder, tableScan(planBuilder, pinotTable, regionId, secondsSinceEpoch, city, fare), aggProjection, defaultSessionHolder));
testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(justDate).singleGroupingSet(new VariableReferenceExpression(Optional.empty(), "date", TIMESTAMP)).addAggregation(planBuilder.variable("agg"), getRowExpression("count(*)", defaultSessionHolder))), String.format("SELECT %s FROM realtimeOnly GROUP BY dateTimeConvert(SUB(secondsSinceEpoch, 50), '1:SECONDS:EPOCH', '1:MILLISECONDS:EPOCH', '1:DAYS') %s 10000", getExpectedAggOutput("count(*)", "dateTimeConvert(SUB(secondsSinceEpoch, 50), '1:SECONDS:EPOCH', '1:MILLISECONDS:EPOCH', '1:DAYS')"), getGroupByLimitKey()));
aggProjection.put("city", "city");
PlanNode newScanWithCity = buildPlan(planBuilder -> project(planBuilder, tableScan(planBuilder, pinotTable, regionId, secondsSinceEpoch, city, fare), aggProjection, defaultSessionHolder));
testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(newScanWithCity).singleGroupingSet(new VariableReferenceExpression(Optional.empty(), "date", TIMESTAMP), variable("city")).addAggregation(planBuilder.variable("agg"), getRowExpression("count(*)", defaultSessionHolder))), String.format("SELECT %s FROM realtimeOnly GROUP BY dateTimeConvert(SUB(secondsSinceEpoch, 50), '1:SECONDS:EPOCH', '1:MILLISECONDS:EPOCH', '1:DAYS'), city %s 10000", getExpectedAggOutput("count(*)", "dateTimeConvert(SUB(secondsSinceEpoch, 50), '1:SECONDS:EPOCH', '1:MILLISECONDS:EPOCH', '1:DAYS'), city"), getGroupByLimitKey()));
}
Aggregations