Search in sources :

Example 6 with PlanBuilder

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

the class TestPinotQueryGenerator method testDistinctSelection.

@Test
public void testDistinctSelection() {
    PlanNode justScan = buildPlan(planBuilder -> tableScan(planBuilder, pinotTable, regionId, secondsSinceEpoch, city, fare));
    testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(justScan).singleGroupingSet(variable("regionid"))), "SELECT count(*) FROM realtimeOnly GROUP BY regionId TOP 10000");
}
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) PlanNode(com.facebook.presto.spi.plan.PlanNode) Test(org.testng.annotations.Test)

Example 7 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder 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());
}
Also used : VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) DistinctLimitNode(com.facebook.presto.spi.plan.DistinctLimitNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Test(org.testng.annotations.Test)

Example 8 with PlanBuilder

use of com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder 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()));
}
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) PlanNode(com.facebook.presto.spi.plan.PlanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 9 with PlanBuilder

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

the class TestPinotQueryGenerator method testAggWithArrayFunctionsInGroupBy.

@Test
public void testAggWithArrayFunctionsInGroupBy() {
    LinkedHashMap<String, String> aggProjection = new LinkedHashMap<>();
    aggProjection.put("array_max_0", "array_max(scores)");
    PlanNode justMaxScores = buildPlan(planBuilder -> project(planBuilder, tableScan(planBuilder, pinotTable, regionId, secondsSinceEpoch, city, fare, scores), aggProjection, defaultSessionHolder));
    testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(justMaxScores).singleGroupingSet(new VariableReferenceExpression(Optional.empty(), "array_max_0", DOUBLE)).addAggregation(planBuilder.variable("agg"), getRowExpression("count(*)", defaultSessionHolder))), String.format("SELECT %s FROM realtimeOnly GROUP BY arrayMax(scores) %s 10000", getExpectedAggOutput("count(*)", "arrayMax(scores)"), getGroupByLimitKey()));
    aggProjection.put("city", "city");
    PlanNode newScanWithCity = buildPlan(planBuilder -> project(planBuilder, tableScan(planBuilder, pinotTable, regionId, secondsSinceEpoch, city, fare, scores), aggProjection, defaultSessionHolder));
    testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(newScanWithCity).singleGroupingSet(new VariableReferenceExpression(Optional.empty(), "array_max_0", DOUBLE), variable("city")).addAggregation(planBuilder.variable("agg"), getRowExpression("count(*)", defaultSessionHolder))), String.format("SELECT %s FROM realtimeOnly GROUP BY arrayMax(scores), city %s 10000", getExpectedAggOutput("count(*)", "arrayMax(scores), city"), getGroupByLimitKey()));
}
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) PlanNode(com.facebook.presto.spi.plan.PlanNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 10 with PlanBuilder

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

the class TestPinotQueryGenerator method testDistinctCountGroupByPushdown.

@Test
public void testDistinctCountGroupByPushdown() {
    PlanNode justScan = buildPlan(planBuilder -> tableScan(planBuilder, pinotTable, regionId, secondsSinceEpoch, city, fare));
    PlanNode distinctAggregation = buildPlan(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(justScan).singleGroupingSet(variable("city"), variable("regionid"))));
    testPinotQuery(planBuilder -> planBuilder.aggregation(aggBuilder -> aggBuilder.source(distinctAggregation).singleGroupingSet(variable("city")).addAggregation(variable("count_regionid"), getRowExpression("count(regionid)", defaultSessionHolder))), String.format("SELECT %s FROM realtimeOnly GROUP BY city %s 10000", getExpectedAggOutput("DISTINCTCOUNT(regionId)", "city"), getGroupByLimitKey()));
}
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) PlanNode(com.facebook.presto.spi.plan.PlanNode) 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