Search in sources :

Example 11 with TransactionId

use of io.trino.transaction.TransactionId in project trino by trinodb.

the class TestKuduIntegrationDynamicFilter method testIncompleteDynamicFilterTimeout.

@Test(timeOut = 30_000)
public void testIncompleteDynamicFilterTimeout() throws Exception {
    QueryRunner runner = getQueryRunner();
    TransactionManager transactionManager = runner.getTransactionManager();
    TransactionId transactionId = transactionManager.beginTransaction(false);
    Session session = Session.builder(getSession()).setCatalogSessionProperty("kudu", "dynamic_filtering_wait_timeout", "1s").build().beginTransactionId(transactionId, transactionManager, new AllowAllAccessControl());
    QualifiedObjectName tableName = new QualifiedObjectName("kudu", "tpch", "orders");
    Optional<TableHandle> tableHandle = runner.getMetadata().getTableHandle(session, tableName);
    assertTrue(tableHandle.isPresent());
    SplitSource splitSource = runner.getSplitManager().getSplits(session, tableHandle.get(), UNGROUPED_SCHEDULING, new IncompleteDynamicFilter(), alwaysTrue());
    List<Split> splits = new ArrayList<>();
    while (!splitSource.isFinished()) {
        splits.addAll(splitSource.getNextBatch(NOT_PARTITIONED, Lifespan.taskWide(), 1000).get().getSplits());
    }
    splitSource.close();
    assertFalse(splits.isEmpty());
}
Also used : ArrayList(java.util.ArrayList) DistributedQueryRunner(io.trino.testing.DistributedQueryRunner) QueryRunner(io.trino.testing.QueryRunner) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) TransactionId(io.trino.transaction.TransactionId) TransactionManager(io.trino.transaction.TransactionManager) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) TableHandle(io.trino.metadata.TableHandle) SplitSource(io.trino.split.SplitSource) Split(io.trino.metadata.Split) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 12 with TransactionId

use of io.trino.transaction.TransactionId in project trino by trinodb.

the class TestIcebergMetadataListing method getStorageTable.

private SchemaTableName getStorageTable(String catalogName, String schemaName, String objectName) {
    TransactionManager transactionManager = getQueryRunner().getTransactionManager();
    TransactionId transactionId = transactionManager.beginTransaction(false);
    Session session = getSession().beginTransactionId(transactionId, transactionManager, getQueryRunner().getAccessControl());
    Optional<MaterializedViewDefinition> materializedView = getQueryRunner().getMetadata().getMaterializedView(session, new QualifiedObjectName(catalogName, schemaName, objectName));
    assertThat(materializedView).isPresent();
    return materializedView.get().getStorageTable().get().getSchemaTableName();
}
Also used : MaterializedViewDefinition(io.trino.metadata.MaterializedViewDefinition) TransactionManager(io.trino.transaction.TransactionManager) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) TransactionId(io.trino.transaction.TransactionId) Session(io.trino.Session)

Example 13 with TransactionId

use of io.trino.transaction.TransactionId in project trino by trinodb.

the class TestIcebergMaterializedViews method getStorageTable.

private SchemaTableName getStorageTable(String catalogName, String schemaName, String objectName) {
    TransactionManager transactionManager = getQueryRunner().getTransactionManager();
    TransactionId transactionId = transactionManager.beginTransaction(false);
    Session session = getSession().beginTransactionId(transactionId, transactionManager, getQueryRunner().getAccessControl());
    Optional<MaterializedViewDefinition> materializedView = getQueryRunner().getMetadata().getMaterializedView(session, new QualifiedObjectName(catalogName, schemaName, objectName));
    assertThat(materializedView).isPresent();
    return materializedView.get().getStorageTable().get().getSchemaTableName();
}
Also used : MaterializedViewDefinition(io.trino.metadata.MaterializedViewDefinition) TransactionManager(io.trino.transaction.TransactionManager) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) TransactionId(io.trino.transaction.TransactionId) Session(io.trino.Session)

Example 14 with TransactionId

use of io.trino.transaction.TransactionId in project trino by trinodb.

the class StartTransactionTask method execute.

@Override
public ListenableFuture<Void> execute(StartTransaction statement, QueryStateMachine stateMachine, List<Expression> parameters, WarningCollector warningCollector) {
    Session session = stateMachine.getSession();
    if (!session.isClientTransactionSupport()) {
        throw new TrinoException(StandardErrorCode.INCOMPATIBLE_CLIENT, "Client does not support transactions");
    }
    if (session.getTransactionId().isPresent()) {
        throw new TrinoException(StandardErrorCode.NOT_SUPPORTED, "Nested transactions not supported");
    }
    Optional<IsolationLevel> isolationLevel = extractIsolationLevel(statement);
    Optional<Boolean> readOnly = extractReadOnly(statement);
    TransactionId transactionId = transactionManager.beginTransaction(isolationLevel.orElse(TransactionManager.DEFAULT_ISOLATION), readOnly.orElse(TransactionManager.DEFAULT_READ_ONLY), false);
    stateMachine.setStartedTransactionId(transactionId);
    // Since the current session does not contain this new transaction ID, we need to manually mark it as inactive
    // when this statement completes.
    transactionManager.trySetInactive(transactionId);
    return immediateVoidFuture();
}
Also used : IsolationLevel(io.trino.spi.transaction.IsolationLevel) TrinoException(io.trino.spi.TrinoException) Session(io.trino.Session) TransactionId(io.trino.transaction.TransactionId)

Example 15 with TransactionId

use of io.trino.transaction.TransactionId in project trino by trinodb.

the class AbstractPropertiesSystemTable method cursor.

@Override
public final RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession session, TupleDomain<Integer> constraint) {
    TransactionId transactionId = ((GlobalSystemTransactionHandle) transactionHandle).getTransactionId();
    InMemoryRecordSet.Builder table = InMemoryRecordSet.builder(tableMetadata);
    List<CatalogName> catalogNames = transactionManager.getCatalogs(transactionId).keySet().stream().sorted().map(CatalogName::new).collect(toImmutableList());
    for (CatalogName catalogName : catalogNames) {
        catalogProperties.apply(catalogName).stream().sorted(Comparator.comparing(PropertyMetadata::getName)).forEach(propertyMetadata -> table.addRow(catalogName.toString(), propertyMetadata.getName(), firstNonNull(propertyMetadata.getDefaultValue(), "").toString(), propertyMetadata.getSqlType().toString(), propertyMetadata.getDescription()));
    }
    return table.build().cursor();
}
Also used : PropertyMetadata(io.trino.spi.session.PropertyMetadata) CatalogName(io.trino.connector.CatalogName) InMemoryRecordSet(io.trino.spi.connector.InMemoryRecordSet) TransactionId(io.trino.transaction.TransactionId)

Aggregations

TransactionId (io.trino.transaction.TransactionId)22 Test (org.testng.annotations.Test)12 SchemaTableName (io.trino.spi.connector.SchemaTableName)11 ImmutableMap (com.google.common.collect.ImmutableMap)8 ConnectorSession (io.trino.spi.connector.ConnectorSession)8 Session (io.trino.Session)7 InformationSchemaMetadata (io.trino.connector.informationschema.InformationSchemaMetadata)7 InformationSchemaTableHandle (io.trino.connector.informationschema.InformationSchemaTableHandle)7 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)7 Constraint (io.trino.spi.connector.Constraint)7 QualifiedObjectName (io.trino.metadata.QualifiedObjectName)6 TrinoException (io.trino.spi.TrinoException)6 CatalogName (io.trino.connector.CatalogName)5 ImmutableList (com.google.common.collect.ImmutableList)4 MockConnectorFactory (io.trino.connector.MockConnectorFactory)4 TransactionManager (io.trino.transaction.TransactionManager)4 Map (java.util.Map)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 TEST_SESSION (io.trino.SessionTestUtils.TEST_SESSION)3 InformationSchemaColumnHandle (io.trino.connector.informationschema.InformationSchemaColumnHandle)3