phoenix-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twdsilva <...@git.apache.org>
Subject [GitHub] phoenix pull request #417: PHOENIX-4820
Date Thu, 27 Dec 2018 00:50:45 GMT
Github user twdsilva commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/417#discussion_r244065522
  
    --- Diff: phoenix-core/src/main/java/org/apache/phoenix/util/ExpressionUtil.java ---
    @@ -68,4 +76,144 @@ public static boolean isPkPositionChanging(TableRef tableRef, List<Expression>
p
             return false;
         }
     
    +    /**
    +     * check the whereExpression to see if the columnExpression is constant.
    +     * eg. for "where a =3 and b > 9", a is constant,but b is not.
    +     * @param columnExpression
    +     * @param whereExpression
    +     * @return
    +     */
    +    public static boolean isColumnExpressionConstant(ColumnExpression columnExpression,
Expression whereExpression) {
    +        if(whereExpression == null) {
    +            return false;
    +        }
    +        IsColumnConstantExpressionVisitor isColumnConstantExpressionVisitor =
    +                new IsColumnConstantExpressionVisitor(columnExpression);
    +        whereExpression.accept(isColumnConstantExpressionVisitor);
    +        return isColumnConstantExpressionVisitor.isConstant();
    +    }
    +
    +    private static class IsColumnConstantExpressionVisitor extends StatelessTraverseNoExpressionVisitor<Void>
{
    +        private final Expression columnExpression ;
    +        private Expression firstRhsConstantExpression = null;
    +        private int rhsConstantCount = 0;
    +        private boolean isNullExpressionVisited = false;
    +
    +        public IsColumnConstantExpressionVisitor(Expression columnExpression) {
    +            this.columnExpression = columnExpression;
    +        }
    +        /**
    +         * only conside and,for "where a = 3 or b = 9", neither a or b is constant.
    +         */
    +        @Override
    +        public Iterator<Expression> visitEnter(AndExpression andExpression) {
    +            if(rhsConstantCount > 1) {
    +                return null;
    +            }
    +            return andExpression.getChildren().iterator();
    +        }
    +        /**
    +         * <pre>
    +         * We just conside {@link ComparisonExpression} because:
    --- End diff --
    
    nit: only consider


---

Mime
View raw message