Search in sources :

Example 1 with PinotQueryGenerator

use of com.facebook.presto.pinot.query.PinotQueryGenerator in project presto by prestodb.

the class TestPinotSplitManager method testSegmentSplitsHelperNoFilter.

private void testSegmentSplitsHelperNoFilter(PinotTableHandle table, int segmentsPerSplit, int expectedNumSplits, boolean expectFilter) {
    PinotConfig pinotConfig = new PinotConfig().setForbidBrokerQueries(false);
    SessionHolder sessionHolder = new SessionHolder(pinotConfig);
    PlanBuilder planBuilder = createPlanBuilder(sessionHolder);
    PlanNode plan = tableScan(planBuilder, table, regionId, city, fare, secondsSinceEpoch);
    PinotQueryGenerator.PinotQueryGeneratorResult pinotQueryGeneratorResult = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution).generate(plan, sessionHolder.getConnectorSession()).get();
    List<PinotColumnHandle> expectedHandles = ImmutableList.copyOf(pinotQueryGeneratorResult.getContext().getAssignments(pinotQueryGeneratorResult.getGeneratedPinotQuery().getFormat() == PinotQueryGenerator.PinotQueryFormat.SQL).values());
    PinotQueryGenerator.GeneratedPinotQuery generatedPql = pinotQueryGeneratorResult.getGeneratedPinotQuery();
    PinotTableHandle pinotTableHandle = new PinotTableHandle(table.getConnectorId(), table.getSchemaName(), table.getTableName(), Optional.of(false), Optional.of(expectedHandles), Optional.of(generatedPql));
    List<PinotSplit> splits = getSplitsHelper(pinotTableHandle, segmentsPerSplit, false);
    assertSplits(splits, expectedNumSplits, SEGMENT);
    splits.forEach(s -> assertSegmentSplitWellFormed(s, expectFilter));
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) PinotQueryGenerator(com.facebook.presto.pinot.query.PinotQueryGenerator) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)

Example 2 with PinotQueryGenerator

use of com.facebook.presto.pinot.query.PinotQueryGenerator in project presto by prestodb.

the class TestPinotSplitManager method testBrokerTopNLarge.

private void testBrokerTopNLarge(PinotTableHandle table, int sessionTopNLarge, int configTopNLarge, boolean useSql) {
    String topNLimitKeyword = useSql ? "LIMIT " : "TOP ";
    PinotConfig pinotConfig = new PinotConfig().setUsePinotSqlForBrokerQueries(useSql).setTopNLarge(configTopNLarge);
    SessionHolder sessionHolder = new SessionHolder(pinotConfig);
    ConnectorSession session = createSessionWithTopNLarge(sessionTopNLarge, pinotConfig);
    PlanBuilder planBuilder = createPlanBuilder(sessionHolder);
    PlanNode tableScanNode = tableScan(planBuilder, table, regionId, city, fare, secondsSinceEpoch);
    AggregationNode aggregationNode = planBuilder.aggregation(aggregationNodeBuilder -> aggregationNodeBuilder.source(tableScanNode).singleGroupingSet(variable("city"), variable("regionid")).addAggregation(planBuilder.variable("sum_fare"), getRowExpression("sum(fare)", sessionHolder)).addAggregation(planBuilder.variable("count_regionid"), getRowExpression("count(regionid)", sessionHolder)));
    PinotQueryGenerator.PinotQueryGeneratorResult pinotQueryGeneratorResult = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution).generate(aggregationNode, session).get();
    String[] limits = pinotQueryGeneratorResult.getGeneratedPinotQuery().getQuery().split(topNLimitKeyword);
    assertEquals(Integer.parseInt(limits[1]), sessionTopNLarge);
    aggregationNode = planBuilder.aggregation(aggregationNodeBuilder -> aggregationNodeBuilder.source(tableScanNode).singleGroupingSet(variable("city"), variable("regionid")).addAggregation(planBuilder.variable("sum_fare"), getRowExpression("sum(fare)", sessionHolder)).addAggregation(planBuilder.variable("count_regionid"), getRowExpression("count(regionid)", sessionHolder)));
    pinotQueryGeneratorResult = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution).generate(aggregationNode, sessionHolder.getConnectorSession()).get();
    limits = pinotQueryGeneratorResult.getGeneratedPinotQuery().getQuery().split(topNLimitKeyword);
    assertEquals(Integer.parseInt(limits[1]), configTopNLarge);
}
Also used : AggregationNode(com.facebook.presto.spi.plan.AggregationNode) ConnectorSplitSource(com.facebook.presto.spi.ConnectorSplitSource) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) PinotQueryGenerator(com.facebook.presto.pinot.query.PinotQueryGenerator) MoreFutures.getFutureValue(com.facebook.airlift.concurrent.MoreFutures.getFutureValue) ArrayList(java.util.ArrayList) NOT_PARTITIONED(com.facebook.presto.spi.connector.NotPartitionedPartitionHandle.NOT_PARTITIONED) ImmutableList(com.google.common.collect.ImmutableList) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) Splitter(com.google.common.base.Splitter) ENGLISH(java.util.Locale.ENGLISH) Assert.assertFalse(org.testng.Assert.assertFalse) SEGMENT(com.facebook.presto.pinot.PinotSplit.SplitType.SEGMENT) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) UTC_KEY(com.facebook.presto.common.type.TimeZoneKey.UTC_KEY) Executors(java.util.concurrent.Executors) ConnectorSession(com.facebook.presto.spi.ConnectorSession) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) PlanNode(com.facebook.presto.spi.plan.PlanNode) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) BROKER(com.facebook.presto.pinot.PinotSplit.SplitType.BROKER) PlanNode(com.facebook.presto.spi.plan.PlanNode) PinotQueryGenerator(com.facebook.presto.pinot.query.PinotQueryGenerator) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) ConnectorSession(com.facebook.presto.spi.ConnectorSession) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)

Example 3 with PinotQueryGenerator

use of com.facebook.presto.pinot.query.PinotQueryGenerator in project presto by prestodb.

the class TestPinotSplitManager method testSegmentSplitsHelperWithFilter.

private void testSegmentSplitsHelperWithFilter(PinotTableHandle table, int segmentsPerSplit, int expectedNumSplits) {
    PinotConfig pinotConfig = new PinotConfig().setForbidBrokerQueries(false);
    SessionHolder sessionHolder = new SessionHolder(pinotConfig);
    PlanBuilder planBuilder = createPlanBuilder(sessionHolder);
    PlanNode plan = filter(planBuilder, tableScan(planBuilder, table, regionId, city, fare, secondsSinceEpoch), getRowExpression("city = 'Boston'", sessionHolder));
    PinotQueryGenerator.PinotQueryGeneratorResult pinotQueryGeneratorResult = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution).generate(plan, sessionHolder.getConnectorSession()).get();
    List<PinotColumnHandle> expectedHandles = ImmutableList.copyOf(pinotQueryGeneratorResult.getContext().getAssignments(pinotQueryGeneratorResult.getGeneratedPinotQuery().getFormat() == PinotQueryGenerator.PinotQueryFormat.SQL).values());
    PinotQueryGenerator.GeneratedPinotQuery generatedPql = pinotQueryGeneratorResult.getGeneratedPinotQuery();
    PinotTableHandle pinotTableHandle = new PinotTableHandle(table.getConnectorId(), table.getSchemaName(), table.getTableName(), Optional.of(false), Optional.of(expectedHandles), Optional.of(generatedPql));
    List<PinotSplit> splits = getSplitsHelper(pinotTableHandle, segmentsPerSplit, false);
    assertSplits(splits, expectedNumSplits, SEGMENT);
    splits.forEach(s -> assertSegmentSplitWellFormed(s, true));
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) PinotQueryGenerator(com.facebook.presto.pinot.query.PinotQueryGenerator) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)

Example 4 with PinotQueryGenerator

use of com.facebook.presto.pinot.query.PinotQueryGenerator in project presto by prestodb.

the class TestPinotSplitManager method testSegmentLimitLarge.

private void testSegmentLimitLarge(PinotTableHandle table, int sessionLimitLarge, int configLimitLarge, boolean useSql) {
    PinotConfig pinotConfig = new PinotConfig().setUsePinotSqlForBrokerQueries(useSql).setLimitLargeForSegment(configLimitLarge);
    SessionHolder sessionHolder = new SessionHolder(pinotConfig);
    ConnectorSession session = createSessionWithLimitLarge(sessionLimitLarge, pinotConfig);
    PlanBuilder planBuilder = createPlanBuilder(sessionHolder);
    PlanNode plan = tableScan(planBuilder, table, regionId, city, fare, secondsSinceEpoch);
    PinotQueryGenerator.PinotQueryGeneratorResult pinotQueryGeneratorResult = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution).generate(plan, session).get();
    String[] limits = pinotQueryGeneratorResult.getGeneratedPinotQuery().getQuery().split("LIMIT ");
    assertEquals(Integer.parseInt(limits[1]), sessionLimitLarge);
    plan = tableScan(planBuilder, table, regionId, city, fare, secondsSinceEpoch);
    pinotQueryGeneratorResult = new PinotQueryGenerator(pinotConfig, functionAndTypeManager, functionAndTypeManager, standardFunctionResolution).generate(plan, sessionHolder.getConnectorSession()).get();
    limits = pinotQueryGeneratorResult.getGeneratedPinotQuery().getQuery().split("LIMIT ");
    assertEquals(Integer.parseInt(limits[1]), configLimitLarge);
}
Also used : PlanNode(com.facebook.presto.spi.plan.PlanNode) PinotQueryGenerator(com.facebook.presto.pinot.query.PinotQueryGenerator) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) ConnectorSession(com.facebook.presto.spi.ConnectorSession) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)

Aggregations

PinotQueryGenerator (com.facebook.presto.pinot.query.PinotQueryGenerator)4 PlanNode (com.facebook.presto.spi.plan.PlanNode)4 PlanBuilder (com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder)4 ConnectorSession (com.facebook.presto.spi.ConnectorSession)2 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)2 MoreFutures.getFutureValue (com.facebook.airlift.concurrent.MoreFutures.getFutureValue)1 UTC_KEY (com.facebook.presto.common.type.TimeZoneKey.UTC_KEY)1 BROKER (com.facebook.presto.pinot.PinotSplit.SplitType.BROKER)1 SEGMENT (com.facebook.presto.pinot.PinotSplit.SplitType.SEGMENT)1 ConnectorSplitSource (com.facebook.presto.spi.ConnectorSplitSource)1 NOT_PARTITIONED (com.facebook.presto.spi.connector.NotPartitionedPartitionHandle.NOT_PARTITIONED)1 AggregationNode (com.facebook.presto.spi.plan.AggregationNode)1 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)1 Splitter (com.google.common.base.Splitter)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ENGLISH (java.util.Locale.ENGLISH)1