Search in sources :

Example 6 with TransactionId

use of io.prestosql.transaction.TransactionId in project hetu-core by openlookeng.

the class RollbackTask method execute.

@Override
public ListenableFuture<?> execute(Rollback statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
    Session session = stateMachine.getSession();
    if (!session.getTransactionId().isPresent()) {
        throw new PrestoException(NOT_IN_TRANSACTION, "No transaction in progress");
    }
    TransactionId transactionId = session.getTransactionId().get();
    stateMachine.clearTransactionId();
    transactionManager.asyncAbort(transactionId);
    return immediateFuture(null);
}
Also used : PrestoException(io.prestosql.spi.PrestoException) Session(io.prestosql.Session) TransactionId(io.prestosql.transaction.TransactionId)

Example 7 with TransactionId

use of io.prestosql.transaction.TransactionId in project hetu-core by openlookeng.

the class QueryStateMachine method beginWithTicker.

static QueryStateMachine beginWithTicker(String query, Optional<String> preparedQuery, Session inputSession, URI self, ResourceGroupId resourceGroup, ResourceGroupManager resourceGroupManager, boolean transactionControl, TransactionManager transactionManager, AccessControl accessControl, Executor executor, Ticker ticker, Metadata metadata, WarningCollector warningCollector) {
    Session localSession = inputSession;
    // If there is not an existing transaction, begin an auto commit transaction
    if (!localSession.getTransactionId().isPresent() && !transactionControl) {
        // TODO: make autocommit isolation level a session parameter
        TransactionId transactionId = transactionManager.beginTransaction(true);
        localSession = localSession.beginTransactionId(transactionId, transactionManager, accessControl);
    }
    QueryStateMachine queryStateMachine = new QueryStateMachine(query, preparedQuery, localSession, self, resourceGroup, resourceGroupManager, transactionManager, executor, ticker, metadata, warningCollector);
    queryStateMachine.addStateChangeListener(newState -> QUERY_STATE_LOG.debug("Query %s is %s", queryStateMachine.getQueryId(), newState));
    return queryStateMachine;
}
Also used : Session(io.prestosql.Session) TransactionId(io.prestosql.transaction.TransactionId)

Example 8 with TransactionId

use of io.prestosql.transaction.TransactionId in project hetu-core by openlookeng.

the class TestAnalyzer method createTestingCatalog.

private Catalog createTestingCatalog(String catalogName, CatalogName catalog) {
    CatalogName systemId = createSystemTablesCatalogName(catalog);
    Connector connector = createTestingConnector();
    InternalNodeManager nodeManager = new InMemoryNodeManager();
    return new Catalog(catalogName, catalog, connector, createInformationSchemaCatalogName(catalog), new InformationSchemaConnector(catalogName, nodeManager, metadata, accessControl), systemId, new SystemConnector(nodeManager, connector.getSystemTables(), transactionId -> transactionManager.getConnectorTransaction(transactionId, catalog)));
}
Also used : SystemConnector(io.prestosql.connector.system.SystemConnector) TestingMetadata(io.prestosql.testing.TestingMetadata) Test(org.testng.annotations.Test) PropertyMetadata.integerProperty(io.prestosql.spi.session.PropertyMetadata.integerProperty) TypeSignature.parseTypeSignature(io.prestosql.spi.type.TypeSignature.parseTypeSignature) Statement(io.prestosql.sql.tree.Statement) WarningCollector(io.prestosql.execution.warnings.WarningCollector) SnapshotConfig(io.prestosql.snapshot.SnapshotConfig) INVALID_FETCH_FIRST_ROW_COUNT(io.prestosql.sql.analyzer.SemanticErrorCode.INVALID_FETCH_FIRST_ROW_COUNT) MUST_BE_AGGREGATE_OR_GROUP_BY(io.prestosql.sql.analyzer.SemanticErrorCode.MUST_BE_AGGREGATE_OR_GROUP_BY) MISMATCHED_COLUMN_ALIASES(io.prestosql.sql.analyzer.SemanticErrorCode.MISMATCHED_COLUMN_ALIASES) TransactionBuilder.transaction(io.prestosql.transaction.TransactionBuilder.transaction) TOO_MANY_ARGUMENTS(io.prestosql.sql.analyzer.SemanticErrorCode.TOO_MANY_ARGUMENTS) MULTIPLE_FIELDS_FROM_SUBQUERY(io.prestosql.sql.analyzer.SemanticErrorCode.MULTIPLE_FIELDS_FROM_SUBQUERY) AccessControl(io.prestosql.security.AccessControl) DUPLICATE_COLUMN_NAME(io.prestosql.sql.analyzer.SemanticErrorCode.DUPLICATE_COLUMN_NAME) MUST_BE_AGGREGATION_FUNCTION(io.prestosql.sql.analyzer.SemanticErrorCode.MUST_BE_AGGREGATION_FUNCTION) Metadata(io.prestosql.metadata.Metadata) TransactionInfo(io.prestosql.transaction.TransactionInfo) CANNOT_HAVE_AGGREGATIONS_WINDOWS_OR_GROUPING(io.prestosql.sql.analyzer.SemanticErrorCode.CANNOT_HAVE_AGGREGATIONS_WINDOWS_OR_GROUPING) WINDOW_REQUIRES_OVER(io.prestosql.sql.analyzer.SemanticErrorCode.WINDOW_REQUIRES_OVER) PropertyMetadata.stringProperty(io.prestosql.spi.session.PropertyMetadata.stringProperty) TaskManagerConfig(io.prestosql.execution.TaskManagerConfig) Joiner(com.google.common.base.Joiner) INVALID_WINDOW_FRAME(io.prestosql.sql.analyzer.SemanticErrorCode.INVALID_WINDOW_FRAME) COLUMN_NAME_NOT_SPECIFIED(io.prestosql.sql.analyzer.SemanticErrorCode.COLUMN_NAME_NOT_SPECIFIED) TransactionManager(io.prestosql.transaction.TransactionManager) CharType(io.prestosql.spi.type.CharType) AccessControlManager(io.prestosql.security.AccessControlManager) INVALID_PARAMETER_USAGE(io.prestosql.sql.analyzer.SemanticErrorCode.INVALID_PARAMETER_USAGE) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) MISSING_SCHEMA(io.prestosql.sql.analyzer.SemanticErrorCode.MISSING_SCHEMA) InformationSchemaConnector(io.prestosql.connector.informationschema.InformationSchemaConnector) WILDCARD_WITHOUT_FROM(io.prestosql.sql.analyzer.SemanticErrorCode.WILDCARD_WITHOUT_FROM) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) INVALID_PROCEDURE_ARGUMENTS(io.prestosql.sql.analyzer.SemanticErrorCode.INVALID_PROCEDURE_ARGUMENTS) InMemoryNodeManager(io.prestosql.metadata.InMemoryNodeManager) CatalogName.createSystemTablesCatalogName(io.prestosql.spi.connector.CatalogName.createSystemTablesCatalogName) Session(io.prestosql.Session) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) MISSING_ATTRIBUTE(io.prestosql.sql.analyzer.SemanticErrorCode.MISSING_ATTRIBUTE) SystemConnector(io.prestosql.connector.system.SystemConnector) MISSING_COLUMN(io.prestosql.sql.analyzer.SemanticErrorCode.MISSING_COLUMN) InternalNodeManager(io.prestosql.metadata.InternalNodeManager) DUPLICATE_RELATION(io.prestosql.sql.analyzer.SemanticErrorCode.DUPLICATE_RELATION) VIEW_IS_STALE(io.prestosql.sql.analyzer.SemanticErrorCode.VIEW_IS_STALE) Language(org.intellij.lang.annotations.Language) TYPE_MISMATCH(io.prestosql.sql.analyzer.SemanticErrorCode.TYPE_MISMATCH) NodeLocation(io.prestosql.sql.tree.NodeLocation) SAMPLE_PERCENTAGE_OUT_OF_RANGE(io.prestosql.sql.analyzer.SemanticErrorCode.SAMPLE_PERCENTAGE_OUT_OF_RANGE) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) CubeManager(io.prestosql.cube.CubeManager) TransactionId(io.prestosql.transaction.TransactionId) VARBINARY(io.prestosql.spi.type.VarbinaryType.VARBINARY) Catalog(io.prestosql.metadata.Catalog) CatalogManager(io.prestosql.metadata.CatalogManager) MISMATCHED_SET_COLUMN_TYPES(io.prestosql.sql.analyzer.SemanticErrorCode.MISMATCHED_SET_COLUMN_TYPES) COLUMN_TYPE_UNKNOWN(io.prestosql.sql.analyzer.SemanticErrorCode.COLUMN_TYPE_UNKNOWN) AllowAllAccessControl(io.prestosql.security.AllowAllAccessControl) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) SystemSessionProperties(io.prestosql.SystemSessionProperties) SqlParser(io.prestosql.sql.parser.SqlParser) QueryManagerConfig(io.prestosql.execution.QueryManagerConfig) NOT_SUPPORTED(io.prestosql.sql.analyzer.SemanticErrorCode.NOT_SUPPORTED) AMBIGUOUS_ATTRIBUTE(io.prestosql.sql.analyzer.SemanticErrorCode.AMBIGUOUS_ATTRIBUTE) HetuConfig(io.prestosql.utils.HetuConfig) REFERENCE_TO_OUTPUT_ATTRIBUTE_WITHIN_ORDER_BY_GROUPING(io.prestosql.sql.analyzer.SemanticErrorCode.REFERENCE_TO_OUTPUT_ATTRIBUTE_WITHIN_ORDER_BY_GROUPING) CATALOG_NOT_SPECIFIED(io.prestosql.sql.analyzer.SemanticErrorCode.CATALOG_NOT_SPECIFIED) REFERENCE_TO_OUTPUT_ATTRIBUTE_WITHIN_ORDER_BY_AGGREGATION(io.prestosql.sql.analyzer.SemanticErrorCode.REFERENCE_TO_OUTPUT_ATTRIBUTE_WITHIN_ORDER_BY_AGGREGATION) NON_NUMERIC_SAMPLE_PERCENTAGE(io.prestosql.sql.analyzer.SemanticErrorCode.NON_NUMERIC_SAMPLE_PERCENTAGE) PropertyMetadata(io.prestosql.spi.session.PropertyMetadata) VIEW_IS_RECURSIVE(io.prestosql.sql.analyzer.SemanticErrorCode.VIEW_IS_RECURSIVE) MUST_BE_COLUMN_REFERENCE(io.prestosql.sql.analyzer.SemanticErrorCode.MUST_BE_COLUMN_REFERENCE) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) DecimalType.createDecimalType(io.prestosql.spi.type.DecimalType.createDecimalType) NESTED_AGGREGATION(io.prestosql.sql.analyzer.SemanticErrorCode.NESTED_AGGREGATION) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) Collections.emptyList(java.util.Collections.emptyList) Collections.nCopies(java.util.Collections.nCopies) ArrayType(io.prestosql.spi.type.ArrayType) BeforeClass(org.testng.annotations.BeforeClass) CatalogName(io.prestosql.spi.connector.CatalogName) NESTED_WINDOW(io.prestosql.sql.analyzer.SemanticErrorCode.NESTED_WINDOW) TINYINT(io.prestosql.spi.type.TinyintType.TINYINT) String.format(java.lang.String.format) List(java.util.List) INVALID_LIMIT_ROW_COUNT(io.prestosql.sql.analyzer.SemanticErrorCode.INVALID_LIMIT_ROW_COUNT) NONDETERMINISTIC_ORDER_BY_EXPRESSION_WITH_SELECT_DISTINCT(io.prestosql.sql.analyzer.SemanticErrorCode.NONDETERMINISTIC_ORDER_BY_EXPRESSION_WITH_SELECT_DISTINCT) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) Optional(java.util.Optional) INVALID_OFFSET_ROW_COUNT(io.prestosql.sql.analyzer.SemanticErrorCode.INVALID_OFFSET_ROW_COUNT) MISSING_CATALOG(io.prestosql.sql.analyzer.SemanticErrorCode.MISSING_CATALOG) Connector(io.prestosql.spi.connector.Connector) MemoryManagerConfig(io.prestosql.memory.MemoryManagerConfig) TOO_MANY_GROUPING_SETS(io.prestosql.sql.analyzer.SemanticErrorCode.TOO_MANY_GROUPING_SETS) MISSING_ORDER_BY(io.prestosql.sql.analyzer.SemanticErrorCode.MISSING_ORDER_BY) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) ORDER_BY_MUST_BE_IN_SELECT(io.prestosql.sql.analyzer.SemanticErrorCode.ORDER_BY_MUST_BE_IN_SELECT) ORDER_BY_MUST_BE_IN_AGGREGATE(io.prestosql.sql.analyzer.SemanticErrorCode.ORDER_BY_MUST_BE_IN_AGGREGATE) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) TestingSession.testSessionBuilder(io.prestosql.testing.TestingSession.testSessionBuilder) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) ViewColumn(io.prestosql.spi.connector.ConnectorViewDefinition.ViewColumn) DATE(io.prestosql.spi.type.DateType.DATE) REAL(io.prestosql.spi.type.RealType.REAL) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) DUPLICATE_PROPERTY(io.prestosql.sql.analyzer.SemanticErrorCode.DUPLICATE_PROPERTY) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) CatalogName.createInformationSchemaCatalogName(io.prestosql.spi.connector.CatalogName.createInformationSchemaCatalogName) Assert.fail(org.testng.Assert.fail) APPLY_FUNCTION(io.prestosql.operator.scalar.ApplyFunction.APPLY_FUNCTION) INVALID_LITERAL(io.prestosql.sql.analyzer.SemanticErrorCode.INVALID_LITERAL) MISSING_TABLE(io.prestosql.sql.analyzer.SemanticErrorCode.MISSING_TABLE) VIEW_ANALYSIS_ERROR(io.prestosql.sql.analyzer.SemanticErrorCode.VIEW_ANALYSIS_ERROR) STANDALONE_LAMBDA(io.prestosql.sql.analyzer.SemanticErrorCode.STANDALONE_LAMBDA) Consumer(java.util.function.Consumer) SCHEMA_NOT_SPECIFIED(io.prestosql.sql.analyzer.SemanticErrorCode.SCHEMA_NOT_SPECIFIED) INVALID_ORDINAL(io.prestosql.sql.analyzer.SemanticErrorCode.INVALID_ORDINAL) SMALLINT(io.prestosql.spi.type.SmallintType.SMALLINT) IsolationLevel(io.prestosql.spi.transaction.IsolationLevel) InformationSchemaConnector(io.prestosql.connector.informationschema.InformationSchemaConnector) SystemConnector(io.prestosql.connector.system.SystemConnector) Connector(io.prestosql.spi.connector.Connector) InformationSchemaConnector(io.prestosql.connector.informationschema.InformationSchemaConnector) InternalNodeManager(io.prestosql.metadata.InternalNodeManager) CatalogName.createSystemTablesCatalogName(io.prestosql.spi.connector.CatalogName.createSystemTablesCatalogName) CatalogName(io.prestosql.spi.connector.CatalogName) CatalogName.createInformationSchemaCatalogName(io.prestosql.spi.connector.CatalogName.createInformationSchemaCatalogName) Catalog(io.prestosql.metadata.Catalog) InMemoryNodeManager(io.prestosql.metadata.InMemoryNodeManager)

Example 9 with TransactionId

use of io.prestosql.transaction.TransactionId in project hetu-core by openlookeng.

the class TestAnalyzer method setup.

@BeforeClass
public void setup() {
    CatalogManager catalogManager = new CatalogManager();
    transactionManager = createTestTransactionManager(catalogManager);
    transactionManager.beginTransaction(false);
    List<TransactionInfo> transactionInfos = transactionManager.getAllTransactionInfos();
    TransactionId transactionId = transactionInfos.get(0).getTransactionId();
    implicitConversionSession = testSessionBuilder().setCatalog(TPCH_CATALOG).setSchema("s1").setSystemProperty("implicit_conversion", "true").setTransactionId(transactionId).build();
    accessControl = new AccessControlManager(transactionManager);
    metadata = createTestMetadataManager(transactionManager, new FeaturesConfig());
    metadata.getFunctionAndTypeManager().registerBuiltInFunctions(ImmutableList.of(APPLY_FUNCTION));
    Catalog tpchTestCatalog = createTestingCatalog(TPCH_CATALOG, TPCH_CATALOG_NAME);
    catalogManager.registerCatalog(tpchTestCatalog);
    metadata.getAnalyzePropertyManager().addProperties(TPCH_CATALOG_NAME, tpchTestCatalog.getConnector(TPCH_CATALOG_NAME).getAnalyzeProperties());
    catalogManager.registerCatalog(createTestingCatalog(SECOND_CATALOG, SECOND_CATALOG_NAME));
    catalogManager.registerCatalog(createTestingCatalog(THIRD_CATALOG, THIRD_CATALOG_NAME));
    SchemaTableName table1 = new SchemaTableName("s1", "t1");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table1, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT), new ColumnMetadata("c", BIGINT), new ColumnMetadata("d", BIGINT))), false));
    SchemaTableName table2 = new SchemaTableName("s1", "t2");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table2, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT))), false));
    SchemaTableName table3 = new SchemaTableName("s1", "t3");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table3, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT), new ColumnMetadata("x", BIGINT, null, true))), false));
    // table in different catalog
    SchemaTableName table4 = new SchemaTableName("s2", "t4");
    inSetupTransaction(session -> metadata.createTable(session, SECOND_CATALOG, new ConnectorTableMetadata(table4, ImmutableList.of(new ColumnMetadata("a", BIGINT))), false));
    // table with a hidden column
    SchemaTableName table5 = new SchemaTableName("s1", "t5");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table5, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", BIGINT, null, true))), false));
    // table with a varchar column
    SchemaTableName table6 = new SchemaTableName("s1", "t6");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table6, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", VARCHAR), new ColumnMetadata("c", BIGINT), new ColumnMetadata("d", BIGINT))), false));
    // table with bigint, double, array of bigints and array of doubles column
    SchemaTableName table7 = new SchemaTableName("s1", "t7");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table7, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", DOUBLE), new ColumnMetadata("c", new ArrayType(BIGINT)), new ColumnMetadata("d", new ArrayType(DOUBLE)))), false));
    // table for implicit conversion
    SchemaTableName table8 = new SchemaTableName("s1", "t8");
    inSetupTransaction(session -> metadata.createTable(session, TPCH_CATALOG, new ConnectorTableMetadata(table8, ImmutableList.of(new ColumnMetadata("a", BIGINT), new ColumnMetadata("b", INTEGER), new ColumnMetadata("c", SMALLINT), new ColumnMetadata("d", TINYINT), new ColumnMetadata("e", createDecimalType(10, 3)), new ColumnMetadata("f", REAL), new ColumnMetadata("g", DOUBLE), new ColumnMetadata("h", VARCHAR), new ColumnMetadata("i", VARBINARY), new ColumnMetadata("j", DATE), new ColumnMetadata("K", CharType.createCharType(3)))), false));
    // valid view referencing table in same schema
    ConnectorViewDefinition viewData1 = new ConnectorViewDefinition("select a from t1", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewColumn("a", BIGINT.getTypeSignature())), Optional.of("user"), false);
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName(TPCH_CATALOG, "s1", "v1"), viewData1, false));
    // stale view (different column type)
    ConnectorViewDefinition viewData2 = new ConnectorViewDefinition("select a from t1", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewColumn("a", parseTypeSignature("varchar"))), Optional.of("user"), false);
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName(TPCH_CATALOG, "s1", "v2"), viewData2, false));
    // view referencing table in different schema from itself and session
    ConnectorViewDefinition viewData3 = new ConnectorViewDefinition("select a from t4", Optional.of(SECOND_CATALOG), Optional.of("s2"), ImmutableList.of(new ViewColumn("a", BIGINT.getTypeSignature())), Optional.of("owner"), false);
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName(THIRD_CATALOG, "s3", "v3"), viewData3, false));
    // valid view with uppercase column name
    ConnectorViewDefinition viewData4 = new ConnectorViewDefinition("select A from t1", Optional.of("tpch"), Optional.of("s1"), ImmutableList.of(new ViewColumn("a", BIGINT.getTypeSignature())), Optional.of("user"), false);
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName("tpch", "s1", "v4"), viewData4, false));
    // recursive view referencing to itself
    ConnectorViewDefinition viewData5 = new ConnectorViewDefinition("select * from v5", Optional.of(TPCH_CATALOG), Optional.of("s1"), ImmutableList.of(new ViewColumn("a", BIGINT.getTypeSignature())), Optional.of("user"), false);
    inSetupTransaction(session -> metadata.createView(session, new QualifiedObjectName(TPCH_CATALOG, "s1", "v5"), viewData5, false));
}
Also used : AccessControlManager(io.prestosql.security.AccessControlManager) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ViewColumn(io.prestosql.spi.connector.ConnectorViewDefinition.ViewColumn) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) CatalogManager(io.prestosql.metadata.CatalogManager) Catalog(io.prestosql.metadata.Catalog) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) TransactionId(io.prestosql.transaction.TransactionId) ConnectorViewDefinition(io.prestosql.spi.connector.ConnectorViewDefinition) ArrayType(io.prestosql.spi.type.ArrayType) TransactionInfo(io.prestosql.transaction.TransactionInfo) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) BeforeClass(org.testng.annotations.BeforeClass)

Example 10 with TransactionId

use of io.prestosql.transaction.TransactionId in project hetu-core by openlookeng.

the class TestInformationSchemaMetadata method testInformationSchemaPredicatePushdownWithConstraintPredicate.

@Test
public void testInformationSchemaPredicatePushdownWithConstraintPredicate() {
    TransactionId transactionId = transactionManager.beginTransaction(false);
    Constraint constraint = new Constraint(TupleDomain.all(), // test_schema has a table named "another_table" and we filter that out in this predicate
    bindings -> {
        NullableValue catalog = bindings.get(new InformationSchemaColumnHandle("table_catalog"));
        NullableValue schema = bindings.get(new InformationSchemaColumnHandle("table_schema"));
        NullableValue table = bindings.get(new InformationSchemaColumnHandle("table_name"));
        boolean isValid = true;
        if (catalog != null) {
            isValid = ((Slice) catalog.getValue()).toStringUtf8().equals("test_catalog");
        }
        if (schema != null) {
            isValid &= ((Slice) schema.getValue()).toStringUtf8().equals("test_schema");
        }
        if (table != null) {
            isValid &= ((Slice) table.getValue()).toStringUtf8().equals("test_view");
        }
        return isValid;
    });
    ConnectorSession session = createNewSession(transactionId);
    ConnectorMetadata connectorMetadata = new InformationSchemaMetadata("test_catalog", this.metadata);
    InformationSchemaTableHandle tableHandle = (InformationSchemaTableHandle) connectorMetadata.getTableHandle(session, new SchemaTableName("information_schema", "views"));
    tableHandle = connectorMetadata.applyFilter(session, tableHandle, constraint).map(ConstraintApplicationResult::getHandle).map(InformationSchemaTableHandle.class::cast).orElseThrow(AssertionError::new);
    assertEquals(tableHandle.getPrefixes(), ImmutableSet.of(new QualifiedTablePrefix("test_catalog", "test_schema", "test_view")));
}
Also used : InformationSchemaTableHandle(io.prestosql.connector.informationschema.InformationSchemaTableHandle) Constraint(io.prestosql.spi.connector.Constraint) Slice(io.airlift.slice.Slice) InformationSchemaColumnHandle(io.prestosql.connector.informationschema.InformationSchemaColumnHandle) NullableValue(io.prestosql.spi.predicate.NullableValue) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) InformationSchemaMetadata(io.prestosql.connector.informationschema.InformationSchemaMetadata) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) TransactionId(io.prestosql.transaction.TransactionId) Test(org.testng.annotations.Test)

Aggregations

TransactionId (io.prestosql.transaction.TransactionId)12 Session (io.prestosql.Session)5 PrestoException (io.prestosql.spi.PrestoException)3 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)3 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 InformationSchemaColumnHandle (io.prestosql.connector.informationschema.InformationSchemaColumnHandle)2 InformationSchemaMetadata (io.prestosql.connector.informationschema.InformationSchemaMetadata)2 InformationSchemaTableHandle (io.prestosql.connector.informationschema.InformationSchemaTableHandle)2 Catalog (io.prestosql.metadata.Catalog)2 CatalogManager (io.prestosql.metadata.CatalogManager)2 SessionPropertyManager (io.prestosql.metadata.SessionPropertyManager)2 AccessControlManager (io.prestosql.security.AccessControlManager)2 CatalogName (io.prestosql.spi.connector.CatalogName)2 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)2 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)2 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)2 Constraint (io.prestosql.spi.connector.Constraint)2 PropertyMetadata (io.prestosql.spi.session.PropertyMetadata)2 IsolationLevel (io.prestosql.spi.transaction.IsolationLevel)2