Search in sources :

Example 1 with HavingCols

use of io.mycat.sqlengine.mpp.HavingCols in project Mycat-Server by MyCATApache.

the class DruidSelectParser method buildGroupByHaving.

private HavingCols buildGroupByHaving(SQLExpr having) {
    if (having == null) {
        return null;
    }
    SQLBinaryOpExpr expr = ((SQLBinaryOpExpr) having);
    SQLExpr left = expr.getLeft();
    SQLBinaryOperator operator = expr.getOperator();
    SQLExpr right = expr.getRight();
    String leftValue = null;
    ;
    if (left instanceof SQLAggregateExpr) {
        leftValue = ((SQLAggregateExpr) left).getMethodName() + "(" + ((SQLAggregateExpr) left).getArguments().get(0) + ")";
    } else if (left instanceof SQLIdentifierExpr) {
        leftValue = ((SQLIdentifierExpr) left).getName();
    }
    String rightValue = null;
    if (right instanceof SQLNumericLiteralExpr) {
        rightValue = right.toString();
    } else if (right instanceof SQLTextLiteralExpr) {
        rightValue = StringUtil.removeBackquote(right.toString());
    }
    return new HavingCols(leftValue, rightValue, operator.getName());
}
Also used : HavingCols(io.mycat.sqlengine.mpp.HavingCols) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Aggregations

SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 HavingCols (io.mycat.sqlengine.mpp.HavingCols)1