use of com.facebook.presto.sql.parser.ParsingOptions in project presto by prestodb.
the class TreeAssertions method assertFormattedSql.
public static void assertFormattedSql(SqlParser sqlParser, Node expected) {
ParsingOptions parsingOptions = new ParsingOptions(AS_DOUBLE);
assertFormattedSql(sqlParser, parsingOptions, expected);
}
use of com.facebook.presto.sql.parser.ParsingOptions in project presto by prestodb.
the class TestNullabilityAnalyzer method assertNullability.
private void assertNullability(String expression, boolean mayReturnNullForNotNullInput) {
Expression rawExpression = rewriteIdentifiersToSymbolReferences(new SqlParser().createExpression(expression, new ParsingOptions()));
Expression desugaredExpression = new TestingDesugarExpressions(TYPES.allVariables()).rewrite(rawExpression);
RowExpression rowExpression = TRANSLATOR.translate(desugaredExpression, TYPES);
assertEquals(analyzer.mayReturnNullOnNonNullInput(rowExpression), mayReturnNullForNotNullInput);
}
use of com.facebook.presto.sql.parser.ParsingOptions in project presto by prestodb.
the class HttpRequestSessionContext method parsePreparedStatementsHeaders.
private static Map<String, String> parsePreparedStatementsHeaders(HttpServletRequest servletRequest, SqlParserOptions sqlParserOptions) {
ImmutableMap.Builder<String, String> preparedStatements = ImmutableMap.builder();
for (String header : splitSessionHeader(servletRequest.getHeaders(PRESTO_PREPARED_STATEMENT))) {
List<String> nameValue = Splitter.on('=').limit(2).trimResults().splitToList(header);
assertRequest(nameValue.size() == 2, "Invalid %s header", PRESTO_PREPARED_STATEMENT);
String statementName;
String sqlString;
try {
statementName = urlDecode(nameValue.get(0));
sqlString = urlDecode(nameValue.get(1));
} catch (IllegalArgumentException e) {
throw badRequest(format("Invalid %s header: %s", PRESTO_PREPARED_STATEMENT, e.getMessage()));
}
// Validate statement
SqlParser sqlParser = new SqlParser(sqlParserOptions);
try {
sqlParser.createStatement(sqlString, new ParsingOptions(AS_DOUBLE));
} catch (ParsingException e) {
throw badRequest(format("Invalid %s header: %s", PRESTO_PREPARED_STATEMENT, e.getMessage()));
}
preparedStatements.put(statementName, sqlString);
}
return preparedStatements.build();
}
use of com.facebook.presto.sql.parser.ParsingOptions in project presto by prestodb.
the class TestExpressionInterpreter method assertRoundTrip.
private static void assertRoundTrip(String expression) {
ParsingOptions parsingOptions = createParsingOptions(TEST_SESSION);
assertEquals(SQL_PARSER.createExpression(expression, parsingOptions), SQL_PARSER.createExpression(formatExpression(SQL_PARSER.createExpression(expression, parsingOptions), Optional.empty()), parsingOptions));
}
use of com.facebook.presto.sql.parser.ParsingOptions in project presto by prestodb.
the class TestSqlFormatter method assetQuery.
private void assetQuery(String query) {
SqlParser parser = new SqlParser();
Statement statement = parser.createStatement(query, new ParsingOptions());
String formattedQuery = getFormattedSql(statement, parser, Optional.empty());
assertEquals(formattedQuery, query);
}
Aggregations