Search in sources :

Example 1 with Execute

use of io.prestosql.sql.tree.Execute in project hetu-core by openlookeng.

the class TestPrepareTask method testPrepareInvalidStatement.

@Test
public void testPrepareInvalidStatement() {
    Statement statement = new Execute(identifier("foo"), emptyList());
    String sqlString = "PREPARE my_query FROM EXECUTE foo";
    assertPrestoExceptionThrownBy(() -> executePrepare("my_query", statement, sqlString, TEST_SESSION)).hasErrorCode(NOT_SUPPORTED).hasMessage("Invalid statement type for prepared statement: EXECUTE");
}
Also used : Execute(io.prestosql.sql.tree.Execute) Statement(io.prestosql.sql.tree.Statement) Test(org.testng.annotations.Test)

Example 2 with Execute

use of io.prestosql.sql.tree.Execute in project hetu-core by openlookeng.

the class PrepareTask method execute.

@Override
public ListenableFuture<?> execute(Prepare prepare, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters, HeuristicIndexerManager heuristicIndexerManager) {
    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().getValue(), sql);
    return immediateFuture(null);
}
Also used : Execute(io.prestosql.sql.tree.Execute) Deallocate(io.prestosql.sql.tree.Deallocate) Statement(io.prestosql.sql.tree.Statement) Prepare(io.prestosql.sql.tree.Prepare) PrestoException(io.prestosql.spi.PrestoException)

Example 3 with Execute

use of io.prestosql.sql.tree.Execute in project hetu-core by openlookeng.

the class QueryPreparer method prepareQuery.

public PreparedQuery prepareQuery(Session session, Statement wrappedStatement) throws ParsingException, PrestoException, SemanticException {
    Statement statement = wrappedStatement;
    Optional<String> prepareSql = Optional.empty();
    if (statement instanceof Execute) {
        prepareSql = Optional.of(session.getPreparedStatementFromExecute((Execute) statement));
        statement = sqlParser.createStatement(prepareSql.get(), createParsingOptions(session));
    }
    if (statement instanceof Explain && ((Explain) statement).isAnalyze()) {
        Statement innerStatement = ((Explain) statement).getStatement();
        Optional<QueryType> innerQueryType = StatementUtils.getQueryType(innerStatement.getClass());
        if (!innerQueryType.isPresent() || innerQueryType.get() == QueryType.DATA_DEFINITION) {
            throw new PrestoException(NOT_SUPPORTED, "EXPLAIN ANALYZE doesn't support statement type: " + innerStatement.getClass().getSimpleName());
        }
    }
    List<Expression> parameters = ImmutableList.of();
    if (wrappedStatement instanceof Execute) {
        parameters = ((Execute) wrappedStatement).getParameters();
    }
    validateParameters(statement, parameters);
    return new PreparedQuery(statement, parameters, prepareSql);
}
Also used : Execute(io.prestosql.sql.tree.Execute) Expression(io.prestosql.sql.tree.Expression) Statement(io.prestosql.sql.tree.Statement) Explain(io.prestosql.sql.tree.Explain) PrestoException(io.prestosql.spi.PrestoException) QueryType(io.prestosql.spi.resourcegroups.QueryType)

Aggregations

Execute (io.prestosql.sql.tree.Execute)3 Statement (io.prestosql.sql.tree.Statement)3 PrestoException (io.prestosql.spi.PrestoException)2 QueryType (io.prestosql.spi.resourcegroups.QueryType)1 Deallocate (io.prestosql.sql.tree.Deallocate)1 Explain (io.prestosql.sql.tree.Explain)1 Expression (io.prestosql.sql.tree.Expression)1 Prepare (io.prestosql.sql.tree.Prepare)1 Test (org.testng.annotations.Test)1