Search in sources :

Example 1 with ThriftTableHandle

use of io.trino.plugin.thrift.ThriftTableHandle in project trino by trinodb.

the class TestThriftProjectionPushdown method testProjectionPushdown.

@Test
public void testProjectionPushdown() {
    PushProjectionIntoTableScan pushProjectionIntoTableScan = new PushProjectionIntoTableScan(tester().getPlannerContext(), tester().getTypeAnalyzer(), new ScalarStatsCalculator(tester().getPlannerContext(), tester().getTypeAnalyzer()));
    TableHandle inputTableHandle = NATION_TABLE;
    String columnName = "orderstatus";
    ColumnHandle columnHandle = new ThriftColumnHandle(columnName, VARCHAR, "", false);
    ConnectorTableHandle projectedThriftHandle = 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(inputTableHandle, ImmutableList.of(orderStatusSymbol), ImmutableMap.of(orderStatusSymbol, columnHandle)));
    }).withSession(SESSION).matches(project(ImmutableMap.of("expr_2", expression(new SymbolReference(columnName))), tableScan(projectedThriftHandle::equals, TupleDomain.all(), ImmutableMap.of(columnName, columnHandle::equals))));
}
Also used : 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) SymbolReference(io.trino.sql.tree.SymbolReference) 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) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 2 with ThriftTableHandle

use of io.trino.plugin.thrift.ThriftTableHandle 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)

Example 3 with ThriftTableHandle

use of io.trino.plugin.thrift.ThriftTableHandle in project trino by trinodb.

the class TestThriftProjectionPushdown method testPruneColumns.

@Test
public void testPruneColumns() {
    PruneTableScanColumns rule = new PruneTableScanColumns(tester().getMetadata());
    ThriftColumnHandle nationKeyColumn = new ThriftColumnHandle("nationKey", VARCHAR, "", false);
    ThriftColumnHandle nameColumn = new ThriftColumnHandle("name", VARCHAR, "", false);
    tester().assertThat(rule).on(p -> {
        Symbol nationKey = p.symbol(nationKeyColumn.getColumnName(), VARCHAR);
        Symbol name = p.symbol(nameColumn.getColumnName(), VARCHAR);
        return p.project(Assignments.of(p.symbol("expr", VARCHAR), nationKey.toSymbolReference()), p.tableScan(NATION_TABLE, ImmutableList.of(nationKey, name), ImmutableMap.<Symbol, ColumnHandle>builder().put(nationKey, nationKeyColumn).put(name, nameColumn).buildOrThrow()));
    }).withSession(SESSION).matches(project(ImmutableMap.of("expr", expression(new SymbolReference(nationKeyColumn.getColumnName()))), tableScan(new ThriftTableHandle(TINY_SCHEMA, "nation", TupleDomain.all(), Optional.of(ImmutableSet.of(nationKeyColumn)))::equals, TupleDomain.all(), ImmutableMap.of(nationKeyColumn.getColumnName(), nationKeyColumn::equals))));
}
Also used : ThriftTableHandle(io.trino.plugin.thrift.ThriftTableHandle) Symbol(io.trino.sql.planner.Symbol) SymbolReference(io.trino.sql.tree.SymbolReference) ThriftColumnHandle(io.trino.plugin.thrift.ThriftColumnHandle) PruneTableScanColumns(io.trino.sql.planner.iterative.rule.PruneTableScanColumns) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Aggregations

ThriftColumnHandle (io.trino.plugin.thrift.ThriftColumnHandle)3 ThriftTableHandle (io.trino.plugin.thrift.ThriftTableHandle)3 Symbol (io.trino.sql.planner.Symbol)3 BaseRuleTest (io.trino.sql.planner.iterative.rule.test.BaseRuleTest)3 SymbolReference (io.trino.sql.tree.SymbolReference)3 Test (org.testng.annotations.Test)3 ScalarStatsCalculator (io.trino.cost.ScalarStatsCalculator)2 TableHandle (io.trino.metadata.TableHandle)2 ColumnHandle (io.trino.spi.connector.ColumnHandle)2 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)2 PruneTableScanColumns (io.trino.sql.planner.iterative.rule.PruneTableScanColumns)2 PushProjectionIntoTableScan (io.trino.sql.planner.iterative.rule.PushProjectionIntoTableScan)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 Closer (com.google.common.io.Closer)1 DriftServer (io.airlift.drift.server.DriftServer)1 Session (io.trino.Session)1 CatalogName (io.trino.connector.CatalogName)1