Search in sources :

Example 1 with PruneTableScanColumns

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);
}
Also used : MoreFiles.deleteRecursively(com.google.common.io.MoreFiles.deleteRecursively) Database(io.trino.plugin.hive.metastore.Database) Test(org.testng.annotations.Test) NoHdfsAuthentication(io.trino.plugin.hive.authentication.NoHdfsAuthentication) CatalogName(io.trino.connector.CatalogName) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) LongLiteral(io.trino.sql.tree.LongLiteral) Arrays.asList(java.util.Arrays.asList) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) HiveHdfsConfiguration(io.trino.plugin.hive.HiveHdfsConfiguration) HiveColumnHandle(io.trino.plugin.hive.HiveColumnHandle) INTEGER(io.trino.spi.type.IntegerType.INTEGER) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) RowType(io.trino.spi.type.RowType) ImmutableSet(com.google.common.collect.ImmutableSet) HdfsEnvironment(io.trino.plugin.hive.HdfsEnvironment) ImmutableMap(com.google.common.collect.ImmutableMap) Domain(io.trino.spi.predicate.Domain) Assignments(io.trino.sql.planner.plan.Assignments) FileHiveMetastore(io.trino.plugin.hive.metastore.file.FileHiveMetastore) ScalarStatsCalculator(io.trino.cost.ScalarStatsCalculator) TestingHiveConnectorFactory(io.trino.plugin.hive.TestingHiveConnectorFactory) String.format(java.lang.String.format) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) ADD(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.ADD) BIGINT(io.trino.spi.type.BigintType.BIGINT) SymbolReference(io.trino.sql.tree.SymbolReference) PushProjectionIntoTableScan(io.trino.sql.planner.iterative.rule.PushProjectionIntoTableScan) HdfsConfig(io.trino.plugin.hive.HdfsConfig) PruneTableScanColumns(io.trino.sql.planner.iterative.rule.PruneTableScanColumns) HdfsConfigurationInitializer(io.trino.plugin.hive.HdfsConfigurationInitializer) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) RowType.field(io.trino.spi.type.RowType.field) MINUS(io.trino.sql.tree.ArithmeticUnaryExpression.Sign.MINUS) Session(io.trino.Session) MetastoreConfig(io.trino.plugin.hive.metastore.MetastoreConfig) PushPredicateIntoTableScan(io.trino.sql.planner.iterative.rule.PushPredicateIntoTableScan) Type(io.trino.spi.type.Type) PlanMatchPattern.filter(io.trino.sql.planner.assertions.PlanMatchPattern.filter) SubscriptExpression(io.trino.sql.tree.SubscriptExpression) HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) ALLOW_INSECURE(com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) NodeVersion(io.trino.plugin.hive.NodeVersion) HiveTableHandle(io.trino.plugin.hive.HiveTableHandle) LocalQueryRunner(io.trino.testing.LocalQueryRunner) HiveColumnHandle.createBaseColumn(io.trino.plugin.hive.HiveColumnHandle.createBaseColumn) HiveType.toHiveType(io.trino.plugin.hive.HiveType.toHiveType) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) Symbol(io.trino.sql.planner.Symbol) AfterClass(org.testng.annotations.AfterClass) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest) PrincipalType(io.trino.spi.security.PrincipalType) IOException(java.io.IOException) HdfsConfiguration(io.trino.plugin.hive.HdfsConfiguration) TupleDomain(io.trino.spi.predicate.TupleDomain) HiveColumnProjectionInfo(io.trino.plugin.hive.HiveColumnProjectionInfo) File(java.io.File) HIVE_INT(io.trino.plugin.hive.HiveType.HIVE_INT) TableHandle(io.trino.metadata.TableHandle) PlanMatchPattern.project(io.trino.sql.planner.assertions.PlanMatchPattern.project) FileHiveMetastoreConfig(io.trino.plugin.hive.metastore.file.FileHiveMetastoreConfig) HiveTransactionHandle(io.trino.plugin.hive.HiveTransactionHandle) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) REGULAR(io.trino.plugin.hive.HiveColumnHandle.ColumnType.REGULAR) HiveTableHandle(io.trino.plugin.hive.HiveTableHandle) Symbol(io.trino.sql.planner.Symbol) PruneTableScanColumns(io.trino.sql.planner.iterative.rule.PruneTableScanColumns) HiveTableHandle(io.trino.plugin.hive.HiveTableHandle) TableHandle(io.trino.metadata.TableHandle) CatalogName(io.trino.connector.CatalogName) HiveTransactionHandle(io.trino.plugin.hive.HiveTransactionHandle) HiveColumnHandle(io.trino.plugin.hive.HiveColumnHandle) Test(org.testng.annotations.Test) BaseRuleTest(io.trino.sql.planner.iterative.rule.test.BaseRuleTest)

Example 2 with PruneTableScanColumns

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))));
}
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

Symbol (io.trino.sql.planner.Symbol)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Files (com.google.common.io.Files)1 MoreFiles.deleteRecursively (com.google.common.io.MoreFiles.deleteRecursively)1 ALLOW_INSECURE (com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE)1 Session (io.trino.Session)1 CatalogName (io.trino.connector.CatalogName)1 ScalarStatsCalculator (io.trino.cost.ScalarStatsCalculator)1 TableHandle (io.trino.metadata.TableHandle)1 HdfsConfig (io.trino.plugin.hive.HdfsConfig)1 HdfsConfiguration (io.trino.plugin.hive.HdfsConfiguration)1 HdfsConfigurationInitializer (io.trino.plugin.hive.HdfsConfigurationInitializer)1 HdfsEnvironment (io.trino.plugin.hive.HdfsEnvironment)1 HiveColumnHandle (io.trino.plugin.hive.HiveColumnHandle)1 REGULAR (io.trino.plugin.hive.HiveColumnHandle.ColumnType.REGULAR)1 HiveColumnHandle.createBaseColumn (io.trino.plugin.hive.HiveColumnHandle.createBaseColumn)1 HiveColumnProjectionInfo (io.trino.plugin.hive.HiveColumnProjectionInfo)1 HiveHdfsConfiguration (io.trino.plugin.hive.HiveHdfsConfiguration)1