com.alibaba.druid.sql.ast.expr.SQLBinaryOperator Java Examples
The following examples show how to use
com.alibaba.druid.sql.ast.expr.SQLBinaryOperator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MycatSchemaStatVisitor.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
/** * 递归拆分OR * * @param whereUnit * TODO:考虑嵌套or语句,条件中有子查询、 exists等很多种复杂情况是否能兼容 */ private void splitUntilNoOr(WhereUnit whereUnit) { if(whereUnit.isFinishedParse()) { if(whereUnit.getSubWhereUnit().size() > 0) { for(int i = 0; i < whereUnit.getSubWhereUnit().size(); i++) { splitUntilNoOr(whereUnit.getSubWhereUnit().get(i)); } } } else { SQLBinaryOpExpr expr = whereUnit.getCanSplitExpr(); if(expr.getOperator() == SQLBinaryOperator.BooleanOr) { // whereUnit.addSplitedExpr(expr.getRight()); addExprIfNotFalse(whereUnit, expr.getRight()); if(expr.getLeft() instanceof SQLBinaryOpExpr) { whereUnit.setCanSplitExpr((SQLBinaryOpExpr)expr.getLeft()); splitUntilNoOr(whereUnit); } else { addExprIfNotFalse(whereUnit, expr.getLeft()); } } else { addExprIfNotFalse(whereUnit, expr); whereUnit.setFinishedParse(true); } } }
Example #2
Source File: JoinParser.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
private void opSQLExpr(SQLBinaryOpExpr expr,String Operator) { if (expr==null) { return; } SQLExpr exprL=expr.getLeft(); if (!(exprL instanceof SQLBinaryOpExpr)) { String field=exprL.toString(); //获取表达式 左边的值 String value=getExpValue(expr.getRight()).toString(); //获取表达式右边的值 if (expr.getOperator()==SQLBinaryOperator.Equality) { if (checkJoinField(value)) {//设置joinKey //joinLkey=field; //joinRkey=value; tableFilter.setJoinKey(field,value); } else { tableFilter.addWhere(field, value, expr.getOperator().getName(), Operator); } } else { tableFilter.addWhere(field, value, expr.getOperator().getName(), Operator); } } }
Example #3
Source File: OrVisitor.java From baymax with Apache License 2.0 | 6 votes |
@Override public boolean visit(SQLBinaryOpExpr x) { x.getLeft().setParent(x); x.getRight().setParent(x); if (!SQLBinaryOperator.BooleanOr.equals(x.getOperator())) { return super.visit(x); } // true * (a and b) = (a and b) 没有意义 if (Boolean.TRUE.equals(WallVisitorUtils.getValue(x))) { return false; } // 这是一个Or表达式 这个or代表的集合是要和当前已经获取的Condition列表 相乘的. orEntity.add(new OrEntity(this, x)); return false; }
Example #4
Source File: WhereParser.java From elasticsearch-sql with Apache License 2.0 | 5 votes |
private boolean isAllowedMethodOnConditionLeft(SQLMethodInvokeExpr method, SQLBinaryOperator operator) { return (method.getMethodName().toLowerCase().equals("nested") || method.getMethodName().toLowerCase().equals("children") || SQLFunctions.buildInFunctions.contains(method.getMethodName().toLowerCase()) ) && !operator.isLogical(); }
Example #5
Source File: ShardRange.java From Zebra with Apache License 2.0 | 5 votes |
private static int convertOperator(SQLBinaryOperator operator) { if (operator == SQLBinaryOperator.GreaterThan) { return ShardRange.OP_Greater; } else if (operator == SQLBinaryOperator.GreaterThanOrEqual) { return ShardRange.OP_GreaterOrEqual; } else if (operator == SQLBinaryOperator.LessThan) { return ShardRange.OP_Less; } else if (operator == SQLBinaryOperator.LessThanOrEqual) { return ShardRange.OP_LessOrEqual; } else if (operator == SQLBinaryOperator.Equality) { return ShardRange.OP_Equal; } else { return ShardRange.OP_NONE; } }
Example #6
Source File: ItemAllAnySubQuery.java From dble with GNU General Public License v2.0 | 5 votes |
public ItemAllAnySubQuery(String currentDb, SQLSelectQuery query, SQLBinaryOperator operator, boolean isAll, ProxyMetaManager metaManager, Map<String, String> usrVariables) { super(currentDb, query, metaManager, usrVariables); this.isAll = isAll; this.operator = operator; if (this.planNode.getColumnsSelected().size() > 1) { throw new MySQLOutPutException(ErrorCode.ER_OPERAND_COLUMNS, "", "Operand should contain 1 column(s)"); } this.select = this.planNode.getColumnsSelected().get(0); }
Example #7
Source File: ExpressionUtil.java From dble with GNU General Public License v2.0 | 5 votes |
private static boolean isLogicalExpression(SQLExpr expr) { //XOR? if (!(expr instanceof SQLBinaryOpExpr)) { return false; } SQLBinaryOpExpr binOpExpr = (SQLBinaryOpExpr) expr; return binOpExpr.getOperator() == SQLBinaryOperator.BooleanAnd || binOpExpr.getOperator() == SQLBinaryOperator.BooleanOr; }
Example #8
Source File: DruidSelectParser.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
private HavingCols buildGroupByHaving(SQLExpr having,Map<String, String> aliaColumns ){ 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) + ")"; String aggrColumnAlias = getAliaColumn(aliaColumns,leftValue); if(aggrColumnAlias != null) { // having聚合函数存在别名 expr.setLeft(new SQLIdentifierExpr(aggrColumnAlias)); leftValue = aggrColumnAlias; } } 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()); }
Example #9
Source File: ExpressionUtil.java From dble with GNU General Public License v2.0 | 5 votes |
/** * allow (A and B) and C * * @param expr * @return */ public static boolean isDNF(SQLExpr expr) { if (!isLogicalExpression(expr)) { return true; } SQLBinaryOpExpr binOpExpr = (SQLBinaryOpExpr) expr; SQLExpr left = binOpExpr.getLeft(); SQLExpr right = binOpExpr.getRight(); if (binOpExpr.getOperator() == SQLBinaryOperator.BooleanAnd) { boolean isAllNonLogicExpr = true; if (left instanceof SQLBinaryOpExpr) { SQLBinaryOpExpr leftBinaryOp = (SQLBinaryOpExpr) left; if (leftBinaryOp.getOperator() == SQLBinaryOperator.BooleanOr) { return false; } if (isLogicalExpression(leftBinaryOp)) { isAllNonLogicExpr = false; } } if (right instanceof SQLBinaryOpExpr) { SQLBinaryOpExpr rightBinaryOp = (SQLBinaryOpExpr) right; if (rightBinaryOp.getOperator() == SQLBinaryOperator.BooleanOr) { return false; } if (isLogicalExpression(rightBinaryOp)) { isAllNonLogicExpr = false; } } if (isAllNonLogicExpr) { return true; } } if (!isDNF(left)) { return false; } return isDNF(right); }
Example #10
Source File: ExpressionUtil.java From dble with GNU General Public License v2.0 | 5 votes |
/** * (A OR B) AND C OR B OR (E OR F) AND G = ((A AND C ) OR (A AND B)) OR B OR * ((E AND G) OR (F AND G)) * * @param expr * @return */ private static SQLBinaryOpExpr expandOrExpression(SQLBinaryOpExpr expr) { SQLExpr left = expr.getLeft(); SQLExpr right = expr.getRight(); SQLExpr leftOp = toDNF(left); SQLExpr rightOp = toDNF(right); return new SQLBinaryOpExpr(leftOp, SQLBinaryOperator.BooleanOr, rightOp); }
Example #11
Source File: ExpressionUtil.java From dble with GNU General Public License v2.0 | 5 votes |
/** * convert Expression to DNF Expression * * @param expr * @return */ public static SQLExpr toDNF(SQLExpr expr) { if (expr == null) return null; while (!isDNF(expr)) { SQLBinaryOpExpr binOpExpr = (SQLBinaryOpExpr) expr; if (binOpExpr.getOperator() == SQLBinaryOperator.BooleanOr) { expr = expandOrExpression(binOpExpr); } else if (binOpExpr.getOperator() == SQLBinaryOperator.BooleanAnd) { expr = expandAndExpression(binOpExpr); } } return expr; }
Example #12
Source File: DruidSelectOracleParser.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
private void parseThreeLevelPageSql(SQLStatement stmt, RouteResultset rrs, SchemaConfig schema, SQLSubqueryTableSource from, SQLBinaryOpExpr one, SQLBinaryOperator operator) { SQLIntegerExpr right = (SQLIntegerExpr) one.getRight(); int firstrownum = right.getNumber().intValue(); if (operator == SQLBinaryOperator.GreaterThanOrEqual&&firstrownum!=0) { firstrownum = firstrownum - 1; } SQLSelectQuery subSelect = from.getSelect().getQuery(); if (subSelect instanceof OracleSelectQueryBlock) { //第二层子查询 OracleSelectQueryBlock twoSubSelect = (OracleSelectQueryBlock) subSelect; if (twoSubSelect.getWhere() instanceof SQLBinaryOpExpr && twoSubSelect.getFrom() instanceof SQLSubqueryTableSource) { SQLBinaryOpExpr twoWhere = (SQLBinaryOpExpr) twoSubSelect.getWhere(); boolean isRowNum = "rownum".equalsIgnoreCase(twoWhere.getLeft().toString()); boolean isLess = twoWhere.getOperator() == SQLBinaryOperator.LessThanOrEqual || twoWhere.getOperator() == SQLBinaryOperator.LessThan; if (isRowNum && twoWhere.getRight() instanceof SQLIntegerExpr && isLess) { int lastrownum = ((SQLIntegerExpr) twoWhere.getRight()).getNumber().intValue(); if (operator == SQLBinaryOperator.LessThan&&lastrownum!=0) { lastrownum = lastrownum - 1; } SQLSelectQuery finalQuery = ((SQLSubqueryTableSource) twoSubSelect.getFrom()).getSelect().getQuery(); if (finalQuery instanceof OracleSelectQueryBlock) { setLimitIFChange(stmt, rrs, schema, one, firstrownum, lastrownum); parseOrderAggGroupOracle(stmt,rrs, (OracleSelectQueryBlock) finalQuery, schema); isNeedParseOrderAgg=false; } } } } }
Example #13
Source File: ShardRange.java From Zebra with Apache License 2.0 | 4 votes |
public ShardRange(SQLBinaryOperator operator, Object firstParameter) { this.firstType = convertOperator(operator); this.firstParameter = firstParameter; }
Example #14
Source File: ItemAllAnySubQuery.java From dble with GNU General Public License v2.0 | 4 votes |
public SQLBinaryOperator getOperator() { return operator; }
Example #15
Source File: ItemFuncIntDiv.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { return new SQLBinaryOpExpr(args.get(0).toExpression(), SQLBinaryOperator.DIV, args.get(1).toExpression()); }
Example #16
Source File: ItemFuncPlus.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { return new SQLBinaryOpExpr(args.get(0).toExpression(), SQLBinaryOperator.Add, args.get(1).toExpression()); }
Example #17
Source File: ItemFuncMinus.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { return new SQLBinaryOpExpr(args.get(0).toExpression(), SQLBinaryOperator.Subtract, args.get(1).toExpression()); }
Example #18
Source File: ItemFuncMod.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { return new SQLBinaryOpExpr(args.get(0).toExpression(), SQLBinaryOperator.Mod, args.get(1).toExpression()); }
Example #19
Source File: ItemFuncMul.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { return new SQLBinaryOpExpr(args.get(0).toExpression(), SQLBinaryOperator.Multiply, args.get(1).toExpression()); }
Example #20
Source File: ItemFuncDiv.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { return new SQLBinaryOpExpr(args.get(0).toExpression(), SQLBinaryOperator.Divide, args.get(1).toExpression()); }
Example #21
Source File: ItemFuncRightShift.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { return new SQLBinaryOpExpr(args.get(0).toExpression(), SQLBinaryOperator.RightShift, args.get(1).toExpression()); }
Example #22
Source File: ItemFuncBitXor.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { return new SQLBinaryOpExpr(args.get(0).toExpression(), SQLBinaryOperator.BitwiseXor, args.get(1).toExpression()); }
Example #23
Source File: ItemFuncBitOr.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { return new SQLBinaryOpExpr(args.get(0).toExpression(), SQLBinaryOperator.BitwiseOr, args.get(1).toExpression()); }
Example #24
Source File: ItemFuncBitAnd.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { return new SQLBinaryOpExpr(args.get(0).toExpression(), SQLBinaryOperator.BitwiseAnd, args.get(1).toExpression()); }
Example #25
Source File: ItemFuncLeftShift.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { return new SQLBinaryOpExpr(args.get(0).toExpression(), SQLBinaryOperator.LeftShift, args.get(1).toExpression()); }
Example #26
Source File: ItemFuncXor.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { SQLExpr left = args.get(0).toExpression(); SQLExpr right = args.get(1).toExpression(); return new SQLBinaryOpExpr(left, SQLBinaryOperator.BooleanXor, right); }
Example #27
Source File: ItemFuncRegex.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { SQLExpr left = args.get(0).toExpression(); SQLExpr right = args.get(1).toExpression(); return new SQLBinaryOpExpr(left, SQLBinaryOperator.RegExp, right); }
Example #28
Source File: ItemFuncGe.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { SQLExpr left = args.get(0).toExpression(); SQLExpr right = args.get(1).toExpression(); return new SQLBinaryOpExpr(left, SQLBinaryOperator.GreaterThanOrEqual, right); }
Example #29
Source File: ItemFuncIsfalse.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { SQLExpr left = args.get(0).toExpression(); return new SQLBinaryOpExpr(left, SQLBinaryOperator.Is, new SQLBooleanExpr(false)); }
Example #30
Source File: ItemFuncEqual.java From dble with GNU General Public License v2.0 | 4 votes |
@Override public SQLExpr toExpression() { SQLExpr left = args.get(0).toExpression(); SQLExpr right = args.get(1).toExpression(); return new SQLBinaryOpExpr(left, SQLBinaryOperator.Equality, right); }