use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class SqlFormatterUtil method getFormattedSql.
public static String getFormattedSql(Statement statement, SqlParser sqlParser, Optional<List<Expression>> parameters) {
String sql = SqlFormatter.formatSql(statement, parameters);
// verify round-trip
Statement parsed;
try {
ParsingOptions parsingOptions = new ParsingOptions(REJECT);
parsed = sqlParser.createStatement(sql, parsingOptions);
} catch (ParsingException e) {
throw new PrestoException(GENERIC_INTERNAL_ERROR, "Formatted query does not parse: " + statement);
}
if (!statement.equals(parsed)) {
throw new PrestoException(GENERIC_INTERNAL_ERROR, "Query does not round-trip: " + statement);
}
return sql;
}
use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class AbstractAnalyzerTest method analyze.
private void analyze(Session clientSession, WarningCollector warningCollector, @Language("SQL") String query) {
transaction(transactionManager, accessControl).singleStatement().readUncommitted().readOnly().execute(clientSession, session -> {
Analyzer analyzer = AbstractAnalyzerTest.createAnalyzer(session, metadata, warningCollector);
Statement statement = SQL_PARSER.createStatement(query);
analyzer.analyze(statement);
});
}
use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class TestUtilizedColumnsAnalyzer method assertUtilizedTableColumns.
private void assertUtilizedTableColumns(@Language("SQL") String query, Map<QualifiedObjectName, Set<String>> expected) {
transaction(transactionManager, accessControl).singleStatement().readUncommitted().readOnly().execute(CLIENT_SESSION, session -> {
Analyzer analyzer = createAnalyzer(session, metadata, WarningCollector.NOOP);
Statement statement = SQL_PARSER.createStatement(query);
Analysis analysis = analyzer.analyze(statement);
assertEquals(analysis.getUtilizedTableColumnReferences().values().stream().findFirst().get(), expected);
});
}
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, 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);
}
use of com.facebook.presto.sql.tree.Statement in project presto by prestodb.
the class TestSqlParser method assertInvalidStatement.
private static void assertInvalidStatement(String expression, String expectedErrorMessageRegex) {
try {
Statement result = SQL_PARSER.createStatement(expression, ParsingOptions.builder().build());
fail("Expected to throw ParsingException for input:[" + expression + "], but got: " + result);
} catch (ParsingException e) {
if (!e.getErrorMessage().matches(expectedErrorMessageRegex)) {
fail(format("Expected error message to match '%s', but was: '%s'", expectedErrorMessageRegex, e.getErrorMessage()));
}
}
}
Aggregations