Search in sources :

Example 1 with HiveTransactionHandle

use of io.trino.plugin.hive.HiveTransactionHandle in project trino by trinodb.

the class TestDeltaLakeSplitManager method getSplits.

private List<DeltaLakeSplit> getSplits(DeltaLakeSplitManager splitManager, DeltaLakeConfig deltaLakeConfig) throws ExecutionException, InterruptedException {
    ConnectorSplitSource splitSource = splitManager.getSplits(// ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableHandle handle, SplitSchedulingStrategy splitSchedulingStrategy
    new HiveTransactionHandle(false), testingConnectorSessionWithConfig(deltaLakeConfig), tableHandle, ConnectorSplitManager.SplitSchedulingStrategy.UNGROUPED_SCHEDULING, DynamicFilter.EMPTY, Constraint.alwaysTrue());
    ImmutableList.Builder<DeltaLakeSplit> splits = ImmutableList.builder();
    while (!splitSource.isFinished()) {
        List<ConnectorSplit> nextBatch = splitSource.getNextBatch(NOT_PARTITIONED, 10).get().getSplits();
        splits.addAll(nextBatch.stream().map(split -> (DeltaLakeSplit) split).collect(Collectors.toList()));
    }
    return splits.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ConnectorSplitSource(io.trino.spi.connector.ConnectorSplitSource) HiveTransactionHandle(io.trino.plugin.hive.HiveTransactionHandle) ConnectorSplit(io.trino.spi.connector.ConnectorSplit)

Example 2 with HiveTransactionHandle

use of io.trino.plugin.hive.HiveTransactionHandle in project trino by trinodb.

the class TestConnectorPushdownRulesWithHive method testPredicatePushdown.

@Test
public void testPredicatePushdown() {
    String tableName = "predicate_test";
    tester().getQueryRunner().execute(format("CREATE TABLE %s (a, b) AS SELECT 5, 6", tableName));
    PushPredicateIntoTableScan pushPredicateIntoTableScan = new PushPredicateIntoTableScan(tester().getPlannerContext(), tester().getTypeAnalyzer());
    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 column = createBaseColumn("a", 0, HIVE_INT, INTEGER, REGULAR, Optional.empty());
    tester().assertThat(pushPredicateIntoTableScan).on(p -> p.filter(PlanBuilder.expression("a = 5"), p.tableScan(table, ImmutableList.of(p.symbol("a", INTEGER)), ImmutableMap.of(p.symbol("a", INTEGER), column)))).matches(filter("a = 5", tableScan(tableHandle -> ((HiveTableHandle) tableHandle).getCompactEffectivePredicate().getDomains().get().equals(ImmutableMap.of(column, Domain.singleValue(INTEGER, 5L))), TupleDomain.all(), ImmutableMap.of("a", column::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) PushPredicateIntoTableScan(io.trino.sql.planner.iterative.rule.PushPredicateIntoTableScan) 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 3 with HiveTransactionHandle

use of io.trino.plugin.hive.HiveTransactionHandle 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 4 with HiveTransactionHandle

use of io.trino.plugin.hive.HiveTransactionHandle in project trino by trinodb.

the class DeltaLakeConnector method beginTransaction.

@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly, boolean autoCommit) {
    checkConnectorSupports(READ_COMMITTED, isolationLevel);
    verify(autoCommit, "Catalog only supports writes using autocommit: DeltaLake");
    ConnectorTransactionHandle transaction = new HiveTransactionHandle(true);
    transactionManager.begin(transaction);
    return transaction;
}
Also used : ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) HiveTransactionHandle(io.trino.plugin.hive.HiveTransactionHandle)

Example 5 with HiveTransactionHandle

use of io.trino.plugin.hive.HiveTransactionHandle in project trino by trinodb.

the class IcebergConnector method beginTransaction.

@Override
public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly, boolean autoCommit) {
    checkConnectorSupports(SERIALIZABLE, isolationLevel);
    ConnectorTransactionHandle transaction = new HiveTransactionHandle(autoCommit);
    transactionManager.begin(transaction);
    return transaction;
}
Also used : ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) HiveTransactionHandle(io.trino.plugin.hive.HiveTransactionHandle)

Aggregations

HiveTransactionHandle (io.trino.plugin.hive.HiveTransactionHandle)8 ImmutableList (com.google.common.collect.ImmutableList)5 NodeVersion (io.trino.plugin.hive.NodeVersion)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 Files (com.google.common.io.Files)4 MoreFiles.deleteRecursively (com.google.common.io.MoreFiles.deleteRecursively)4 ALLOW_INSECURE (com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE)4 Session (io.trino.Session)4 CatalogName (io.trino.connector.CatalogName)4 ScalarStatsCalculator (io.trino.cost.ScalarStatsCalculator)4 TableHandle (io.trino.metadata.TableHandle)4 HdfsConfig (io.trino.plugin.hive.HdfsConfig)4 HdfsConfiguration (io.trino.plugin.hive.HdfsConfiguration)4 HdfsConfigurationInitializer (io.trino.plugin.hive.HdfsConfigurationInitializer)4 HdfsEnvironment (io.trino.plugin.hive.HdfsEnvironment)4 HiveColumnHandle (io.trino.plugin.hive.HiveColumnHandle)4 REGULAR (io.trino.plugin.hive.HiveColumnHandle.ColumnType.REGULAR)4 HiveColumnHandle.createBaseColumn (io.trino.plugin.hive.HiveColumnHandle.createBaseColumn)4 HiveColumnProjectionInfo (io.trino.plugin.hive.HiveColumnProjectionInfo)4