Replace SPEL ==, &&, || to SQL =, and, or .
@param spel the spring expression
@return sql expression
358702
private static String replaceOperators(String spel) {
        if (StringUtils.isBlank(spel)) {
            return spel;
        }
        return spel.replaceAll("==", " = ")
            .replaceAll("&&", " and ")
            .replaceAll("\\|\\|", " or ");
    }
424855
def regexp_replace(str, pattern, replacement):
    
    """
    sc = SparkContext._active_spark_context
    jc = sc._jvm.functions.regexp_replace(_to_java_column(str), pattern, replacement)
    return Column(jc)
1321465
public static Expression replace(Expression expression, String substring, String repl) {
        return x("REPLACE(" + expression.toString() + ", \"" + substring + "\", \"" + repl + "\")");
    }
1077122
public String replaceVariableStatements(final JQLContext jqlContext, final String jql, final JQLReplaceVariableStatementListener listener) {
		final List<Triple<Token, Token, String>> replace = new ArrayList<>();
		final One<Integer> currentSelectLevel = new One<Integer>(-1);

		JqlBaseListener rewriterListener = new JqlBaseListener() {

			@Override
			public void enterSelect_core(Select_coreContext ctx) {
				currentSelectLevel.value0++;
			}

			@Override
			public void enterSelect_or_values(Select_or_valuesContext ctx) {
				currentSelectLevel.value0++;
			}

			@Override
			public void exitSelect_core(Select_coreContext ctx) {
				currentSelectLevel.value0--;
			}

			@Override
			public void exitSelect_or_values(Select_or_valuesContext ctx) {
				currentSelectLevel.value0--;
			}

			@Override
			public void enterProjected_columns(Projected_columnsContext ctx) {
				// we work on level 0
				if (currentSelectLevel.value0 > 0)
					return;

				int start = ctx.getStart().getStartIndex() - 1;
				int stop = ctx.getStop().getStopIndex() + 1;

				if (start == stop)
					return;

				String statement = jql.substring(start, stop);

				String value = listener.onProjectedColumns(statement);

				if (value != null) {
					replace.add(new Triple<Token, Token, String>(ctx.start, ctx.stop, value));
				}
			}

			@Override
			public void enterWhere_stmt(Where_stmtContext ctx) {
				// we work on level 0
				if (currentSelectLevel.value0 > 0)
					return;

				int start = ctx.getStart().getStartIndex() - 1;
				int stop = ctx.getStop().getStopIndex() + 1;

				if (start == stop)
					return;

				String statement = jql.substring(start, stop);

				String value = listener.onWhere(statement);

				if (value != null) {
					replace.add(new Triple<Token, Token, String>(ctx.start, ctx.stop, value));
				}
			}

			@Override
			public void enterOrder_stmt(Order_stmtContext ctx) {
				// we work on level 0
				if (currentSelectLevel.value0 > 0)
					return;

				int start = ctx.getStart().getStartIndex() - 1;
				int stop = ctx.getStop().getStopIndex() + 1;

				if (start == stop)
					return;

				String statement = jql.substring(start, stop);

				String value = listener.onOrderBy(statement);

				if (value != null) {
					replace.add(new Triple<Token, Token, String>(ctx.start, ctx.stop, value));
				}
			}

			@Override
			public void enterGroup_stmt(Group_stmtContext ctx) {
				// we work on level 0
				if (currentSelectLevel.value0 > 0)
					return;

				int start = ctx.getStart().getStartIndex() - 1;
				int stop = ctx.getStop().getStopIndex() + 1;

				if (start == stop)
					return;

				String statement = jql.substring(start, stop);

				String value = listener.onGroup(statement);

				if (value != null) {
					replace.add(new Triple<Token, Token, String>(ctx.start, ctx.stop, value));
				}
			}

			@Override
			public void enterHaving_stmt(Having_stmtContext ctx) {
				// we work on level 0
				if (currentSelectLevel.value0 > 0)
					return;

				int start = ctx.getStart().getStartIndex() - 1;
				int stop = ctx.getStop().getStopIndex() + 1;

				if (start == stop)
					return;

				String statement = jql.substring(start, stop);

				String value = listener.onHaving(statement);

				if (value != null) {
					replace.add(new Triple<Token, Token, String>(ctx.start, ctx.stop, value));
				}
			}

			@Override
			public void enterOffset_stmt(Offset_stmtContext ctx) {
				// we work on level 0
				if (currentSelectLevel.value0 > 0)
					return;

				int start = ctx.getStart().getStartIndex() - 1;
				int stop = ctx.getStop().getStopIndex() + 1;

				if (start == stop)
					return;

				String statement = jql.substring(start, stop);

				String value = listener.onOffset(statement);

				if (value != null) {
					replace.add(new Triple<Token, Token, String>(ctx.start, ctx.stop, value));
				}
			}

			@Override
			public void enterLimit_stmt(Limit_stmtContext ctx) {
				// we work on level 0
				if (currentSelectLevel.value0 > 0)
					return;

				int start = ctx.getStart().getStartIndex() - 1;
				int stop = ctx.getStop().getStopIndex() + 1;

				if (start == stop)
					return;

				String statement = jql.substring(start, stop);

				String value = listener.onLimit(statement);

				if (value != null) {
					replace.add(new Triple<Token, Token, String>(ctx.start, ctx.stop, value));
				}
			}

			@Override
			public void enterColumn_name_set(Column_name_setContext ctx) {
				// we work on level 0
				if (currentSelectLevel.value0 > 0)
					return;

				int start = ctx.getStart().getStartIndex() - 1;
				int stop = ctx.getStop().getStopIndex() + 2;

				if (start == stop)
					return;

				String statement = jql.substring(start, stop);

				String value = listener.onColumnNameSet(statement);

				if (value != null) {
					replace.add(new Triple<Token, Token, String>(ctx.start, ctx.stop, value));
				}
			}

			@Override
			public void enterColumn_value_set(Column_value_setContext ctx) {
				// we work on level 0
				if (currentSelectLevel.value0 > 0)
					return;

				int start = ctx.getStart().getStartIndex() - 1;
				int stop = ctx.getStop().getStopIndex() + 2;

				if (start == stop)
					return;

				String statement = jql.substring(start, stop);

				String value = listener.onColumnValueSet(statement);

				if (value != null) {
					replace.add(new Triple<Token, Token, String>(ctx.start, ctx.stop, value));
				}
			}

		};

		return replaceInternal(jqlContext, jql, replace, rewriterListener);
	}
180633
private List<String> normalize(String sql) {

        String normSql = sql.replaceAll(";", "; ");
        normSql = normSql.replaceAll("\\s+", " ");
        return Arrays.stream(normSql.split(";")).map(s -> s.trim()).collect(Collectors.toList());
    }
1263089
public <E extends Object> int executeSQL(String sql, List<E> params) {
        if (params == null || params.size() == 0) {
            return jdbcTemplate.update(sql);
        } else {
            return jdbcTemplate.update(sql, params.toArray(new Object[params.size()]));
        }
    }
1252103
private static String sqlFilter(String sql) {
        sql = sql.replace(", WHERE", " WHERE").replace("AND  OR", "OR");
        if (sql.endsWith(Const.SPACE + Const.SQL_AND + Const.SPACE)) {
            sql = sql.substring(0, sql.length() - 5);
        }
        if (sql.endsWith(", ")) {
            sql = sql.substring(0, sql.length() - 2);
        }
        return sql;
    }
984606
public static String changeCatalog(String sql){
		CatalogContext catalogContext = catalogContextHolder.get();
		if(catalogContext != null && catalogContext.getCatalog() != null && catalogContext.getPlaceHolder() != null){
			sql = sql.replace(catalogContext.getPlaceHolder(), catalogContext.getCatalog());
		}
		logger.debug("real sql: "+sql);
		return sql;
	}
623397
function (expr, cb, joinCond) {
            expr = (isUndefined(expr) || isNull(expr) || (Array.isArray(expr) && !expr.length)) ? null : expr;
            if (expr && cb) {
                return new BooleanExpression(joinCond || "AND", this._filterExpr(expr, null, joinCond), this._filterExpr(cb, null, joinCond));
            } else if (cb) {
                expr = cb;
            }
            if (isInstanceOf(expr, Expression)) {
                if (isInstanceOf(expr, NumericExpression, StringExpression)) {
                    throw new QueryError("Invalid SQL Expression type : " + expr);
                }
                return expr;
            } else if (Array.isArray(expr)) {
                if (expr.length) {
                    var first = expr[0];
                    if (isString(first)) {
                        return new PlaceHolderLiteralString(first, expr.slice(1), true);
                    } else if (Expression.isConditionSpecifier(expr)) {
                        return BooleanExpression.fromValuePairs(expr, joinCond);
                    } else {
                        return BooleanExpression.fromArgs([joinCond || "AND"].concat(expr.map(function (e) {
                            return this._filterExpr(e, null, "AND");
                        }, this)));
                    }
                }
            } else if (isFunction(expr)) {
                return this._filterExpr(expr.call(sql, sql), null, joinCond);
            } else if (isBoolean(expr)) {
                return new BooleanExpression("NOOP", expr);
            } else if (isString(expr)) {
                return this.stringToIdentifier(expr);
            } else if (isInstanceOf(expr, LiteralString)) {
                return new LiteralString("(" + expr + ")");
            } else if (isHash(expr)) {
                return BooleanExpression.fromValuePairs(expr, joinCond);
            } else {
                throw new QueryError("Invalid filter argument");
            }
        }
397255
public static String getPreparedSql(String patternSql) {
        Matcher matcher = PATTERN.matcher(patternSql);
        StringBuilder preparedSql = new StringBuilder();
        int i = 0;
        int start = 0;
        while (matcher.find()) {
            i++;
            preparedSql.append(patternSql.substring(start, matcher.start())).append(" $").append(i).append(" ");
            start = matcher.end();
        }
        if (preparedSql.length() == 0) {
            // no pattern elements in the pattern sql, return the pattern sql directly as prepared sql.
            return patternSql;
        }
        return preparedSql.toString();
    }
975715
@Override
	public String sqlRegex(String columnname, String pattern, boolean caseinSensitive, boolean multiLine, boolean dotAllMode) {

        if(quotes.matcher(pattern).matches() ) {
            pattern = pattern.substring(1, pattern.length() - 1); // remove the
            // enclosing
            // quotes
        }
		//An ARE can begin with embedded options: a sequence (?n)  specifies options affecting the rest of the RE. 
		//n is newline-sensitive matching
		String flags = "";
		if (multiLine)
			flags = "(?w)"; //inverse partial newline-sensitive matching
		else
		if(dotAllMode)
			flags = "(?p)"; //partial newline-sensitive matching
		
		return columnname + " ~" + ((caseinSensitive)? "* " : " ") + "'"+ ((multiLine && dotAllMode)? "(?n)" : flags) + pattern + "'";
	}
5818
public static Set<String> getSqlParams(final String sql) {
		SqlParser parser = new SqlParserImpl(sql);
		ContextTransformer transformer = parser.parse();
		Node rootNode = transformer.getRoot();

		Set<String> params = new LinkedHashSet<>();
		traverseNode(rootNode, params);
		params.removeIf(s -> CONSTANT_PAT.matcher(s).matches());
		return params;
	}
775156
private StringBuffer toQueryPrefixNoSelect(String t) {

        StringBuffer sb = new StringBuffer(255);

        return sb.append(t).append(whereTrue);
    }
850810
private SelectSubqueryExpression parseSubqueryExpression(VoltXMLElement exprNode) {
        assert(exprNode.children.size() == 1);
        VoltXMLElement subqueryElmt = exprNode.children.get(0);
        AbstractParsedStmt subqueryStmt = parseSubquery(subqueryElmt);
        // add table to the query cache
        String withoutAlias = null;
        StmtSubqueryScan stmtSubqueryScan =
                addSubqueryToStmtCache(subqueryStmt, withoutAlias);
        // Set to the default SELECT_SUBQUERY. May be overridden depending on the context
        return new SelectSubqueryExpression(ExpressionType.SELECT_SUBQUERY, stmtSubqueryScan);
    }
151610
@Override
	public String sqlRegex(String columnname, String pattern, boolean caseinSensitive, boolean multiLine, boolean dotAllMode) {
        Pattern quotes = Pattern.compile("[\"`\\['].*[\"`\\]']");
		if(quotes.matcher(pattern).matches() ) {
		pattern = pattern.substring(1, pattern.length() - 1); // remove the
		// enclosing
		// quotes
        }
		String sql = columnname + " REGEXP ";
		if (!caseinSensitive) 
			sql += "BINARY ";
			
		return sql + "'" + pattern + "'";
	}
590276
public static String formatSQL(String sql) {
		if (sql == null || sql.length() == 0)
			return sql;
		StringBuilder sb = new StringBuilder();
		char[] chars = sql.toCharArray();
		boolean addedSpace = false;
		for (char c : chars) {
			if (isInvisibleChar(c)) {
				if (!addedSpace) {
					sb.append(" ");
					addedSpace = true;
				}
			} else {
				sb.append(c);
				addedSpace = false;
			}
		}
		sb.append(" ");
		return sb.toString();
	}
1168801
public ExecuteSQLQueryBuilder validate(String column, String ... values) {
		action.getControlResultSet().put(column, Arrays.asList(values));
		return this;
	}