use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class Analyzer method analyze.
public Analysis analyze(Statement statement, boolean isDescribe) {
Statement rewrittenStatement = StatementRewrite.rewrite(session, metadata, sqlParser, queryExplainer, statement, parameters, accessControl);
Analysis analysis = new Analysis(rewrittenStatement, parameters, isDescribe);
StatementAnalyzer analyzer = new StatementAnalyzer(analysis, metadata, sqlParser, accessControl, session);
analyzer.analyze(rewrittenStatement, Scope.create());
return analysis;
}
use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class LocalQueryRunner method createPlan.
public Plan createPlan(Session session, @Language("SQL") String sql, List<PlanOptimizer> optimizers, LogicalPlanner.Stage stage) {
Statement wrapped = sqlParser.createStatement(sql);
Statement statement = unwrapExecuteStatement(wrapped, sqlParser, session);
List<Expression> parameters = emptyList();
if (wrapped instanceof Execute) {
parameters = ((Execute) wrapped).getParameters();
}
validateParameters(statement, parameters);
assertFormattedSql(sqlParser, statement);
PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
QueryExplainer queryExplainer = new QueryExplainer(optimizers, metadata, accessControl, sqlParser, dataDefinitionTask);
Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(queryExplainer), parameters);
LogicalPlanner logicalPlanner = new LogicalPlanner(session, optimizers, idAllocator, metadata, sqlParser);
Analysis analysis = analyzer.analyze(statement);
return logicalPlanner.plan(analysis, stage);
}
use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class TestUnwrapExecute method testTooManyParameters.
@Test
public void testTooManyParameters() throws Exception {
try {
Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT * FROM foo where col1 = ?").build();
Statement statement = SQL_PARSER.createStatement("EXECUTE my_query USING 1,2");
validateParameters(unwrapExecuteStatement(statement, SQL_PARSER, session), ((Execute) statement).getParameters());
fail("expected exception");
} catch (SemanticException e) {
assertEquals(e.getCode(), INVALID_PARAMETER_USAGE);
}
}
use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class TestUnwrapExecute method testExecuteStatement.
@Test
public void testExecuteStatement() throws Exception {
Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT * FROM foo").build();
Statement statement = SQL_PARSER.createStatement("EXECUTE my_query");
assertEquals(unwrapExecuteStatement(statement, SQL_PARSER, session), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo"))));
}
use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class TestUnwrapExecute method testTooFewParameters.
@Test
public void testTooFewParameters() throws Exception {
try {
Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT ? FROM foo where col1 = ?").build();
Statement statement = SQL_PARSER.createStatement("EXECUTE my_query USING 1");
validateParameters(unwrapExecuteStatement(statement, SQL_PARSER, session), ((Execute) statement).getParameters());
fail("expected exception");
} catch (SemanticException e) {
assertEquals(e.getCode(), INVALID_PARAMETER_USAGE);
}
}
Aggregations