Search in sources :

Example 1 with PinotColumnHandle

use of com.facebook.presto.pinot.PinotColumnHandle 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");
}
Also used : Arrays(java.util.Arrays) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) Assert.assertEquals(org.testng.Assert.assertEquals) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test) TIMESTAMP(com.facebook.presto.common.type.TimestampType.TIMESTAMP) DistinctLimitNode(com.facebook.presto.spi.plan.DistinctLimitNode) Function(java.util.function.Function) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ImmutableList(com.google.common.collect.ImmutableList) PinotTableHandle(com.facebook.presto.pinot.PinotTableHandle) Map(java.util.Map) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) BiConsumer(java.util.function.BiConsumer) OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) NoSuchElementException(java.util.NoSuchElementException) Assert.assertFalse(org.testng.Assert.assertFalse) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PinotColumnHandle(com.facebook.presto.pinot.PinotColumnHandle) SortOrder(com.facebook.presto.common.block.SortOrder) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) Ordering(com.facebook.presto.spi.plan.Ordering) Set(java.util.Set) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) PlanNode(com.facebook.presto.spi.plan.PlanNode) List(java.util.List) TestPinotQueryBase(com.facebook.presto.pinot.TestPinotQueryBase) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) PinotConfig(com.facebook.presto.pinot.PinotConfig) TopNNode(com.facebook.presto.spi.plan.TopNNode) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) PinotColumnHandle(com.facebook.presto.pinot.PinotColumnHandle) PlanNode(com.facebook.presto.spi.plan.PlanNode) PinotConfig(com.facebook.presto.pinot.PinotConfig) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Test(org.testng.annotations.Test)

Example 2 with PinotColumnHandle

use of com.facebook.presto.pinot.PinotColumnHandle in project presto by prestodb.

the class TestPinotPlanOptimizer method testDistinctCountPushdownNoOverride.

private void testDistinctCountPushdownNoOverride(PinotConfig pinotConfig) {
    PlanBuilder planBuilder = createPlanBuilder(new SessionHolder(pinotConfig));
    Map<VariableReferenceExpression, PinotColumnHandle> leftColumnHandleMap = ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "regionid", regionId.getDataType()), regionId);
    PlanNode leftJustScan = tableScan(planBuilder, pinotTable, leftColumnHandleMap);
    PlanNode leftAggregation = planBuilder.aggregation(aggBuilder -> aggBuilder.source(leftJustScan).addAggregation(planBuilder.variable("approx_distinct(regionid)"), getRowExpression("approx_distinct(regionid)", defaultSessionHolder), Optional.empty(), Optional.empty(), false, Optional.empty()).globalGrouping());
    PlanNode optimized = getOptimizedPlan(pinotConfig, planBuilder, leftAggregation);
    assertPlanMatch(optimized, PinotTableScanMatcher.match(pinotTable, Optional.of("SELECT DISTINCTCOUNTHLL\\(regionId\\) FROM hybrid"), Optional.of(false), leftAggregation.getOutputVariables(), useSqlSyntax()), typeProvider);
    PlanNode optimizedPlan = getOptimizedPlan(planBuilder, limit(planBuilder, 50L, tableScan(planBuilder, pinotTable, distinctCountDim)));
    assertPlanMatch(optimizedPlan, PinotTableScanMatcher.match(pinotTable, Optional.of("SELECT distinctCountDim FROM hybrid LIMIT 50"), Optional.of(false), optimizedPlan.getOutputVariables(), useSqlSyntax()), typeProvider);
}
Also used : PinotColumnHandle(com.facebook.presto.pinot.PinotColumnHandle) PlanNode(com.facebook.presto.spi.plan.PlanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)

Example 3 with PinotColumnHandle

use of com.facebook.presto.pinot.PinotColumnHandle in project presto by prestodb.

the class TestPinotPlanOptimizer method testSetOperationQueryWithSubQueriesPushdown.

@Test
public void testSetOperationQueryWithSubQueriesPushdown() {
    PlanBuilder planBuilder = createPlanBuilder(defaultSessionHolder);
    Map<VariableReferenceExpression, PinotColumnHandle> leftColumnHandleMap = ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "regionid", regionId.getDataType()), regionId);
    PlanNode leftJustScan = tableScan(planBuilder, pinotTable, leftColumnHandleMap);
    PlanNode leftMarkDistinct = markDistinct(planBuilder, variable("regionid$distinct"), ImmutableList.of(variable("regionid")), leftJustScan);
    PlanNode leftAggregation = planBuilder.aggregation(aggBuilder -> aggBuilder.source(leftMarkDistinct).addAggregation(planBuilder.variable("count(regionid)"), getRowExpression("count(regionid)", defaultSessionHolder), Optional.empty(), Optional.empty(), false, Optional.of(variable("regionid$distinct"))).globalGrouping());
    Map<VariableReferenceExpression, PinotColumnHandle> rightColumnHandleMap = ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "regionid_33", regionId.getDataType()), regionId);
    PlanNode rightJustScan = tableScan(planBuilder, pinotTable, rightColumnHandleMap);
    PlanNode rightMarkDistinct = markDistinct(planBuilder, variable("regionid$distinct_62"), ImmutableList.of(variable("regionid")), rightJustScan);
    PlanNode rightAggregation = planBuilder.aggregation(aggBuilder -> aggBuilder.source(rightMarkDistinct).addAggregation(planBuilder.variable("count(regionid_33)"), getRowExpression("count(regionid_33)", defaultSessionHolder), Optional.empty(), Optional.empty(), false, Optional.of(variable("regionid$distinct_62"))).globalGrouping());
    validateSetOperationOptimizer(planBuilder, planBuilder.union(ArrayListMultimap.create(), ImmutableList.of(leftAggregation, rightAggregation)));
    validateSetOperationOptimizer(planBuilder, planBuilder.intersect(ArrayListMultimap.create(), ImmutableList.of(leftAggregation, rightAggregation)));
    validateSetOperationOptimizer(planBuilder, planBuilder.except(ArrayListMultimap.create(), ImmutableList.of(leftAggregation, rightAggregation)));
}
Also used : PinotColumnHandle(com.facebook.presto.pinot.PinotColumnHandle) PlanNode(com.facebook.presto.spi.plan.PlanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 4 with PinotColumnHandle

use of com.facebook.presto.pinot.PinotColumnHandle in project presto by prestodb.

the class TestPinotPlanOptimizer method testDistinctCountInSubQueryPushdown.

private void testDistinctCountInSubQueryPushdown(String distinctCountFunctionName, PinotConfig pinotConfig) {
    PlanBuilder planBuilder = createPlanBuilder(new SessionHolder(pinotConfig));
    Map<VariableReferenceExpression, PinotColumnHandle> leftColumnHandleMap = ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "regionid", regionId.getDataType()), regionId);
    PlanNode leftJustScan = tableScan(planBuilder, pinotTable, leftColumnHandleMap);
    PlanNode leftMarkDistinct = markDistinct(planBuilder, variable("regionid$distinct"), ImmutableList.of(variable("regionid")), leftJustScan);
    PlanNode leftAggregation = planBuilder.aggregation(aggBuilder -> aggBuilder.source(leftMarkDistinct).addAggregation(planBuilder.variable("count(regionid)"), getRowExpression("count(regionid)", defaultSessionHolder), Optional.empty(), Optional.empty(), false, Optional.of(variable("regionid$distinct"))).globalGrouping());
    PlanNode optimized = getOptimizedPlan(pinotConfig, planBuilder, leftAggregation);
    assertPlanMatch(optimized, PinotTableScanMatcher.match(pinotTable, Optional.of(String.format("SELECT %s\\(regionId\\) FROM hybrid", distinctCountFunctionName)), Optional.of(false), leftAggregation.getOutputVariables(), useSqlSyntax()), typeProvider);
    Map<VariableReferenceExpression, PinotColumnHandle> rightColumnHandleMap = ImmutableMap.of(new VariableReferenceExpression(Optional.empty(), "regionid_33", regionId.getDataType()), regionId);
    PlanNode rightJustScan = tableScan(planBuilder, pinotTable, rightColumnHandleMap);
    PlanNode rightMarkDistinct = markDistinct(planBuilder, variable("regionid$distinct_62"), ImmutableList.of(variable("regionid")), rightJustScan);
    PlanNode rightAggregation = planBuilder.aggregation(aggBuilder -> aggBuilder.source(rightMarkDistinct).addAggregation(planBuilder.variable("count(regionid_33)"), getRowExpression("count(regionid_33)", defaultSessionHolder), Optional.empty(), Optional.empty(), false, Optional.of(variable("regionid$distinct_62"))).globalGrouping());
    optimized = getOptimizedPlan(pinotConfig, planBuilder, rightAggregation);
    assertPlanMatch(optimized, PinotTableScanMatcher.match(pinotTable, Optional.of(String.format("SELECT %s\\(regionId\\) FROM hybrid", distinctCountFunctionName)), Optional.of(false), rightAggregation.getOutputVariables(), useSqlSyntax()), typeProvider);
}
Also used : PinotColumnHandle(com.facebook.presto.pinot.PinotColumnHandle) PlanNode(com.facebook.presto.spi.plan.PlanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)

Example 5 with PinotColumnHandle

use of com.facebook.presto.pinot.PinotColumnHandle in project presto by prestodb.

the class PinotQueryGeneratorContext method getAssignments.

public LinkedHashMap<VariableReferenceExpression, PinotColumnHandle> getAssignments(boolean isSqlSyntax) {
    LinkedHashMap<VariableReferenceExpression, PinotColumnHandle> result = new LinkedHashMap<>();
    LinkedHashSet<VariableReferenceExpression> outputFields = new LinkedHashSet<>();
    if (!isSqlSyntax) {
        outputFields.addAll(groupByColumns);
    }
    outputFields.addAll(outputs.stream().filter(variable -> !hiddenColumnSet.contains(variable)).collect(Collectors.toList()));
    outputFields.stream().forEach(variable -> {
        Selection selection = selections.get(variable);
        PinotColumnHandle handle = selection.getOrigin() == Origin.TABLE_COLUMN ? new PinotColumnHandle(selection.getDefinition(), variable.getType(), PinotColumnHandle.PinotColumnType.REGULAR) : new PinotColumnHandle(variable, PinotColumnHandle.PinotColumnType.DERIVED);
        result.put(variable, handle);
    });
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PinotColumnHandle(com.facebook.presto.pinot.PinotColumnHandle) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

PinotColumnHandle (com.facebook.presto.pinot.PinotColumnHandle)8 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)8 LinkedHashMap (java.util.LinkedHashMap)5 SortOrder (com.facebook.presto.common.block.SortOrder)4 PinotConfig (com.facebook.presto.pinot.PinotConfig)4 PlanNode (com.facebook.presto.spi.plan.PlanNode)4 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)4 ImmutableList (com.google.common.collect.ImmutableList)4 String.format (java.lang.String.format)4 HashSet (java.util.HashSet)4 LinkedHashSet (java.util.LinkedHashSet)4 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 PINOT_QUERY_GENERATOR_FAILURE (com.facebook.presto.pinot.PinotErrorCode.PINOT_QUERY_GENERATOR_FAILURE)3 PINOT_UNSUPPORTED_EXPRESSION (com.facebook.presto.pinot.PinotErrorCode.PINOT_UNSUPPORTED_EXPRESSION)3 PinotException (com.facebook.presto.pinot.PinotException)3 PINOT_DISTINCT_COUNT_FUNCTION_NAME (com.facebook.presto.pinot.PinotPushdownUtils.PINOT_DISTINCT_COUNT_FUNCTION_NAME)3