Search in sources :

Example 21 with Statement

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

the class TestUnwrapExecute method testExecuteStatementDoesNotExist.

@Test
public void testExecuteStatementDoesNotExist() throws Exception {
    try {
        Statement statement = SQL_PARSER.createStatement("execute my_query");
        unwrapExecuteStatement(statement, SQL_PARSER, TEST_SESSION);
        fail("expected exception");
    } catch (PrestoException e) {
        assertEquals(e.getErrorCode(), NOT_FOUND.toErrorCode());
    }
}
Also used : SqlQueryManager.unwrapExecuteStatement(com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement) Statement(com.facebook.presto.sql.tree.Statement) PrestoException(com.facebook.presto.spi.PrestoException) Test(org.testng.annotations.Test)

Example 22 with Statement

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

the class TestUnwrapExecute method testSelectStatement.

@Test
public void testSelectStatement() throws Exception {
    Statement statement = SQL_PARSER.createStatement("SELECT * FROM foo");
    assertEquals(unwrapExecuteStatement(statement, SQL_PARSER, TEST_SESSION), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo"))));
}
Also used : SqlQueryManager.unwrapExecuteStatement(com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement) Statement(com.facebook.presto.sql.tree.Statement) AllColumns(com.facebook.presto.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Example 23 with Statement

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

the class AbstractPhaseExecutor method runQuery.

protected BenchmarkQueryEvent runQuery(BenchmarkQuery benchmarkQuery) {
    Optional<QueryStats> queryStats = Optional.empty();
    Statement statement = sqlParser.createStatement(benchmarkQuery.getQuery(), parsingOptions);
    PrestoAction prestoAction = prestoActionFactory.get(benchmarkQuery);
    try {
        queryStats = Optional.of(prestoAction.execute(statement));
        return buildEvent(benchmarkQuery, queryStats, Optional.empty());
    } catch (QueryException e) {
        return buildEvent(benchmarkQuery, queryStats, Optional.of(e));
    } catch (Throwable t) {
        log.error(t);
        return buildEvent(benchmarkQuery, queryStats, Optional.empty());
    }
}
Also used : PrestoAction(com.facebook.presto.benchmark.prestoaction.PrestoAction) QueryStats(com.facebook.presto.jdbc.QueryStats) Statement(com.facebook.presto.sql.tree.Statement)

Example 24 with Statement

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

the class QueryPreparer method prepareQuery.

public PreparedQuery prepareQuery(Session session, Statement wrappedStatement, WarningCollector warningCollector) 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, warningCollector));
    }
    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);
    Optional<String> formattedQuery = Optional.empty();
    if (isLogFormattedQueryEnabled(session)) {
        formattedQuery = Optional.of(getFormattedQuery(statement, parameters));
    }
    return new PreparedQuery(statement, parameters, formattedQuery, prepareSql);
}
Also used : Execute(com.facebook.presto.sql.tree.Execute) Expression(com.facebook.presto.sql.tree.Expression) Statement(com.facebook.presto.sql.tree.Statement) Explain(com.facebook.presto.sql.tree.Explain) PrestoException(com.facebook.presto.spi.PrestoException) QueryType(com.facebook.presto.spi.resourceGroups.QueryType)

Example 25 with Statement

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

the class PrepareTask method execute.

@Override
public ListenableFuture<?> execute(Prepare prepare, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine queryStateMachine, 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());
    queryStateMachine.addPreparedStatement(prepare.getName().getValue(), 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)

Aggregations

Statement (com.facebook.presto.sql.tree.Statement)34 SqlQueryManager.unwrapExecuteStatement (com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement)7 Test (org.testng.annotations.Test)7 Session (com.facebook.presto.Session)6 PrestoException (com.facebook.presto.spi.PrestoException)6 Execute (com.facebook.presto.sql.tree.Execute)5 Expression (com.facebook.presto.sql.tree.Expression)5 Analysis (com.facebook.presto.sql.analyzer.Analysis)4 Analyzer (com.facebook.presto.sql.analyzer.Analyzer)4 ParsingException (com.facebook.presto.sql.parser.ParsingException)4 Explain (com.facebook.presto.sql.tree.Explain)4 FeaturesConfig (com.facebook.presto.sql.analyzer.FeaturesConfig)3 QueryExplainer (com.facebook.presto.sql.analyzer.QueryExplainer)3 CreateView (com.facebook.presto.sql.tree.CreateView)3 TransactionManager (com.facebook.presto.transaction.TransactionManager)3 ImmutableList (com.google.common.collect.ImmutableList)3 QueryPreparer (com.facebook.presto.execution.QueryPreparer)2 SqlQueryExecutionFactory (com.facebook.presto.execution.SqlQueryExecution.SqlQueryExecutionFactory)2 QueryStats (com.facebook.presto.jdbc.QueryStats)2 QueryType (com.facebook.presto.spi.resourceGroups.QueryType)2