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));
}
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;
}
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()));
}
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);
}
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);
}
Aggregations