Search in sources :

Example 6 with ParsingOptions

use of com.facebook.presto.sql.parser.ParsingOptions in project presto by prestodb.

the class TestConcurrentExecutor method createExecutor.

private ConcurrentPhaseExecutor createExecutor(BenchmarkRunnerConfig config) {
    SqlParser sqlParser = new SqlParser(new SqlParserOptions().allowIdentifierSymbol(COLON, AT_SIGN));
    ParsingOptions parsingOptions = ParsingOptions.builder().setDecimalLiteralTreatment(AS_DOUBLE).build();
    PrestoActionFactory prestoActionFactory = new BenchmarkPrestoActionFactory(new PrestoExceptionClassifier(ImmutableSet.of()), new PrestoClusterConfig().setJdbcUrl(format("jdbc:presto://%s:%s", queryRunner.getServer().getAddress().getHost(), queryRunner.getServer().getAddress().getPort())), new RetryConfig());
    return new ConcurrentPhaseExecutor(sqlParser, parsingOptions, prestoActionFactory, ImmutableSet.of(getEventClient()), config.setTestId(TEST_ID));
}
Also used : SqlParserOptions(com.facebook.presto.sql.parser.SqlParserOptions) BenchmarkPrestoActionFactory(com.facebook.presto.benchmark.prestoaction.BenchmarkPrestoActionFactory) PrestoExceptionClassifier(com.facebook.presto.benchmark.prestoaction.PrestoExceptionClassifier) RetryConfig(com.facebook.presto.benchmark.retry.RetryConfig) ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) SqlParser(com.facebook.presto.sql.parser.SqlParser) PrestoActionFactory(com.facebook.presto.benchmark.prestoaction.PrestoActionFactory) BenchmarkPrestoActionFactory(com.facebook.presto.benchmark.prestoaction.BenchmarkPrestoActionFactory) PrestoClusterConfig(com.facebook.presto.benchmark.prestoaction.PrestoClusterConfig)

Example 7 with ParsingOptions

use of com.facebook.presto.sql.parser.ParsingOptions 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;
}
Also used : ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) Statement(com.facebook.presto.sql.tree.Statement) ParsingException(com.facebook.presto.sql.parser.ParsingException) PrestoException(com.facebook.presto.spi.PrestoException)

Example 8 with ParsingOptions

use of com.facebook.presto.sql.parser.ParsingOptions in project presto by prestodb.

the class TestVariableExtractor method assertVariables.

private static void assertVariables(String expression) {
    Expression expected = rewriteIdentifiersToSymbolReferences(new SqlParser().createExpression(expression, new ParsingOptions()));
    RowExpression actual = TRANSLATOR.translate(expected, SYMBOL_TYPES);
    assertEquals(VariablesExtractor.extractUnique(expected, SYMBOL_TYPES), extractUnique(actual));
    assertEquals(VariablesExtractor.extractAll(expected, SYMBOL_TYPES).stream().sorted().collect(toImmutableList()), extractAll(actual).stream().sorted().collect(toImmutableList()));
}
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 9 with ParsingOptions

use of com.facebook.presto.sql.parser.ParsingOptions in project presto by prestodb.

the class TestRowExpressionSerde method getRoundTrip.

private RowExpression getRoundTrip(String sql, boolean optimize) {
    RowExpression rowExpression = translate(expression(sql, new ParsingOptions(AS_DOUBLE)), optimize);
    String json = codec.toJson(rowExpression);
    return codec.fromJson(json);
}
Also used : ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) RowExpression(com.facebook.presto.spi.relation.RowExpression)

Example 10 with ParsingOptions

use of com.facebook.presto.sql.parser.ParsingOptions in project presto by prestodb.

the class TestRowExpressionSerde method testDereference.

@Test
public void testDereference() {
    String sql = "CAST(ROW(1) AS ROW(col1 integer)).col1";
    RowExpression before = translate(expression(sql, new ParsingOptions(AS_DOUBLE)), false);
    RowExpression after = getRoundTrip(sql, false);
    assertEquals(before, after);
}
Also used : ParsingOptions(com.facebook.presto.sql.parser.ParsingOptions) RowExpression(com.facebook.presto.spi.relation.RowExpression) Test(org.testng.annotations.Test)

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