Search in sources :

Example 96 with Session

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"));
}
Also used : Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 97 with Session

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());
}
Also used : AccessControlManager(com.facebook.presto.security.AccessControlManager) TransactionManager(com.facebook.presto.transaction.TransactionManager) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) QueryId(com.facebook.presto.spi.QueryId) Rollback(com.facebook.presto.sql.tree.Rollback) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) AccessControl(com.facebook.presto.security.AccessControl) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 98 with Session

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());
            }
        }
    }
}
Also used : Session(com.facebook.presto.Session)

Example 99 with Session

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();
}
Also used : Session(com.facebook.presto.Session) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Symbol(com.facebook.presto.sql.planner.Symbol) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Map(java.util.Map) MatchResult.match(com.facebook.presto.sql.planner.assertions.MatchResult.match) Optional(java.util.Optional) NO_MATCH(com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) AggregationNode(com.facebook.presto.sql.planner.plan.AggregationNode) Metadata(com.facebook.presto.metadata.Metadata) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Symbol(com.facebook.presto.sql.planner.Symbol) AggregationNode(com.facebook.presto.sql.planner.plan.AggregationNode)

Example 100 with Session

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));
}
Also used : JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) ImmutableSet(com.google.common.collect.ImmutableSet) Session(com.facebook.presto.Session) Set(java.util.Set) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Expression(com.facebook.presto.sql.tree.Expression) PlanNode(com.facebook.presto.sql.planner.plan.PlanNode) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) NO_MATCH(com.facebook.presto.sql.planner.assertions.MatchResult.NO_MATCH) ImmutableCollectors.toImmutableSet(com.facebook.presto.util.ImmutableCollectors.toImmutableSet) Metadata(com.facebook.presto.metadata.Metadata) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode)

Aggregations

Session (com.facebook.presto.Session)121 Test (org.testng.annotations.Test)61 QueryId (com.facebook.presto.spi.QueryId)21 MaterializedResult (com.facebook.presto.testing.MaterializedResult)20 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)19 PrestoException (com.facebook.presto.spi.PrestoException)17 TransactionManager (com.facebook.presto.transaction.TransactionManager)16 AccessControl (com.facebook.presto.security.AccessControl)15 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)14 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)14 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)13 AccessControlManager (com.facebook.presto.security.AccessControlManager)13 ConnectorId (com.facebook.presto.connector.ConnectorId)12 LocalQueryRunner (com.facebook.presto.testing.LocalQueryRunner)12 Type (com.facebook.presto.spi.type.Type)11 List (java.util.List)11 TableHandle (com.facebook.presto.metadata.TableHandle)10 TpchConnectorFactory (com.facebook.presto.tpch.TpchConnectorFactory)10 Optional (java.util.Optional)10 ColumnHandle (com.facebook.presto.spi.ColumnHandle)9