Search in sources :

Example 1 with TransactionInfo

use of io.prestosql.transaction.TransactionInfo 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 2 with TransactionInfo

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

the class TestStartTransactionTask method testStartTransaction.

@Test
public void testStartTransaction() {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    getFutureValue(new StartTransactionTask().execute(new StartTransaction(ImmutableList.of()), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList(), new HeuristicIndexerManager(new FileSystemClientManager(), new HetuMetaStoreManager())));
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    TransactionInfo transactionInfo = transactionManager.getTransactionInfo(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().get());
    assertFalse(transactionInfo.isAutoCommitContext());
}
Also used : TransactionManager(io.prestosql.transaction.TransactionManager) InMemoryTransactionManager(io.prestosql.transaction.InMemoryTransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) AllowAllAccessControl(io.prestosql.security.AllowAllAccessControl) HeuristicIndexerManager(io.prestosql.heuristicindex.HeuristicIndexerManager) TransactionInfo(io.prestosql.transaction.TransactionInfo) HetuMetaStoreManager(io.prestosql.metastore.HetuMetaStoreManager) StartTransaction(io.prestosql.sql.tree.StartTransaction) Session(io.prestosql.Session) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) Test(org.testng.annotations.Test)

Example 3 with TransactionInfo

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

the class TestStartTransactionTask method testStartTransactionExplicitModes.

@Test
public void testStartTransactionExplicitModes() {
    Session session = sessionBuilder().setClientTransactionSupport().build();
    TransactionManager transactionManager = createTestTransactionManager();
    QueryStateMachine stateMachine = createQueryStateMachine("START TRANSACTION", session, transactionManager);
    assertFalse(stateMachine.getSession().getTransactionId().isPresent());
    getFutureValue(new StartTransactionTask().execute(new StartTransaction(ImmutableList.of(new Isolation(Isolation.Level.SERIALIZABLE), new TransactionAccessMode(true))), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList(), new HeuristicIndexerManager(new FileSystemClientManager(), new HetuMetaStoreManager())));
    assertFalse(stateMachine.getQueryInfo(Optional.empty()).isClearTransactionId());
    assertTrue(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().isPresent());
    assertEquals(transactionManager.getAllTransactionInfos().size(), 1);
    TransactionInfo transactionInfo = transactionManager.getTransactionInfo(stateMachine.getQueryInfo(Optional.empty()).getStartedTransactionId().get());
    assertEquals(transactionInfo.getIsolationLevel(), IsolationLevel.SERIALIZABLE);
    assertTrue(transactionInfo.isReadOnly());
    assertFalse(transactionInfo.isAutoCommitContext());
}
Also used : TransactionManager(io.prestosql.transaction.TransactionManager) InMemoryTransactionManager(io.prestosql.transaction.InMemoryTransactionManager) InMemoryTransactionManager.createTestTransactionManager(io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager) TransactionAccessMode(io.prestosql.sql.tree.TransactionAccessMode) AllowAllAccessControl(io.prestosql.security.AllowAllAccessControl) HeuristicIndexerManager(io.prestosql.heuristicindex.HeuristicIndexerManager) Isolation(io.prestosql.sql.tree.Isolation) TransactionInfo(io.prestosql.transaction.TransactionInfo) HetuMetaStoreManager(io.prestosql.metastore.HetuMetaStoreManager) StartTransaction(io.prestosql.sql.tree.StartTransaction) Session(io.prestosql.Session) FileSystemClientManager(io.prestosql.filesystem.FileSystemClientManager) Test(org.testng.annotations.Test)

Aggregations

TransactionInfo (io.prestosql.transaction.TransactionInfo)3 Session (io.prestosql.Session)2 FileSystemClientManager (io.prestosql.filesystem.FileSystemClientManager)2 HeuristicIndexerManager (io.prestosql.heuristicindex.HeuristicIndexerManager)2 HetuMetaStoreManager (io.prestosql.metastore.HetuMetaStoreManager)2 AllowAllAccessControl (io.prestosql.security.AllowAllAccessControl)2 StartTransaction (io.prestosql.sql.tree.StartTransaction)2 InMemoryTransactionManager (io.prestosql.transaction.InMemoryTransactionManager)2 InMemoryTransactionManager.createTestTransactionManager (io.prestosql.transaction.InMemoryTransactionManager.createTestTransactionManager)2 TransactionManager (io.prestosql.transaction.TransactionManager)2 Test (org.testng.annotations.Test)2 Catalog (io.prestosql.metadata.Catalog)1 CatalogManager (io.prestosql.metadata.CatalogManager)1 AccessControlManager (io.prestosql.security.AccessControlManager)1 ColumnMetadata (io.prestosql.spi.connector.ColumnMetadata)1 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)1 ConnectorViewDefinition (io.prestosql.spi.connector.ConnectorViewDefinition)1 ViewColumn (io.prestosql.spi.connector.ConnectorViewDefinition.ViewColumn)1 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)1 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)1