Search in sources :

Example 1 with Prepare

use of com.facebook.presto.sql.tree.Prepare in project presto by prestodb.

the class PrepareTask method execute.

@Override
public ListenableFuture<?> execute(Prepare prepare, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
    Statement statement = prepare.getStatement();
    if ((statement instanceof Prepare) || (statement instanceof Execute) || (statement instanceof Deallocate)) {
        String type = statement.getClass().getSimpleName().toUpperCase(ENGLISH);
        throw new PrestoException(NOT_SUPPORTED, "Invalid statement type for prepared statement: " + type);
    }
    String sql = getFormattedSql(statement, sqlParser, Optional.empty());
    stateMachine.addPreparedStatement(prepare.getName(), sql);
    return immediateFuture(null);
}
Also used : Execute(com.facebook.presto.sql.tree.Execute) Deallocate(com.facebook.presto.sql.tree.Deallocate) Statement(com.facebook.presto.sql.tree.Statement) Prepare(com.facebook.presto.sql.tree.Prepare) PrestoException(com.facebook.presto.spi.PrestoException)

Example 2 with Prepare

use of com.facebook.presto.sql.tree.Prepare in project presto by prestodb.

the class TestPrepareTask method executePrepare.

private Map<String, String> executePrepare(String statementName, Statement statement, String sqlString, Session session) {
    TransactionManager transactionManager = createTestTransactionManager();
    AccessControl accessControl = new AccessControlManager(transactionManager);
    QueryStateMachine stateMachine = QueryStateMachine.begin(new QueryId("query"), sqlString, session, URI.create("fake://uri"), false, transactionManager, accessControl, executor, metadata);
    Prepare prepare = new Prepare(statementName, statement);
    new PrepareTask(new SqlParser()).execute(prepare, transactionManager, metadata, new AllowAllAccessControl(), stateMachine, emptyList());
    return stateMachine.getAddedPreparedStatements();
}
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) SqlParser(com.facebook.presto.sql.parser.SqlParser) Prepare(com.facebook.presto.sql.tree.Prepare) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) AccessControl(com.facebook.presto.security.AccessControl)

Aggregations

Prepare (com.facebook.presto.sql.tree.Prepare)2 AccessControl (com.facebook.presto.security.AccessControl)1 AccessControlManager (com.facebook.presto.security.AccessControlManager)1 AllowAllAccessControl (com.facebook.presto.security.AllowAllAccessControl)1 PrestoException (com.facebook.presto.spi.PrestoException)1 QueryId (com.facebook.presto.spi.QueryId)1 SqlParser (com.facebook.presto.sql.parser.SqlParser)1 Deallocate (com.facebook.presto.sql.tree.Deallocate)1 Execute (com.facebook.presto.sql.tree.Execute)1 Statement (com.facebook.presto.sql.tree.Statement)1 TransactionManager (com.facebook.presto.transaction.TransactionManager)1 TransactionManager.createTestTransactionManager (com.facebook.presto.transaction.TransactionManager.createTestTransactionManager)1