Search in sources :

Example 1 with ParsingOptions

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

Example 2 with ParsingOptions

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);
}
Also used : RowExpression(com.facebook.presto.spi.relation.RowExpression) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) Expression(com.facebook.presto.sql.tree.Expression) ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) SqlParser(com.facebook.presto.sql.parser.SqlParser) RowExpression(com.facebook.presto.spi.relation.RowExpression)

Example 3 with ParsingOptions

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();
}
Also used : ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) ParsingException(com.facebook.presto.sql.parser.ParsingException) SqlParser(com.facebook.presto.sql.parser.SqlParser) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap)

Example 4 with ParsingOptions

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));
}
Also used : ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) ParsingUtil.createParsingOptions(com.facebook.presto.sql.ParsingUtil.createParsingOptions)

Example 5 with 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);
}
Also used : ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) Statement(com.facebook.presto.sql.tree.Statement) SqlParser(com.facebook.presto.sql.parser.SqlParser)

Aggregations

ParsingOptions (com.facebook.presto.sql.parser.ParsingOptions)13 RowExpression (com.facebook.presto.spi.relation.RowExpression)5 SqlParser (com.facebook.presto.sql.parser.SqlParser)5 Expression (com.facebook.presto.sql.tree.Expression)4 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)2 ParsingException (com.facebook.presto.sql.parser.ParsingException)2 Symbol (com.facebook.presto.sql.planner.Symbol)2 TypeProvider (com.facebook.presto.sql.planner.TypeProvider)2 Statement (com.facebook.presto.sql.tree.Statement)2 BenchmarkPrestoActionFactory (com.facebook.presto.benchmark.prestoaction.BenchmarkPrestoActionFactory)1 PrestoActionFactory (com.facebook.presto.benchmark.prestoaction.PrestoActionFactory)1 PrestoClusterConfig (com.facebook.presto.benchmark.prestoaction.PrestoClusterConfig)1 PrestoExceptionClassifier (com.facebook.presto.benchmark.prestoaction.PrestoExceptionClassifier)1 RetryConfig (com.facebook.presto.benchmark.retry.RetryConfig)1 PrestoException (com.facebook.presto.spi.PrestoException)1 ParsingUtil.createParsingOptions (com.facebook.presto.sql.ParsingUtil.createParsingOptions)1 SqlParserOptions (com.facebook.presto.sql.parser.SqlParserOptions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 Test (org.testng.annotations.Test)1