use of io.trino.sql.planner.iterative.rule.PruneTableScanColumns in project trino by trinodb.
the class TestConnectorPushdownRulesWithHive method testColumnPruningProjectionPushdown.
@Test
public void testColumnPruningProjectionPushdown() {
String tableName = "column_pruning_projection_test";
tester().getQueryRunner().execute(format("CREATE TABLE %s (a, b) AS SELECT 5, 6", tableName));
PruneTableScanColumns pruneTableScanColumns = new PruneTableScanColumns(tester().getMetadata());
HiveTableHandle hiveTable = new HiveTableHandle(SCHEMA_NAME, tableName, ImmutableMap.of(), ImmutableList.of(), ImmutableList.of(), Optional.empty());
TableHandle table = new TableHandle(new CatalogName(HIVE_CATALOG_NAME), hiveTable, new HiveTransactionHandle(false));
HiveColumnHandle columnA = createBaseColumn("a", 0, HIVE_INT, INTEGER, REGULAR, Optional.empty());
HiveColumnHandle columnB = createBaseColumn("b", 1, HIVE_INT, INTEGER, REGULAR, Optional.empty());
tester().assertThat(pruneTableScanColumns).on(p -> {
Symbol symbolA = p.symbol("a", INTEGER);
Symbol symbolB = p.symbol("b", INTEGER);
return p.project(Assignments.of(p.symbol("x"), symbolA.toSymbolReference()), p.tableScan(table, ImmutableList.of(symbolA, symbolB), ImmutableMap.of(symbolA, columnA, symbolB, columnB)));
}).matches(strictProject(ImmutableMap.of("expr", expression("COLA")), tableScan(hiveTable.withProjectedColumns(ImmutableSet.of(columnA))::equals, TupleDomain.all(), ImmutableMap.of("COLA", columnA::equals))));
metastore.dropTable(SCHEMA_NAME, tableName, true);
}
use of io.trino.sql.planner.iterative.rule.PruneTableScanColumns 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))));
}
Aggregations