Search in sources :

Example 1 with SQLInListExpr

use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project Mycat_plus by coderczp.

the class InSubQueryResultHandler method dohandler.

@Override
public String dohandler(SQLStatement statement, SQLSelect sqlselect, SQLObject parent, List param) {
    SQLExprImpl inlistExpr = null;
    if (null == param || param.isEmpty()) {
        inlistExpr = new SQLNullExpr();
    } else {
        inlistExpr = new SQLInListExpr();
        ((SQLInListExpr) inlistExpr).setTargetList(param);
        ((SQLInListExpr) inlistExpr).setExpr(((SQLInSubQueryExpr) parent).getExpr());
        ((SQLInListExpr) inlistExpr).setNot(((SQLInSubQueryExpr) parent).isNot());
        ((SQLInListExpr) inlistExpr).setParent(sqlselect.getParent());
    }
    if (parent.getParent() instanceof MySqlSelectQueryBlock) {
        ((MySqlSelectQueryBlock) parent.getParent()).setWhere(inlistExpr);
    } else if (parent.getParent() instanceof SQLBinaryOpExpr) {
        SQLBinaryOpExpr pp = ((SQLBinaryOpExpr) parent.getParent());
        if (pp.getLeft().equals(parent)) {
            pp.setLeft(inlistExpr);
        } else if (pp.getRight().equals(parent)) {
            pp.setRight(inlistExpr);
        }
    }
    return statement.toString();
}
Also used : SQLInListExpr(com.alibaba.druid.sql.ast.expr.SQLInListExpr) SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) SQLExprImpl(com.alibaba.druid.sql.ast.SQLExprImpl) SQLNullExpr(com.alibaba.druid.sql.ast.expr.SQLNullExpr) MySqlSelectQueryBlock(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)

Example 2 with SQLInListExpr

use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project Mycat_plus by coderczp.

the class BinaryOpResultHandler method dohandler.

@Override
public String dohandler(SQLStatement statement, SQLSelect sqlselect, SQLObject parent, List param) {
    SQLBinaryOpExpr pp = (SQLBinaryOpExpr) parent;
    if (pp.getLeft() instanceof SQLQueryExpr) {
        SQLQueryExpr left = (SQLQueryExpr) pp.getLeft();
        if (left.getSubQuery().equals(sqlselect)) {
            SQLExprImpl listExpr = null;
            if (null == param || param.isEmpty()) {
                listExpr = new SQLNullExpr();
            } else {
                listExpr = new SQLListExpr();
                listExpr.setParent(left.getParent());
                ((SQLListExpr) listExpr).getItems().addAll(param);
            }
            pp.setLeft(listExpr);
        }
    } else if (pp.getRight() instanceof SQLQueryExpr) {
        SQLQueryExpr right = (SQLQueryExpr) pp.getRight();
        if (right.getSubQuery().equals(sqlselect)) {
            SQLExprImpl listExpr = null;
            if (null == param || param.isEmpty()) {
                listExpr = new SQLNullExpr();
            } else {
                listExpr = new SQLListExpr();
                listExpr.setParent(right.getParent());
                ((SQLListExpr) listExpr).getItems().addAll(param);
            }
            pp.setRight(listExpr);
        }
    } else if (pp.getLeft() instanceof SQLInSubQueryExpr) {
        SQLInSubQueryExpr left = (SQLInSubQueryExpr) pp.getLeft();
        if (left.getSubQuery().equals(sqlselect)) {
            SQLExprImpl inlistExpr = null;
            if (null == param || param.isEmpty()) {
                inlistExpr = new SQLNullExpr();
            } else {
                inlistExpr = new SQLInListExpr();
                ((SQLInListExpr) inlistExpr).setTargetList(param);
                ((SQLInListExpr) inlistExpr).setExpr(pp.getRight());
                ((SQLInListExpr) inlistExpr).setNot(left.isNot());
                ((SQLInListExpr) inlistExpr).setParent(left.getParent());
            }
            pp.setLeft(inlistExpr);
        }
    } else if (pp.getRight() instanceof SQLInSubQueryExpr) {
        SQLInSubQueryExpr right = (SQLInSubQueryExpr) pp.getRight();
        if (right.getSubQuery().equals(sqlselect)) {
            SQLExprImpl listExpr = null;
            if (null == param || param.isEmpty()) {
                listExpr = new SQLNullExpr();
            } else {
                listExpr = new SQLListExpr();
                ((SQLListExpr) listExpr).getItems().addAll(param);
            }
            pp.setRight(listExpr);
        }
    }
    return statement.toString();
}
Also used : SQLInListExpr(com.alibaba.druid.sql.ast.expr.SQLInListExpr) SQLQueryExpr(com.alibaba.druid.sql.ast.expr.SQLQueryExpr) SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) SQLExprImpl(com.alibaba.druid.sql.ast.SQLExprImpl) SQLNullExpr(com.alibaba.druid.sql.ast.expr.SQLNullExpr) SQLListExpr(com.alibaba.druid.sql.ast.expr.SQLListExpr) SQLInSubQueryExpr(com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr)

Example 3 with SQLInListExpr

use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project dble by actiontech.

the class ItemFuncIn method toExpression.

@Override
public SQLExpr toExpression() {
    SQLInListExpr in = new SQLInListExpr(args.get(0).toExpression(), this.negated);
    List<SQLExpr> targetList = new ArrayList<>();
    int index = 0;
    for (Item item : args) {
        if (index != 0) {
            targetList.add(item.toExpression());
        }
        index++;
    }
    in.setTargetList(targetList);
    return in;
}
Also used : SQLInListExpr(com.alibaba.druid.sql.ast.expr.SQLInListExpr) Item(com.actiontech.dble.plan.common.item.Item) ArrayList(java.util.ArrayList) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 4 with SQLInListExpr

use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project Mycat-Server by MyCATApache.

the class JoinParser method parserWhere.

private void parserWhere(SQLExpr aexpr, String Operator) {
    if (aexpr == null) {
        return;
    }
    if (aexpr instanceof SQLBinaryOpExpr) {
        SQLBinaryOpExpr expr = (SQLBinaryOpExpr) aexpr;
        SQLExpr exprL = expr.getLeft();
        if (!(exprL instanceof SQLBinaryOpExpr)) {
            opSQLExpr((SQLBinaryOpExpr) aexpr, Operator);
        } else {
            // if (expr.getOperator().getName().equals("AND")) {
            if (expr.getOperator() == SQLBinaryOperator.BooleanAnd) {
                // parserWhere(exprL);
                // parserWhere(expr.getRight());
                andorWhere(exprL, expr.getOperator().getName(), expr.getRight());
            } else if (expr.getOperator() == SQLBinaryOperator.BooleanOr) {
                // .getName().equals("OR")) {
                andorWhere(exprL, expr.getOperator().getName(), expr.getRight());
            } else {
                throw new RuntimeException("Can't identify the operation of  of where");
            }
        }
    } else if (aexpr instanceof SQLInListExpr) {
        SQLInListExpr expr = (SQLInListExpr) aexpr;
        SQLExpr exprL = expr.getExpr();
        String field = exprL.toString();
        tableFilter.addWhere(field, SQLUtils.toMySqlString(expr), Operator);
    }
}
Also used : SQLInListExpr(com.alibaba.druid.sql.ast.expr.SQLInListExpr) SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 5 with SQLInListExpr

use of com.alibaba.druid.sql.ast.expr.SQLInListExpr in project Mycat-Server by MyCATApache.

the class BinaryOpResultHandler method dohandler.

@Override
public String dohandler(SQLStatement statement, SQLSelect sqlselect, SQLObject parent, List param) {
    SQLBinaryOpExpr pp = (SQLBinaryOpExpr) parent;
    if (pp.getLeft() instanceof SQLQueryExpr) {
        SQLQueryExpr left = (SQLQueryExpr) pp.getLeft();
        if (left.getSubQuery().equals(sqlselect)) {
            SQLExprImpl listExpr = null;
            if (null == param || param.isEmpty()) {
                listExpr = new SQLNullExpr();
            } else {
                listExpr = new SQLListExpr();
                listExpr.setParent(left.getParent());
                ((SQLListExpr) listExpr).getItems().addAll(param);
            }
            pp.setLeft(listExpr);
        }
    } else if (pp.getRight() instanceof SQLQueryExpr) {
        SQLQueryExpr right = (SQLQueryExpr) pp.getRight();
        if (right.getSubQuery().equals(sqlselect)) {
            SQLExprImpl listExpr = null;
            if (null == param || param.isEmpty()) {
                listExpr = new SQLNullExpr();
            } else {
                listExpr = new SQLListExpr();
                listExpr.setParent(right.getParent());
                ((SQLListExpr) listExpr).getItems().addAll(param);
            }
            pp.setRight(listExpr);
        }
    } else if (pp.getLeft() instanceof SQLInSubQueryExpr) {
        SQLInSubQueryExpr left = (SQLInSubQueryExpr) pp.getLeft();
        if (left.getSubQuery().equals(sqlselect)) {
            SQLExprImpl inlistExpr = null;
            if (null == param || param.isEmpty()) {
                inlistExpr = new SQLNullExpr();
            } else {
                inlistExpr = new SQLInListExpr();
                ((SQLInListExpr) inlistExpr).setTargetList(param);
                ((SQLInListExpr) inlistExpr).setExpr(pp.getRight());
                ((SQLInListExpr) inlistExpr).setNot(left.isNot());
                ((SQLInListExpr) inlistExpr).setParent(left.getParent());
            }
            pp.setLeft(inlistExpr);
        }
    } else if (pp.getRight() instanceof SQLInSubQueryExpr) {
        SQLInSubQueryExpr right = (SQLInSubQueryExpr) pp.getRight();
        if (right.getSubQuery().equals(sqlselect)) {
            SQLExprImpl listExpr = null;
            if (null == param || param.isEmpty()) {
                listExpr = new SQLNullExpr();
            } else {
                listExpr = new SQLListExpr();
                ((SQLListExpr) listExpr).getItems().addAll(param);
            }
            pp.setRight(listExpr);
        }
    }
    return statement.toString();
}
Also used : SQLInListExpr(com.alibaba.druid.sql.ast.expr.SQLInListExpr) SQLQueryExpr(com.alibaba.druid.sql.ast.expr.SQLQueryExpr) SQLBinaryOpExpr(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr) SQLExprImpl(com.alibaba.druid.sql.ast.SQLExprImpl) SQLNullExpr(com.alibaba.druid.sql.ast.expr.SQLNullExpr) SQLListExpr(com.alibaba.druid.sql.ast.expr.SQLListExpr) SQLInSubQueryExpr(com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr)

Aggregations

SQLInListExpr (com.alibaba.druid.sql.ast.expr.SQLInListExpr)11 SQLBinaryOpExpr (com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr)7 SQLExprImpl (com.alibaba.druid.sql.ast.SQLExprImpl)4 SQLNullExpr (com.alibaba.druid.sql.ast.expr.SQLNullExpr)4 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)3 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)2 SQLInSubQueryExpr (com.alibaba.druid.sql.ast.expr.SQLInSubQueryExpr)2 SQLListExpr (com.alibaba.druid.sql.ast.expr.SQLListExpr)2 SQLQueryExpr (com.alibaba.druid.sql.ast.expr.SQLQueryExpr)2 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)2 Item (com.actiontech.dble.plan.common.item.Item)1 SQLOver (com.alibaba.druid.sql.ast.SQLOver)1 SQLAllExpr (com.alibaba.druid.sql.ast.expr.SQLAllExpr)1 SQLAnyExpr (com.alibaba.druid.sql.ast.expr.SQLAnyExpr)1 SQLCurrentOfCursorExpr (com.alibaba.druid.sql.ast.expr.SQLCurrentOfCursorExpr)1 SQLDefaultExpr (com.alibaba.druid.sql.ast.expr.SQLDefaultExpr)1 SQLMethodInvokeExpr (com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr)1 SQLSomeExpr (com.alibaba.druid.sql.ast.expr.SQLSomeExpr)1 SQLAlterTableAlterColumn (com.alibaba.druid.sql.ast.statement.SQLAlterTableAlterColumn)1 SQLAlterTableDisableConstraint (com.alibaba.druid.sql.ast.statement.SQLAlterTableDisableConstraint)1