use of io.trino.sql.parser.ParsingException in project trino by trinodb.
the class SqlFormatterUtil method getFormattedSql.
public static String getFormattedSql(Statement statement, SqlParser sqlParser) {
String sql = SqlFormatter.formatSql(statement);
// verify round-trip
Statement parsed;
try {
ParsingOptions parsingOptions = new ParsingOptions(REJECT);
parsed = sqlParser.createStatement(sql, parsingOptions);
} catch (ParsingException e) {
throw formattingFailure(e, "Formatted query does not parse", statement, sql);
}
if (!statement.equals(parsed)) {
throw formattingFailure(null, "Query does not round-trip", statement, sql);
}
return sql;
}
use of io.trino.sql.parser.ParsingException in project trino by trinodb.
the class HttpRequestSessionContextFactory method parsePreparedStatementsHeaders.
private Map<String, String> parsePreparedStatementsHeaders(ProtocolHeaders protocolHeaders, MultivaluedMap<String, String> headers) {
ImmutableMap.Builder<String, String> preparedStatements = ImmutableMap.builder();
parseProperty(headers, protocolHeaders.requestPreparedStatement()).forEach((key, value) -> {
String statementName;
try {
statementName = urlDecode(key);
} catch (IllegalArgumentException e) {
throw badRequest(format("Invalid %s header: %s", protocolHeaders.requestPreparedStatement(), e.getMessage()));
}
String sqlString = preparedStatementEncoder.decodePreparedStatementFromHeader(value);
// Validate statement
SqlParser sqlParser = new SqlParser();
try {
sqlParser.createStatement(sqlString, new ParsingOptions(AS_DOUBLE));
} catch (ParsingException e) {
throw badRequest(format("Invalid %s header: %s", protocolHeaders.requestPreparedStatement(), e.getMessage()));
}
preparedStatements.put(statementName, sqlString);
});
return preparedStatements.buildOrThrow();
}
use of io.trino.sql.parser.ParsingException in project trino by trinodb.
the class TypeCalculation method calculateLiteralValue.
public static Long calculateLiteralValue(String calculation, Map<String, Long> inputs) {
try {
ParserRuleContext tree = parseTypeCalculation(calculation);
CalculateTypeVisitor visitor = new CalculateTypeVisitor(inputs);
BigInteger result = visitor.visit(tree);
return result.longValueExact();
} catch (StackOverflowError e) {
throw new ParsingException("Type calculation is too large (stack overflow while parsing)");
}
}
Aggregations