Search in sources :

Example 1 with PreparedQuery

use of com.facebook.presto.execution.QueryPreparer.PreparedQuery in project presto by prestodb.

the class TestQueryPreparer method testFormattedQuery.

@Test
public void testFormattedQuery() {
    Session prepareSession = testSessionBuilder().setSystemProperty(LOG_FORMATTED_QUERY_ENABLED, "true").build();
    PreparedQuery preparedQuery = QUERY_PREPARER.prepareQuery(prepareSession, "PREPARE test FROM SELECT * FROM foo where col1 = ?", WarningCollector.NOOP);
    assertEquals(preparedQuery.getFormattedQuery(), Optional.of("-- Formatted Query:\n" + "PREPARE test FROM\n" + "   SELECT *\n" + "   FROM\n" + "     foo\n" + "   WHERE (col1 = ?)\n"));
    preparedQuery = QUERY_PREPARER.prepareQuery(prepareSession, "PREPARE test FROM SELECT * FROM foo", WarningCollector.NOOP);
    assertEquals(preparedQuery.getFormattedQuery(), Optional.of("-- Formatted Query:\n" + "PREPARE test FROM\n" + "   SELECT *\n" + "   FROM\n" + "     foo\n"));
}
Also used : PreparedQuery(com.facebook.presto.execution.QueryPreparer.PreparedQuery) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 2 with PreparedQuery

use of com.facebook.presto.execution.QueryPreparer.PreparedQuery in project presto by prestodb.

the class TestQueryPreparer method testExecuteStatement.

@Test
public void testExecuteStatement() {
    Session session = testSessionBuilder().addPreparedStatement("my_query", "SELECT * FROM foo").build();
    PreparedQuery preparedQuery = QUERY_PREPARER.prepareQuery(session, "EXECUTE my_query", WarningCollector.NOOP);
    assertEquals(preparedQuery.getStatement(), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo"))));
}
Also used : PreparedQuery(com.facebook.presto.execution.QueryPreparer.PreparedQuery) AllColumns(com.facebook.presto.sql.tree.AllColumns) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 3 with PreparedQuery

use of com.facebook.presto.execution.QueryPreparer.PreparedQuery in project presto by prestodb.

the class TestQueryPreparer method testSelectStatement.

@Test
public void testSelectStatement() {
    PreparedQuery preparedQuery = QUERY_PREPARER.prepareQuery(TEST_SESSION, "SELECT * FROM foo", WarningCollector.NOOP);
    assertEquals(preparedQuery.getStatement(), simpleQuery(selectList(new AllColumns()), table(QualifiedName.of("foo"))));
}
Also used : PreparedQuery(com.facebook.presto.execution.QueryPreparer.PreparedQuery) AllColumns(com.facebook.presto.sql.tree.AllColumns) Test(org.testng.annotations.Test)

Example 4 with PreparedQuery

use of com.facebook.presto.execution.QueryPreparer.PreparedQuery 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, WarningCollector warningCollector) {
    Statement wrappedStatement = sqlParser.createStatement(sql, createParsingOptions(session, warningCollector));
    PreparedQuery preparedQuery = new QueryPreparer(sqlParser).prepareQuery(session, wrappedStatement, warningCollector);
    assertFormattedSql(sqlParser, createParsingOptions(session), preparedQuery.getStatement());
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    QueryExplainer queryExplainer = new QueryExplainer(optimizers, planFragmenter, metadata, accessControl, sqlParser, statsCalculator, costCalculator, dataDefinitionTask, distributedPlanChecker);
    Analyzer analyzer = new Analyzer(session, metadata, sqlParser, accessControl, Optional.of(queryExplainer), preparedQuery.getParameters(), warningCollector);
    LogicalPlanner logicalPlanner = new LogicalPlanner(wrappedStatement instanceof Explain, session, optimizers, singleNodePlanChecker, idAllocator, metadata, sqlParser, statsCalculator, costCalculator, warningCollector);
    Analysis analysis = analyzer.analyze(preparedQuery.getStatement());
    return logicalPlanner.plan(analysis, stage);
}
Also used : QueryPreparer(com.facebook.presto.execution.QueryPreparer) QueryExplainer(com.facebook.presto.sql.analyzer.QueryExplainer) LogicalPlanner(com.facebook.presto.sql.planner.LogicalPlanner) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) Statement(com.facebook.presto.sql.tree.Statement) Analysis(com.facebook.presto.sql.analyzer.Analysis) Explain(com.facebook.presto.sql.tree.Explain) PreparedQuery(com.facebook.presto.execution.QueryPreparer.PreparedQuery) Analyzer(com.facebook.presto.sql.analyzer.Analyzer)

Example 5 with PreparedQuery

use of com.facebook.presto.execution.QueryPreparer.PreparedQuery in project presto by prestodb.

the class LocalQueryRunner method createPlan.

public Plan createPlan(Session session, @Language("SQL") String sql, LogicalPlanner.Stage stage, boolean forceSingleNode, WarningCollector warningCollector) {
    PreparedQuery preparedQuery = new QueryPreparer(sqlParser).prepareQuery(session, sql, warningCollector);
    assertFormattedSql(sqlParser, createParsingOptions(session), preparedQuery.getStatement());
    return createPlan(session, sql, getPlanOptimizers(forceSingleNode), stage, warningCollector);
}
Also used : QueryPreparer(com.facebook.presto.execution.QueryPreparer) PreparedQuery(com.facebook.presto.execution.QueryPreparer.PreparedQuery)

Aggregations

PreparedQuery (com.facebook.presto.execution.QueryPreparer.PreparedQuery)7 Session (com.facebook.presto.Session)4 QueryPreparer (com.facebook.presto.execution.QueryPreparer)2 PrestoException (com.facebook.presto.spi.PrestoException)2 WarningCollector (com.facebook.presto.spi.WarningCollector)2 QueryType (com.facebook.presto.spi.resourceGroups.QueryType)2 AllColumns (com.facebook.presto.sql.tree.AllColumns)2 Test (org.testng.annotations.Test)2 DDLDefinitionTask (com.facebook.presto.execution.DDLDefinitionTask)1 QueryInfo (com.facebook.presto.execution.QueryInfo)1 QueryStateTimer (com.facebook.presto.execution.QueryStateTimer)1 StreamingSubPlan (com.facebook.presto.execution.scheduler.StreamingSubPlan)1 TableWriteInfo (com.facebook.presto.execution.scheduler.TableWriteInfo)1 TableWriteInfo.createTableWriteInfo (com.facebook.presto.execution.scheduler.TableWriteInfo.createTableWriteInfo)1 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)1 BasicQueryInfo (com.facebook.presto.server.BasicQueryInfo)1 SessionContext (com.facebook.presto.server.SessionContext)1 PrestoSparkSessionProperties.getSparkBroadcastJoinMaxMemoryOverride (com.facebook.presto.spark.PrestoSparkSessionProperties.getSparkBroadcastJoinMaxMemoryOverride)1 IPrestoSparkQueryExecution (com.facebook.presto.spark.classloader_interface.IPrestoSparkQueryExecution)1 PrestoSparkExecutionException (com.facebook.presto.spark.classloader_interface.PrestoSparkExecutionException)1