Search in sources :

Example 36 with VARCHAR

use of io.trino.spi.type.VarcharType.VARCHAR 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<>()));
    }
}
Also used : ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TopNApplicationResult(io.trino.spi.connector.TopNApplicationResult) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) CatalogName(io.trino.connector.CatalogName) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) MockConnectorFactory(io.trino.connector.MockConnectorFactory) PlanMatchPattern.sort(io.trino.sql.planner.assertions.PlanMatchPattern.sort) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) ColumnHandle(io.trino.spi.connector.ColumnHandle) ASCENDING(io.trino.sql.tree.SortItem.Ordering.ASCENDING) Symbol(io.trino.sql.planner.Symbol) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) RuleTester.defaultRuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TopNNode(io.trino.sql.planner.plan.TopNNode) RuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester) PlanMatchPattern.topN(io.trino.sql.planner.assertions.PlanMatchPattern.topN) TupleDomain(io.trino.spi.predicate.TupleDomain) SchemaTableName(io.trino.spi.connector.SchemaTableName) FIRST(io.trino.sql.tree.SortItem.NullOrdering.FIRST) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) TableHandle(io.trino.metadata.TableHandle) BIGINT(io.trino.spi.type.BigintType.BIGINT) Optional(java.util.Optional) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) Session(io.trino.Session) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) MockConnectorFactory(io.trino.connector.MockConnectorFactory) HashMap(java.util.HashMap) RuleTester.defaultRuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester) RuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester) MockConnectorTableHandle(io.trino.connector.MockConnectorTableHandle) Symbol(io.trino.sql.planner.Symbol) Test(org.testng.annotations.Test)

Example 37 with VARCHAR

use of io.trino.spi.type.VarcharType.VARCHAR in project trino by trinodb.

the class TestThriftProjectionPushdown method testDoesNotFire.

@Test
public void testDoesNotFire() {
    PushProjectionIntoTableScan pushProjectionIntoTableScan = new PushProjectionIntoTableScan(tester().getPlannerContext(), tester().getTypeAnalyzer(), new ScalarStatsCalculator(tester().getPlannerContext(), tester().getTypeAnalyzer()));
    String columnName = "orderstatus";
    ColumnHandle columnHandle = new ThriftColumnHandle(columnName, VARCHAR, "", false);
    ConnectorTableHandle tableWithColumns = new ThriftTableHandle(TINY_SCHEMA, "nation", TupleDomain.all(), Optional.of(ImmutableSet.of(columnHandle)));
    tester().assertThat(pushProjectionIntoTableScan).on(p -> {
        Symbol orderStatusSymbol = p.symbol(columnName, VARCHAR);
        return p.project(Assignments.of(p.symbol("expr_2", VARCHAR), orderStatusSymbol.toSymbolReference()), p.tableScan(new TableHandle(new CatalogName(CATALOG), tableWithColumns, ThriftTransactionHandle.INSTANCE), ImmutableList.of(orderStatusSymbol), ImmutableMap.of(orderStatusSymbol, columnHandle)));
    }).doesNotFire();
}
Also used : ThriftTransactionHandle(io.trino.plugin.thrift.ThriftTransactionHandle) Test(org.testng.annotations.Test) ThriftTableHandle(io.trino.plugin.thrift.ThriftTableHandle) CatalogName(io.trino.connector.CatalogName) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) Closer(com.google.common.io.Closer) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) LocalQueryRunner(io.trino.testing.LocalQueryRunner) Map(java.util.Map) ColumnHandle(io.trino.spi.connector.ColumnHandle) ThriftQueryRunner.startThriftServers(io.trino.plugin.thrift.integration.ThriftQueryRunner.startThriftServers) ThriftColumnHandle(io.trino.plugin.thrift.ThriftColumnHandle) Symbol(io.trino.sql.planner.Symbol) AfterClass(org.testng.annotations.AfterClass) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) Assignments(io.trino.sql.planner.plan.Assignments) DriftServer(io.airlift.drift.server.DriftServer) IOException(java.io.IOException) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) TupleDomain(io.trino.spi.predicate.TupleDomain) ScalarStatsCalculator(io.trino.cost.ScalarStatsCalculator) SchemaTableName(io.trino.spi.connector.SchemaTableName) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) TableHandle(io.trino.metadata.TableHandle) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) SymbolReference(io.trino.sql.tree.SymbolReference) PushProjectionIntoTableScan(io.trino.sql.planner.iterative.rule.PushProjectionIntoTableScan) PruneTableScanColumns(io.trino.sql.planner.iterative.rule.PruneTableScanColumns) Optional(java.util.Optional) ThriftQueryRunner.driftServerPort(io.trino.plugin.thrift.integration.ThriftQueryRunner.driftServerPort) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) Session(io.trino.Session) ThriftPlugin(io.trino.plugin.thrift.ThriftPlugin) ColumnHandle(io.trino.spi.connector.ColumnHandle) ThriftColumnHandle(io.trino.plugin.thrift.ThriftColumnHandle) ThriftTableHandle(io.trino.plugin.thrift.ThriftTableHandle) PushProjectionIntoTableScan(io.trino.sql.planner.iterative.rule.PushProjectionIntoTableScan) Symbol(io.trino.sql.planner.Symbol) ScalarStatsCalculator(io.trino.cost.ScalarStatsCalculator) ThriftColumnHandle(io.trino.plugin.thrift.ThriftColumnHandle) ThriftTableHandle(io.trino.plugin.thrift.ThriftTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) TableHandle(io.trino.metadata.TableHandle) CatalogName(io.trino.connector.CatalogName) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)37 VARCHAR (io.trino.spi.type.VarcharType.VARCHAR)37 Test (org.testng.annotations.Test)34 Optional (java.util.Optional)31 BIGINT (io.trino.spi.type.BigintType.BIGINT)30 ImmutableMap (com.google.common.collect.ImmutableMap)26 List (java.util.List)25 ColumnHandle (io.trino.spi.connector.ColumnHandle)20 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)20 Map (java.util.Map)19 TupleDomain (io.trino.spi.predicate.TupleDomain)18 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)17 Session (io.trino.Session)17 SchemaTableName (io.trino.spi.connector.SchemaTableName)16 ImmutableSet (com.google.common.collect.ImmutableSet)15 TableHandle (io.trino.metadata.TableHandle)15 Type (io.trino.spi.type.Type)15 TestingSession.testSessionBuilder (io.trino.testing.TestingSession.testSessionBuilder)15 Assert.assertTrue (org.testng.Assert.assertTrue)15 CatalogName (io.trino.connector.CatalogName)14