Code review comment: There are only three places where BLACKQUOTE is used. This label cannot be added arbitrarily and can only be used behind AS

Code under review:
public String visitSelect(SelectRelation stmt, Void context) {
            StringBuilder sqlBuilder = new StringBuilder();
            SelectList selectList = stmt.getSelectList();
            sqlBuilder.append("SELECT ");
            if (selectList.isDistinct()) {
                sqlBuilder.append("DISTINCT");
            }

            List<String> selectListString = new ArrayList<>();
            for (int i = 0; i < selectList.getItems().size(); ++i) {
                SelectListItem item = selectList.getItems().get(i);
                if (item.isStar()) {
                    List<Expr> outputExpression = SelectAnalyzer.expandStar(item, stmt.getRelation());
                    for (Expr expr : outputExpression) {
                        selectListString.add(visit(expr) + " AS `" + toSQL(expr) + "`");
                    }
                } else {
                    if (item.getAlias() != null) {
                        selectListString.add((visit(item.getExpr()) + " AS `" + item.getAlias()) + "`");
                    } else {
                        selectListString.add(visit(item.getExpr()) + " AS `" + toSQL(item.getExpr()) + "`");
                    }
                }
            }
            sqlBuilder.append(Joiner.on(", ").join(selectListString));

            if (stmt.getRelation() != null) {
                sqlBuilder.append(" FROM ");
                sqlBuilder.append(visit(stmt.getRelation()));
            }

            if (stmt.hasWhereClause()) {
                sqlBuilder.append(" WHERE ");
                sqlBuilder.append(visit(stmt.getWhereClause()));
            }

            if (stmt.hasGroupByClause()) {
                sqlBuilder.append(" GROUP BY ");
                sqlBuilder.append(stmt.getGroupByClause().toSql());
            }

            if (stmt.hasHavingClause()) {
                sqlBuilder.append(" HAVING ");
                sqlBuilder.append(visit(stmt.getHavingClause()));
            }

            return sqlBuilder.toString();
        }

Line commented on: selectListString.add(visit(expr) + " AS `" + toSQL(expr) + "`");

Revised code:
public String visitSelect(SelectRelation stmt, Void context) {
            StringBuilder sqlBuilder = new StringBuilder();
            SelectList selectList = stmt.getSelectList();
            sqlBuilder.append("SELECT ");
            if (selectList.isDistinct()) {
                sqlBuilder.append("DISTINCT");
            }

            List<String> selectListString = new ArrayList<>();
            for (int i = 0; i < selectList.getItems().size(); ++i) {
                SelectListItem item = selectList.getItems().get(i);
                if (item.isStar()) {
                    List<Expr> outputExpression = SelectAnalyzer.expandStar(item, stmt.getRelation());
                    for (Expr expr : outputExpression) {
                        selectListString.add(visit(expr) + " AS `" + AST2SQL.toString(expr) + "`");
                    }
                } else {
                    if (item.getAlias() != null) {
                        selectListString.add((visit(item.getExpr()) + " AS `" + item.getAlias()) + "`");
                    } else {
                        selectListString.add(visit(item.getExpr()) + " AS `" + AST2SQL.toString(item.getExpr()) + "`");
                    }
                }
            }
            sqlBuilder.append(Joiner.on(", ").join(selectListString));

            if (stmt.getRelation() != null) {
                sqlBuilder.append(" FROM ");
                sqlBuilder.append(visit(stmt.getRelation()));
            }

            if (stmt.hasWhereClause()) {
                sqlBuilder.append(" WHERE ");
                sqlBuilder.append(visit(stmt.getWhereClause()));
            }

            if (stmt.hasGroupByClause()) {
                sqlBuilder.append(" GROUP BY ");
                sqlBuilder.append(stmt.getGroupByClause().toSql());
            }

            if (stmt.hasHavingClause()) {
                sqlBuilder.append(" HAVING ");
                sqlBuilder.append(visit(stmt.getHavingClause()));
            }

            return sqlBuilder.toString();
        }