Skip to content

Commit

Permalink
[improvement][headless] fix derived metric case parse error (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
jipeli authored Jan 22, 2024
1 parent 7ec77c7 commit c12f5d2
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.ExpressionVisitorAdapter;
import net.sf.jsqlparser.expression.Function;
import net.sf.jsqlparser.expression.WhenClause;
import net.sf.jsqlparser.schema.Column;

public class ExpressionReplaceVisitor extends ExpressionVisitorAdapter {
Expand All @@ -19,6 +20,20 @@ public ExpressionReplaceVisitor(Map<String, String> fieldExprMap) {
this.fieldExprMap = fieldExprMap;
}

public void visit(WhenClause expr) {
expr.getWhenExpression().accept(this);
if (expr.getThenExpression() instanceof Column) {
Column column = (Column) expr.getThenExpression();
Expression expression = QueryExpressionReplaceVisitor.getExpression(
QueryExpressionReplaceVisitor.getReplaceExpr(column, fieldExprMap));
if (Objects.nonNull(expression)) {
expr.setThenExpression(expression);
}
} else {
expr.getThenExpression().accept(this);
}
}

protected void visitBinaryExpression(BinaryExpression expr) {
Expression left = expr.getLeftExpression();
Expression right = expr.getRightExpression();
Expand Down

0 comments on commit c12f5d2

Please sign in to comment.