当前位置: 首页>>代码示例>>Java>>正文


Java SQLBinaryOpExpr.getRight方法代码示例

本文整理汇总了Java中com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr.getRight方法的典型用法代码示例。如果您正苦于以下问题:Java SQLBinaryOpExpr.getRight方法的具体用法?Java SQLBinaryOpExpr.getRight怎么用?Java SQLBinaryOpExpr.getRight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr的用法示例。


在下文中一共展示了SQLBinaryOpExpr.getRight方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: explanSpecialCondWithBothSidesAreLiterals

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入方法依赖的package包/类
private boolean explanSpecialCondWithBothSidesAreLiterals(SQLBinaryOpExpr bExpr, Where where) throws SqlParseException {
    if ((bExpr.getLeft() instanceof SQLNumericLiteralExpr || bExpr.getLeft() instanceof SQLCharExpr) &&
            (bExpr.getRight() instanceof SQLNumericLiteralExpr || bExpr.getRight() instanceof SQLCharExpr)
            ) {
        SQLMethodInvokeExpr sqlMethodInvokeExpr = new SQLMethodInvokeExpr("script", null);
        String operator = bExpr.getOperator().getName();
        if (operator.equals("=")) {
            operator = "==";
        }
        sqlMethodInvokeExpr.addParameter(
                new SQLCharExpr(Util.expr2Object(bExpr.getLeft(), "'") +
                        " " + operator + " " +
                        Util.expr2Object(bExpr.getRight(), "'"))
        );

        explanCond("AND", sqlMethodInvokeExpr, where);
        return true;
    }
    return false;
}
 
开发者ID:NLPchina,项目名称:elasticsearch-sql,代码行数:21,代码来源:WhereParser.java

示例2: parseThreeLevelPageSql

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入方法依赖的package包/类
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;
                   }

               }

           }

       }
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:37,代码来源:DruidSelectOracleParser.java

示例3: tryParseFromMethodExpr

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入方法依赖的package包/类
public boolean tryParseFromMethodExpr(SQLMethodInvokeExpr expr) throws SqlParseException {
    if (!expr.getMethodName().toLowerCase().equals("script")) {
        return false;
    }
    List<SQLExpr> methodParameters = expr.getParameters();
    if (methodParameters.size() == 0) {
        return false;
    }
    script = Util.extendedToString(methodParameters.get(0));

    if (methodParameters.size() == 1) {
        return true;
    }

    args = new HashMap<>();
    for (int i = 1; i < methodParameters.size(); i++) {

        SQLExpr innerExpr = methodParameters.get(i);
        if (!(innerExpr instanceof SQLBinaryOpExpr)) {
            return false;
        }
        SQLBinaryOpExpr binaryOpExpr = (SQLBinaryOpExpr) innerExpr;
        if (!binaryOpExpr.getOperator().getName().equals("=")) {
            return false;
        }

        SQLExpr right = binaryOpExpr.getRight();
        Object value = Util.expr2Object(right);
        String key = Util.extendedToString(binaryOpExpr.getLeft());
        if(key.equals("script_type")){
            parseAndUpdateScriptType(value.toString());
        }
        else {
            args.put(key, value);
        }

    }
    return true;
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:40,代码来源:ScriptFilter.java

示例4: expandOrExpression

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入方法依赖的package包/类
/**
 * (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);
}
 
开发者ID:actiontech,项目名称:dble,代码行数:15,代码来源:ExpressionUtil.java

示例5: isDNF

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:actiontech,项目名称:dble,代码行数:44,代码来源:ExpressionUtil.java

示例6: explanSpecialCondWithBothSidesAreProperty

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入方法依赖的package包/类
private boolean explanSpecialCondWithBothSidesAreProperty(SQLBinaryOpExpr bExpr, Where where) throws SqlParseException {
    //join is not support
    if ((bExpr.getLeft() instanceof SQLPropertyExpr || bExpr.getLeft() instanceof SQLIdentifierExpr) &&
            (bExpr.getRight() instanceof SQLPropertyExpr || bExpr.getRight() instanceof SQLIdentifierExpr) &&
            Sets.newHashSet("=", "<", ">", ">=", "<=").contains(bExpr.getOperator().getName()) &&
            !Util.isFromJoinOrUnionTable(bExpr)

            ) {
        SQLMethodInvokeExpr sqlMethodInvokeExpr = new SQLMethodInvokeExpr("script", null);
        String operator = bExpr.getOperator().getName();
        if (operator.equals("=")) {
            operator = "==";
        }

        String leftProperty = Util.expr2Object(bExpr.getLeft()).toString();
        String rightProperty = Util.expr2Object(bExpr.getRight()).toString();
        if (leftProperty.split("\\.").length > 1) {

            leftProperty = leftProperty.substring(leftProperty.split("\\.")[0].length() + 1);
        }

        if (rightProperty.split("\\.").length > 1) {
            rightProperty = rightProperty.substring(rightProperty.split("\\.")[0].length() + 1);
        }

        sqlMethodInvokeExpr.addParameter(new SQLCharExpr(
                "doc['" + leftProperty + "'].value " +
                        operator +
                        " doc['" + rightProperty + "'].value"));


        explanCond("AND", sqlMethodInvokeExpr, where);
        return true;
    }
    return false;
}
 
开发者ID:NLPchina,项目名称:elasticsearch-sql,代码行数:37,代码来源:WhereParser.java

示例7: main

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入方法依赖的package包/类
public static void main(String[] args) {
        String sql = " select * from event where eventId = 0001 and eventKey = key and eventName between begin and end";
        String insert = " insert into uservalues(id,ooo)";
        //使用mysql解析
        MySqlStatementParser sqlStatementParser = new MySqlStatementParser(sql) ;
        //解析select查询
//        System.out.println("parse select "+sqlStatementParser.parseStatement());
        SQLSelectStatement sqlStatement = (SQLSelectStatement) sqlStatementParser.parseStatement();
        SQLSelect sqlSelect = sqlStatement.getSelect() ;
        //获取sql查询块
        SQLSelectQueryBlock sqlSelectQuery = (SQLSelectQueryBlock)sqlSelect.getQuery() ;
        StringBuffer out = new StringBuffer() ;
//        //创建sql解析的标准化输出
//        SQLASTOutputVisitor sqlastOutputVisitor = SQLUtils.createFormatOutputVisitor(out , SQLUtils.parseStatements(sql, JdbcUtils.MYSQL) , JdbcUtils.MYSQL) ;
        SQLBinaryOpExpr expr = (SQLBinaryOpExpr)sqlSelectQuery.getWhere();
        System.out.println("expr:"+expr.getClass().getName());
//        sqlastOutputVisitor.visit(expr);
        SQLBetweenExpr betweenExpr = (SQLBetweenExpr) expr.getRight();
        System.out.println(betweenExpr.getBeginExpr().toString());
//        SQLIdentifierExpr sqlIdentifierExpr = (SQLIdentifierExpr) exprRight.getLeft();
//        sqlIdentifierExpr.accept(sqlastOutputVisitor);
//        List<Object> params = sqlVariantRefExpr.getName();
//        System.out.println(sqlIdentifierExpr.getName());
        int index = 0;
//        for (TableStat.Column column:sqlastOutputVisitor.getgetColumns()){
//            System.out.println(column.getName()+":"+params.get(index));
//            index++;
//        }
//
//        //解析select项
//        out.delete(0, out.length()) ;
//        for (SQLSelectItem sqlSelectItem : sqlSelectQuery.getSelectList()) {
//            if(out.length()>1){
//                out.append(",") ;
//            }
//            sqlSelectItem.accept(sqlastOutputVisitor);
//        }
//        System.out.println("SELECT "+out) ;
//
//        //解析from
//        out.delete(0, out.length()) ;
//        sqlSelectQuery.getFrom().accept(sqlastOutputVisitor) ;
//        System.out.println("FROM "+out) ;
//
//        //解析where
//        out.delete(0, out.length()) ;
//        sqlSelectQuery.getWhere().accept(sqlastOutputVisitor) ;
//        System.out.println("WHERE "+out);

    }
 
开发者ID:rpgmakervx,项目名称:slardar,代码行数:51,代码来源:SqlParserTest.java

示例8: rearrangement

import com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr; //导入方法依赖的package包/类
/**
 * a inner_join (b inner_join c) -&lt; a inner_join b innre_join c
 */
public void rearrangement() {
    if (joinType != JoinType.COMMA && joinType != JoinType.INNER_JOIN) {
        return;
    }
    if (right instanceof SQLJoinTableSource) {
        SQLJoinTableSource rightJoin = (SQLJoinTableSource) right;

        if (rightJoin.joinType != JoinType.COMMA && rightJoin.joinType != JoinType.INNER_JOIN) {
            return;
        }

        SQLTableSource a = left;
        SQLTableSource b = rightJoin.getLeft();
        SQLTableSource c = rightJoin.getRight();
        SQLExpr on_ab = condition;
        SQLExpr on_bc = rightJoin.condition;

        setLeft(rightJoin);
        rightJoin.setLeft(a);
        rightJoin.setRight(b);


        boolean on_ab_match = false;
        if (on_ab instanceof SQLBinaryOpExpr) {
            SQLBinaryOpExpr on_ab_binaryOpExpr = (SQLBinaryOpExpr) on_ab;
            if (on_ab_binaryOpExpr.getLeft() instanceof SQLPropertyExpr
                    && on_ab_binaryOpExpr.getRight() instanceof SQLPropertyExpr) {
                String leftOwnerName = ((SQLPropertyExpr) on_ab_binaryOpExpr.getLeft()).getOwnernName();
                String rightOwnerName = ((SQLPropertyExpr) on_ab_binaryOpExpr.getRight()).getOwnernName();

                if (rightJoin.containsAlias(leftOwnerName) && rightJoin.containsAlias(rightOwnerName)) {
                    on_ab_match = true;
                }
            }
        }

        if (on_ab_match) {
            rightJoin.setCondition(on_ab);
        } else {
            rightJoin.setCondition(null);
            on_bc = SQLBinaryOpExpr.and(on_bc, on_ab);
        }

        setRight(c);
        setCondition(on_bc);
    }
}
 
开发者ID:zuonima,项目名称:sql-utils,代码行数:51,代码来源:SQLJoinTableSource.java


注:本文中的com.alibaba.druid.sql.ast.expr.SQLBinaryOpExpr.getRight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。