use of io.trino.spi.connector.TopNApplicationResult in project trino by trinodb.
the class TestPushTopNIntoTableScan method testPushPartialTopNIntoTableScan.
@Test
public void testPushPartialTopNIntoTableScan() {
try (RuleTester ruleTester = defaultRuleTester()) {
MockConnectorTableHandle connectorHandle = new MockConnectorTableHandle(TEST_SCHEMA_TABLE);
// make the mock connector return a new connectorHandle
MockConnectorFactory.ApplyTopN applyTopN = (session, handle, topNCount, sortItems, tableAssignments) -> Optional.of(new TopNApplicationResult<>(connectorHandle, true, false));
MockConnectorFactory mockFactory = createMockFactory(assignments, Optional.of(applyTopN));
ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, mockFactory, ImmutableMap.of());
ruleTester.assertThat(new PushTopNIntoTableScan(ruleTester.getMetadata())).on(p -> {
Symbol dimension = p.symbol(dimensionName, VARCHAR);
Symbol metric = p.symbol(metricName, BIGINT);
return p.topN(1, ImmutableList.of(dimension), TopNNode.Step.PARTIAL, p.tableScan(TEST_TABLE_HANDLE, ImmutableList.of(dimension, metric), ImmutableMap.of(dimension, dimensionColumn, metric, metricColumn)));
}).withSession(MOCK_SESSION).matches(tableScan(connectorHandle::equals, TupleDomain.all(), new HashMap<>()));
}
}
use of io.trino.spi.connector.TopNApplicationResult in project trino by trinodb.
the class TestPushTopNIntoTableScan method testPushSingleTopNIntoTableScanNotGuaranteed.
@Test
public void testPushSingleTopNIntoTableScanNotGuaranteed() {
try (RuleTester ruleTester = defaultRuleTester()) {
MockConnectorTableHandle connectorHandle = new MockConnectorTableHandle(TEST_SCHEMA_TABLE);
// make the mock connector return a new connectorHandle
MockConnectorFactory.ApplyTopN applyTopN = (session, handle, topNCount, sortItems, tableAssignments) -> Optional.of(new TopNApplicationResult<>(connectorHandle, false, false));
MockConnectorFactory mockFactory = createMockFactory(assignments, Optional.of(applyTopN));
ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, mockFactory, ImmutableMap.of());
ruleTester.assertThat(new PushTopNIntoTableScan(ruleTester.getMetadata())).on(p -> {
Symbol dimension = p.symbol(dimensionName, VARCHAR);
Symbol metric = p.symbol(metricName, BIGINT);
return p.topN(1, ImmutableList.of(dimension), p.tableScan(TEST_TABLE_HANDLE, ImmutableList.of(dimension, metric), ImmutableMap.of(dimension, dimensionColumn, metric, metricColumn)));
}).withSession(MOCK_SESSION).matches(topN(1, ImmutableList.of(sort(dimensionName, ASCENDING, FIRST)), TopNNode.Step.SINGLE, tableScan(connectorHandle::equals, TupleDomain.all(), ImmutableMap.of(dimensionName, dimensionColumn::equals, metricName, metricColumn::equals))));
}
}
use of io.trino.spi.connector.TopNApplicationResult in project trino by trinodb.
the class TestPushTopNIntoTableScan method testPushFinalTopNIntoTableScan.
/**
* Ensure FINAL TopN can be pushed into table scan.
* <p>
* In case of TopN over outer join, TopN may become eligible for push down
* only after PARTIAL TopN was pushed down and only then the join was
* pushed down as well -- the connector may decide to accept Join pushdown
* only after it learns there is TopN in play which limits results size.
* <p>
* Thus the optimization sequence can be:
* <ol>
* <li>Try to push Join into Table Scan -- connector rejects that (e.g. too big data set size)
* <li>Create FINAL/PARTIAL TopN
* <li>Push PARTIAL TopN through Outer Join
* <li>Push PARTIAL TopN into Table Scan -- connector accepts that.
* <li>Push Join into Table Scan -- connector now accepts join pushdown.
* <li>Push FINAL TopN into Table Scan
* </ol>
*/
@Test
public void testPushFinalTopNIntoTableScan() {
try (RuleTester ruleTester = defaultRuleTester()) {
MockConnectorTableHandle connectorHandle = new MockConnectorTableHandle(TEST_SCHEMA_TABLE);
// make the mock connector return a new connectorHandle
MockConnectorFactory.ApplyTopN applyTopN = (session, handle, topNCount, sortItems, tableAssignments) -> Optional.of(new TopNApplicationResult<>(connectorHandle, true, false));
MockConnectorFactory mockFactory = createMockFactory(assignments, Optional.of(applyTopN));
ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, mockFactory, ImmutableMap.of());
ruleTester.assertThat(new PushTopNIntoTableScan(ruleTester.getMetadata())).on(p -> {
Symbol dimension = p.symbol(dimensionName, VARCHAR);
Symbol metric = p.symbol(metricName, BIGINT);
return p.topN(1, ImmutableList.of(dimension), TopNNode.Step.FINAL, p.tableScan(TEST_TABLE_HANDLE, ImmutableList.of(dimension, metric), ImmutableMap.of(dimension, dimensionColumn, metric, metricColumn)));
}).withSession(MOCK_SESSION).matches(tableScan(connectorHandle::equals, TupleDomain.all(), new HashMap<>()));
}
}
use of io.trino.spi.connector.TopNApplicationResult in project trino by trinodb.
the class TestPushTopNIntoTableScan method testPushPartialTopNIntoTableScanNotGuaranteed.
@Test
public void testPushPartialTopNIntoTableScanNotGuaranteed() {
try (RuleTester ruleTester = defaultRuleTester()) {
MockConnectorTableHandle connectorHandle = new MockConnectorTableHandle(TEST_SCHEMA_TABLE);
// make the mock connector return a new connectorHandle
MockConnectorFactory.ApplyTopN applyTopN = (session, handle, topNCount, sortItems, tableAssignments) -> Optional.of(new TopNApplicationResult<>(connectorHandle, false, false));
MockConnectorFactory mockFactory = createMockFactory(assignments, Optional.of(applyTopN));
ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, mockFactory, ImmutableMap.of());
ruleTester.assertThat(new PushTopNIntoTableScan(ruleTester.getMetadata())).on(p -> {
Symbol dimension = p.symbol(dimensionName, VARCHAR);
Symbol metric = p.symbol(metricName, BIGINT);
return p.topN(1, ImmutableList.of(dimension), TopNNode.Step.PARTIAL, p.tableScan(TEST_TABLE_HANDLE, ImmutableList.of(dimension, metric), ImmutableMap.of(dimension, dimensionColumn, metric, metricColumn)));
}).withSession(MOCK_SESSION).matches(topN(1, ImmutableList.of(sort(dimensionName, ASCENDING, FIRST)), TopNNode.Step.PARTIAL, tableScan(connectorHandle::equals, TupleDomain.all(), ImmutableMap.of(dimensionName, dimensionColumn::equals, metricName, metricColumn::equals))));
}
}
use of io.trino.spi.connector.TopNApplicationResult in project trino by trinodb.
the class TestPushTopNIntoTableScan method testPushSingleTopNIntoTableScan.
@Test
public void testPushSingleTopNIntoTableScan() {
try (RuleTester ruleTester = defaultRuleTester()) {
MockConnectorTableHandle connectorHandle = new MockConnectorTableHandle(TEST_SCHEMA_TABLE);
// make the mock connector return a new connectorHandle
MockConnectorFactory.ApplyTopN applyTopN = (session, handle, topNCount, sortItems, tableAssignments) -> Optional.of(new TopNApplicationResult<>(connectorHandle, true, false));
MockConnectorFactory mockFactory = createMockFactory(assignments, Optional.of(applyTopN));
ruleTester.getQueryRunner().createCatalog(MOCK_CATALOG, mockFactory, ImmutableMap.of());
ruleTester.assertThat(new PushTopNIntoTableScan(ruleTester.getMetadata())).on(p -> {
Symbol dimension = p.symbol(dimensionName, VARCHAR);
Symbol metric = p.symbol(metricName, BIGINT);
return p.topN(1, ImmutableList.of(dimension), p.tableScan(TEST_TABLE_HANDLE, ImmutableList.of(dimension, metric), ImmutableMap.of(dimension, dimensionColumn, metric, metricColumn)));
}).withSession(MOCK_SESSION).matches(tableScan(connectorHandle::equals, TupleDomain.all(), new HashMap<>()));
}
}
Aggregations