use of com.facebook.presto.Session in project presto by prestodb.
the class AbstractTestQueries method testExecuteUsingWithSubquery.
@Test
public void testExecuteUsingWithSubquery() {
String query = "SELECT ? in (SELECT orderkey FROM orders)";
Session session = Session.builder(getSession()).addPreparedStatement("my_query", query).build();
assertQuery(session, "EXECUTE my_query USING 10", "SELECT 10 in (SELECT orderkey FROM orders)");
}
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));
}
use of com.facebook.presto.Session in project presto by prestodb.
the class MemoryLocalQueryRunner method createMemoryLocalQueryRunner.
private static LocalQueryRunner createMemoryLocalQueryRunner() {
Session.SessionBuilder sessionBuilder = testSessionBuilder().setCatalog("memory").setSchema("default");
Session session = sessionBuilder.build();
LocalQueryRunner localQueryRunner = LocalQueryRunner.queryRunnerWithInitialTransaction(session);
// add tpch
localQueryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.<String, String>of());
localQueryRunner.createCatalog("memory", new MemoryConnectorFactory(), ImmutableMap.<String, String>of());
return localQueryRunner;
}
Aggregations