use of com.facebook.presto.Session in project presto by prestodb.
the class InformationSchemaPageSourceProvider method getInternalTable.
private InternalTable getInternalTable(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, ConnectorSplit connectorSplit, List<ColumnHandle> columns) {
InformationSchemaTransactionHandle transaction = (InformationSchemaTransactionHandle) transactionHandle;
InformationSchemaSplit split = (InformationSchemaSplit) connectorSplit;
requireNonNull(columns, "columns is null");
InformationSchemaTableHandle handle = split.getTableHandle();
Map<String, NullableValue> filters = split.getFilters();
Session session = Session.builder(metadata.getSessionPropertyManager()).setTransactionId(transaction.getTransactionId()).setQueryId(new QueryId(connectorSession.getQueryId())).setIdentity(connectorSession.getIdentity()).setSource("information_schema").setCatalog(// default catalog is not be used
"").setSchema(// default schema is not be used
"").setTimeZoneKey(connectorSession.getTimeZoneKey()).setLocale(connectorSession.getLocale()).setStartTime(connectorSession.getStartTime()).build();
return getInformationSchemaTable(session, handle.getCatalogName(), handle.getSchemaTableName(), filters);
}
use of com.facebook.presto.Session in project presto by prestodb.
the class StartTransactionTask method execute.
@Override
public ListenableFuture<?> execute(StartTransaction statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
Session session = stateMachine.getSession();
if (!session.isClientTransactionSupport()) {
throw new PrestoException(StandardErrorCode.INCOMPATIBLE_CLIENT, "Client does not support transactions");
}
if (session.getTransactionId().isPresent()) {
throw new PrestoException(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 immediateFuture(null);
}
use of com.facebook.presto.Session in project presto by prestodb.
the class RenameSchemaTask method execute.
@Override
public ListenableFuture<?> execute(RenameSchema statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
Session session = stateMachine.getSession();
CatalogSchemaName source = createCatalogSchemaName(session, statement, Optional.of(statement.getSource()));
CatalogSchemaName target = new CatalogSchemaName(source.getCatalogName(), statement.getTarget());
if (!metadata.schemaExists(session, source)) {
throw new SemanticException(MISSING_SCHEMA, statement, "Schema '%s' does not exist", source);
}
if (metadata.schemaExists(session, target)) {
throw new SemanticException(SCHEMA_ALREADY_EXISTS, statement, "Target schema '%s' already exists", target);
}
accessControl.checkCanRenameSchema(session.getRequiredTransactionId(), session.getIdentity(), source, statement.getTarget());
metadata.renameSchema(session, source, statement.getTarget());
return immediateFuture(null);
}
use of com.facebook.presto.Session in project presto by prestodb.
the class RollbackTask method execute.
@Override
public ListenableFuture<?> execute(Rollback statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
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);
}
use of com.facebook.presto.Session in project presto by prestodb.
the class MetadataManager method getLayouts.
@Override
public List<TableLayoutResult> getLayouts(Session session, TableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns) {
if (constraint.getSummary().isNone()) {
return ImmutableList.of();
}
ConnectorId connectorId = table.getConnectorId();
ConnectorTableHandle connectorTable = table.getConnectorHandle();
CatalogMetadata catalogMetadata = getCatalogMetadata(session, connectorId);
ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
ConnectorTransactionHandle transaction = catalogMetadata.getTransactionHandleFor(connectorId);
ConnectorSession connectorSession = session.toConnectorSession(connectorId);
List<ConnectorTableLayoutResult> layouts = metadata.getTableLayouts(connectorSession, connectorTable, constraint, desiredColumns);
return layouts.stream().map(layout -> new TableLayoutResult(fromConnectorLayout(connectorId, transaction, layout.getTableLayout()), layout.getUnenforcedConstraint())).collect(toImmutableList());
}
Aggregations