Search in sources :

Example 1 with IsolationLevel

use of io.trino.spi.transaction.IsolationLevel 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 2 with IsolationLevel

use of io.trino.spi.transaction.IsolationLevel in project trino by trinodb.

the class IndexedTpchConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> properties, ConnectorContext context) {
    int splitsPerNode = getSplitsPerNode(properties);
    TpchIndexedData indexedData = new TpchIndexedData(indexSpec);
    NodeManager nodeManager = context.getNodeManager();
    return new Connector() {

        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly, boolean autoCommit) {
            return TpchTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorSession session, ConnectorTransactionHandle transactionHandle) {
            return new TpchIndexMetadata(indexedData);
        }

        @Override
        public ConnectorSplitManager getSplitManager() {
            return new TpchSplitManager(nodeManager, splitsPerNode);
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider() {
            return new TpchRecordSetProvider(DecimalTypeMapping.DOUBLE);
        }

        @Override
        public ConnectorIndexProvider getIndexProvider() {
            return new TpchIndexProvider(indexedData);
        }

        @Override
        public Set<SystemTable> getSystemTables() {
            return ImmutableSet.of(new ExampleSystemTable());
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
            return new TpchNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
Also used : Connector(io.trino.spi.connector.Connector) IsolationLevel(io.trino.spi.transaction.IsolationLevel) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) TpchSplitManager(io.trino.plugin.tpch.TpchSplitManager) NodeManager(io.trino.spi.NodeManager) TpchNodePartitioningProvider(io.trino.plugin.tpch.TpchNodePartitioningProvider) ConnectorSession(io.trino.spi.connector.ConnectorSession) SystemTable(io.trino.spi.connector.SystemTable) TpchRecordSetProvider(io.trino.plugin.tpch.TpchRecordSetProvider)

Example 3 with IsolationLevel

use of io.trino.spi.transaction.IsolationLevel in project trino by trinodb.

the class TpchConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> properties, ConnectorContext context) {
    int splitsPerNode = getSplitsPerNode(properties);
    ColumnNaming columnNaming = ColumnNaming.valueOf(properties.getOrDefault(TPCH_COLUMN_NAMING_PROPERTY, ColumnNaming.SIMPLIFIED.name()).toUpperCase(ENGLISH));
    DecimalTypeMapping decimalTypeMapping = DecimalTypeMapping.valueOf(properties.getOrDefault(TPCH_DOUBLE_TYPE_MAPPING_PROPERTY, DecimalTypeMapping.DOUBLE.name()).toUpperCase(ENGLISH));
    NodeManager nodeManager = context.getNodeManager();
    return new Connector() {

        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly, boolean autoCommit) {
            return TpchTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorSession session, ConnectorTransactionHandle transaction) {
            return new TpchMetadata(columnNaming, decimalTypeMapping, predicatePushdownEnabled, partitioningEnabled, getTpchTableScanRedirectionCatalog(properties), getTpchTableScanRedirectionSchema(properties));
        }

        @Override
        public ConnectorSplitManager getSplitManager() {
            return new TpchSplitManager(nodeManager, splitsPerNode);
        }

        @Override
        public ConnectorPageSourceProvider getPageSourceProvider() {
            if (isProducePages(properties)) {
                return new TpchPageSourceProvider(getMaxRowsPerPage(properties), decimalTypeMapping);
            }
            throw new UnsupportedOperationException();
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider() {
            if (!isProducePages(properties)) {
                return new TpchRecordSetProvider(decimalTypeMapping);
            }
            throw new UnsupportedOperationException();
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
            return new TpchNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
Also used : Connector(io.trino.spi.connector.Connector) IsolationLevel(io.trino.spi.transaction.IsolationLevel) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) NodeManager(io.trino.spi.NodeManager) ConnectorSession(io.trino.spi.connector.ConnectorSession)

Example 4 with IsolationLevel

use of io.trino.spi.transaction.IsolationLevel in project trino by trinodb.

the class TpcdsConnectorFactory method create.

@Override
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context) {
    int splitsPerNode = getSplitsPerNode(config);
    NodeManager nodeManager = context.getNodeManager();
    return new Connector() {

        @Override
        public ConnectorTransactionHandle beginTransaction(IsolationLevel isolationLevel, boolean readOnly, boolean autoCommit) {
            return TpcdsTransactionHandle.INSTANCE;
        }

        @Override
        public ConnectorMetadata getMetadata(ConnectorSession session, ConnectorTransactionHandle transactionHandle) {
            return new TpcdsMetadata();
        }

        @Override
        public ConnectorSplitManager getSplitManager() {
            return new TpcdsSplitManager(nodeManager, splitsPerNode, isWithNoSexism(config));
        }

        @Override
        public ConnectorRecordSetProvider getRecordSetProvider() {
            return new TpcdsRecordSetProvider();
        }

        @Override
        public ConnectorNodePartitioningProvider getNodePartitioningProvider() {
            return new TpcdsNodePartitioningProvider(nodeManager, splitsPerNode);
        }
    };
}
Also used : NodeManager(io.trino.spi.NodeManager) Connector(io.trino.spi.connector.Connector) IsolationLevel(io.trino.spi.transaction.IsolationLevel) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) ConnectorSession(io.trino.spi.connector.ConnectorSession)

Aggregations

IsolationLevel (io.trino.spi.transaction.IsolationLevel)4 NodeManager (io.trino.spi.NodeManager)3 Connector (io.trino.spi.connector.Connector)3 ConnectorSession (io.trino.spi.connector.ConnectorSession)3 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)3 Session (io.trino.Session)1 TpchNodePartitioningProvider (io.trino.plugin.tpch.TpchNodePartitioningProvider)1 TpchRecordSetProvider (io.trino.plugin.tpch.TpchRecordSetProvider)1 TpchSplitManager (io.trino.plugin.tpch.TpchSplitManager)1 TrinoException (io.trino.spi.TrinoException)1 SystemTable (io.trino.spi.connector.SystemTable)1 TransactionId (io.trino.transaction.TransactionId)1