Search in sources :

Example 6 with TransactionId

use of com.facebook.presto.transaction.TransactionId in project presto by prestodb.

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);
    Map<ConnectorId, Map<String, PropertyMetadata<?>>> connectorProperties = propertySupplier.get();
    for (Entry<String, ConnectorId> entry : new TreeMap<>(transactionManager.getCatalogNames(transactionId)).entrySet()) {
        String catalog = entry.getKey();
        Map<String, PropertyMetadata<?>> properties = new TreeMap<>(connectorProperties.getOrDefault(entry.getValue(), ImmutableMap.of()));
        for (PropertyMetadata<?> propertyMetadata : properties.values()) {
            table.addRow(catalog, propertyMetadata.getName(), firstNonNull(propertyMetadata.getDefaultValue(), "").toString(), propertyMetadata.getSqlType().toString(), propertyMetadata.getDescription());
        }
    }
    return table.build().cursor();
}
Also used : TreeMap(java.util.TreeMap) InMemoryRecordSet(com.facebook.presto.spi.InMemoryRecordSet) TransactionId(com.facebook.presto.transaction.TransactionId) PropertyMetadata(com.facebook.presto.spi.session.PropertyMetadata) ImmutableMap(com.google.common.collect.ImmutableMap) TreeMap(java.util.TreeMap) Map(java.util.Map) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 7 with TransactionId

use of com.facebook.presto.transaction.TransactionId in project presto by prestodb.

the class QueryStateMachine method beginWithTicker.

static QueryStateMachine beginWithTicker(QueryId queryId, String query, Session session, URI self, boolean transactionControl, TransactionManager transactionManager, AccessControl accessControl, Executor executor, Ticker ticker, Metadata metadata) {
    session.getTransactionId().ifPresent(transactionControl ? transactionManager::trySetActive : transactionManager::checkAndSetActive);
    Session querySession;
    boolean autoCommit = !session.getTransactionId().isPresent() && !transactionControl;
    if (autoCommit) {
        // TODO: make autocommit isolation level a session parameter
        TransactionId transactionId = transactionManager.beginTransaction(true);
        querySession = session.beginTransactionId(transactionId, transactionManager, accessControl);
    } else {
        querySession = session;
    }
    QueryStateMachine queryStateMachine = new QueryStateMachine(queryId, query, querySession, self, autoCommit, transactionManager, executor, ticker, metadata);
    queryStateMachine.addStateChangeListener(newState -> log.debug("Query %s is %s", queryId, newState));
    queryStateMachine.addStateChangeListener(newState -> {
        if (newState.isDone()) {
            session.getTransactionId().ifPresent(transactionManager::trySetInactive);
        }
    });
    return queryStateMachine;
}
Also used : Session(com.facebook.presto.Session) TransactionId(com.facebook.presto.transaction.TransactionId)

Aggregations

TransactionId (com.facebook.presto.transaction.TransactionId)7 Session (com.facebook.presto.Session)4 PrestoException (com.facebook.presto.spi.PrestoException)3 ConnectorId (com.facebook.presto.connector.ConnectorId)2 QueryStats (com.facebook.presto.execution.QueryStats)2 StageInfo (com.facebook.presto.execution.StageInfo)2 TaskInfo (com.facebook.presto.execution.TaskInfo)2 TaskStats (com.facebook.presto.operator.TaskStats)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 DateTime (org.joda.time.DateTime)2 FailureInfo (com.facebook.presto.client.FailureInfo)1 NodeVersion (com.facebook.presto.client.NodeVersion)1 EventListenerManager (com.facebook.presto.eventlistener.EventListenerManager)1 Column (com.facebook.presto.execution.Column)1 Input (com.facebook.presto.execution.Input)1 QueryInfo (com.facebook.presto.execution.QueryInfo)1 TaskId (com.facebook.presto.execution.TaskId)1 TaskState (com.facebook.presto.execution.TaskState)1 DriverStats (com.facebook.presto.operator.DriverStats)1