presto-main/src/main/java/io/prestosql/sql/SqlFormatterUtil.java/SqlFormatterUtil/getFormattedSql
class SqlFormatterUtil:    public static String getFormattedSql(Statement statement, SqlParser sqlParser)
    {
        String sql = SqlFormatter.formatSql(statement);

        // verify round-trip
        Statement parsed;
        try {
            ParsingOptions parsingOptions = new ParsingOptions(REJECT /* formatted SQL should be unambiguous */);
            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;
    }