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());
}
}
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"))));
}
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());
}
}
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);
}
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);
}
Aggregations