use of com.facebook.presto.Session in project presto by prestodb.
the class TestDeallocateTask method testDeallocate.
@Test
public void testDeallocate() {
Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT bar, baz FROM foo").build();
Set<String> statements = executeDeallocate("my_query", "DEALLOCATE PREPARE my_query", session);
assertEquals(statements, ImmutableSet.of("my_query"));
}
use of com.facebook.presto.Session in project presto by prestodb.
the class TestRollbackTask method testUnknownTransactionRollback.
@Test
public void testUnknownTransactionRollback() throws Exception {
TransactionManager transactionManager = createTestTransactionManager();
AccessControl accessControl = new AccessControlManager(transactionManager);
Session session = sessionBuilder().setTransactionId(// Use a random transaction ID that is unknown to the system
TransactionId.create()).build();
QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), "ROLLBACK", session, URI.create("fake://uri"), true, transactionManager, accessControl, executor, metadata);
getFutureValue(new RollbackTask().execute(new Rollback(), transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList()));
// Still issue clear signal
assertTrue(stateMachine.getQueryInfoWithoutDetails().isClearTransactionId());
assertFalse(stateMachine.getQueryInfoWithoutDetails().getStartedTransactionId().isPresent());
assertTrue(transactionManager.getAllTransactionInfos().isEmpty());
}
use of com.facebook.presto.Session in project presto by prestodb.
the class TransactionBuilder method execute.
public <T> T execute(Session session, Function<Session, T> callback) {
requireNonNull(session, "session is null");
requireNonNull(callback, "callback is null");
boolean managedTransaction = !session.getTransactionId().isPresent();
Session transactionSession;
if (managedTransaction) {
TransactionId transactionId = transactionManager.beginTransaction(isolationLevel, readOnly, singleStatement);
transactionSession = session.beginTransactionId(transactionId, transactionManager, accessControl);
} else {
// Check if we can merge with the existing transaction
TransactionInfo transactionInfo = transactionManager.getTransactionInfo(session.getTransactionId().get());
checkState(transactionInfo.getIsolationLevel().meetsRequirementOf(isolationLevel), "Cannot provide %s isolation with existing transaction isolation: %s", isolationLevel, transactionInfo.getIsolationLevel());
checkState(!transactionInfo.isReadOnly() || readOnly, "Cannot provide read-write semantics with existing read-only transaction");
checkState(!transactionInfo.isAutoCommitContext() && !singleStatement, "Cannot combine auto commit transactions");
transactionSession = session;
}
boolean success = false;
try {
T result = callback.apply(transactionSession);
success = true;
return result;
} finally {
if (managedTransaction) {
if (success) {
getFutureValue(transactionManager.asyncCommit(transactionSession.getTransactionId().get()));
} else {
transactionManager.asyncAbort(transactionSession.getTransactionId().get());
}
}
}
}
use of com.facebook.presto.Session in project presto by prestodb.
the class AggregationMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
AggregationNode aggregationNode = (AggregationNode) node;
if (groupId.isPresent() != aggregationNode.getGroupIdSymbol().isPresent()) {
return NO_MATCH;
}
if (groupingSets.size() != aggregationNode.getGroupingSets().size()) {
return NO_MATCH;
}
List<Symbol> aggregationsWithMask = aggregationNode.getAggregations().entrySet().stream().filter(entry -> entry.getValue().isDistinct()).map(entry -> entry.getKey()).collect(Collectors.toList());
if (aggregationsWithMask.size() != masks.keySet().size()) {
return NO_MATCH;
}
for (Symbol symbol : aggregationsWithMask) {
if (!masks.keySet().contains(symbol)) {
return NO_MATCH;
}
}
for (int i = 0; i < groupingSets.size(); i++) {
if (!matches(groupingSets.get(i), aggregationNode.getGroupingSets().get(i), symbolAliases)) {
return NO_MATCH;
}
}
return match();
}
use of com.facebook.presto.Session in project presto by prestodb.
the class JoinMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
JoinNode joinNode = (JoinNode) node;
if (joinNode.getCriteria().size() != equiCriteria.size()) {
return NO_MATCH;
}
if (filter.isPresent()) {
if (!joinNode.getFilter().isPresent()) {
return NO_MATCH;
}
if (!new ExpressionVerifier(symbolAliases).process(joinNode.getFilter().get(), filter.get())) {
return NO_MATCH;
}
} else {
if (joinNode.getFilter().isPresent()) {
return NO_MATCH;
}
}
/*
* Have to use order-independent comparison; there are no guarantees what order
* the equi criteria will have after planning and optimizing.
*/
Set<JoinNode.EquiJoinClause> actual = ImmutableSet.copyOf(joinNode.getCriteria());
Set<JoinNode.EquiJoinClause> expected = equiCriteria.stream().map(maker -> maker.getExpectedValue(symbolAliases)).collect(toImmutableSet());
return new MatchResult(expected.equals(actual));
}
Aggregations