Search in sources :

Example 1 with Statement

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;
}
Also used : Statement(com.facebook.presto.sql.tree.Statement)

Example 2 with Statement

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);
}
Also used : QueryExplainer(com.facebook.presto.sql.analyzer.QueryExplainer) LogicalPlanner(com.facebook.presto.sql.planner.LogicalPlanner) Execute(com.facebook.presto.sql.tree.Execute) Expression(com.facebook.presto.sql.tree.Expression) PlanNodeIdAllocator(com.facebook.presto.sql.planner.PlanNodeIdAllocator) SqlQueryManager.unwrapExecuteStatement(com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement) Statement(com.facebook.presto.sql.tree.Statement) Analysis(com.facebook.presto.sql.analyzer.Analysis) Analyzer(com.facebook.presto.sql.analyzer.Analyzer)

Example 3 with Statement

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);
    }
}
Also used : SqlQueryManager.unwrapExecuteStatement(com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement) Statement(com.facebook.presto.sql.tree.Statement) Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException) Test(org.testng.annotations.Test)

Example 4 with Statement

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"))));
}
Also used : SqlQueryManager.unwrapExecuteStatement(com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement) Statement(com.facebook.presto.sql.tree.Statement) AllColumns(com.facebook.presto.sql.tree.AllColumns) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 5 with Statement

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);
    }
}
Also used : SqlQueryManager.unwrapExecuteStatement(com.facebook.presto.execution.SqlQueryManager.unwrapExecuteStatement) Statement(com.facebook.presto.sql.tree.Statement) Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException) Test(org.testng.annotations.Test)

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