Github user jihoonson commented on a diff in the pull request:

    https://github.com/apache/tajo/pull/772#discussion_r39946230
  
    --- Diff: 
tajo-plan/src/main/java/org/apache/tajo/plan/expr/AlgebraicUtil.java ---
    @@ -493,4 +497,190 @@ public Object visitTimeLiteral(Object ctx, 
Stack<Expr> stack, TimeLiteral expr)
           return super.visitTimeLiteral(ctx, stack, expr);
         }
       }
    +
    +  /**
    +   * Find the top expr matched to type from the given expr
    +   *
    +   * @param expr start expr
    +   * @param type to find
    +   * @return a found expr
    +   */
    +  public static <T extends Expr> T findTopExpr(Expr expr, OpType type) 
throws TajoException {
    +    Preconditions.checkNotNull(expr);
    +    Preconditions.checkNotNull(type);
    +
    +    ExprFinder finder = new ExprFinder(type);
    +    finder.visit(null, new Stack<Expr>(), expr);
    +
    +    if (finder.getFoundExprs().size() == 0) {
    +      return null;
    +    }
    +    return (T) finder.getFoundExprs().get(0);
    +  }
    +
    +  private static class ExprFinder extends SimpleAlgebraVisitor<Object, 
Expr> {
    +    private List<Expr> list = new ArrayList<Expr>();
    +    private final OpType[] tofind;
    +    private boolean topmost = false;
    +    private boolean finished = false;
    +
    +    public ExprFinder(OpType... type) {
    +
    +      this.tofind = type;
    +    }
    +
    +    public ExprFinder(OpType[] type, boolean topmost) {
    +      this(type);
    +      this.topmost = topmost;
    +    }
    +
    +    @Override
    +    public Expr visit(Object ctx, Stack<Expr> stack, Expr expr) throws 
TajoException {
    +      if (!finished) {
    +        for (OpType type : tofind) {
    +          if (expr.getType() == type) {
    +            list.add(expr);
    +          }
    +          if (topmost && list.size() > 0) {
    +            finished = true;
    +          }
    +        }
    +      }
    +      return super.visit(ctx, stack, expr);
    +    }
    +
    +    public List<Expr> getFoundExprs() {
    +      return list;
    +    }
    +
    +  }
    +
    +  public static Expr[] toConjunctiveNormalFormArray(Expr expr) {
    +    List<Expr> list = new ArrayList<Expr>();
    +    toConjunctiveNormalFormArrayRecursive(expr, list);
    +    return list.toArray(new Expr[list.size()]);
    +  }
    +
    +  private static void toConjunctiveNormalFormArrayRecursive(Expr node, 
List<Expr> found) {
    +    if (node.getType() == OpType.And) {
    +      toConjunctiveNormalFormArrayRecursive(((BinaryOperator) 
node).getLeft(), found);
    +      toConjunctiveNormalFormArrayRecursive(((BinaryOperator) 
node).getRight(), found);
    +    } else {
    +      found.add(node);
    +    }
    +  }
    +
    +  /**
    +   * It finds unique columns from a Expr.
    +   */
    +  public static LinkedHashSet<ColumnReferenceExpr> 
findUniqueColumnReferences(Expr expr) throws TajoException {
    +    UniqueColumnReferenceFinder finder = new UniqueColumnReferenceFinder();
    +    finder.visit(null, new Stack<Expr>(), expr);
    +    return finder.getColumnRefs();
    +  }
    +
    +  private static class UniqueColumnReferenceFinder extends 
SimpleAlgebraVisitor<Object, Expr> {
    +    private LinkedHashSet<ColumnReferenceExpr> columnSet = 
Sets.newLinkedHashSet();
    +    private ColumnReferenceExpr field = null;
    +
    +    @Override
    +    public Expr visit(Object ctx, Stack<Expr> stack, Expr expr) throws 
TajoException {
    +      if (expr.getType() == OpType.Column) {
    +        field = (ColumnReferenceExpr) expr;
    +        columnSet.add(field);
    +      }
    +      return super.visit(ctx, stack, expr);
    +    }
    +
    +    public LinkedHashSet<ColumnReferenceExpr> getColumnRefs() {
    +      return this.columnSet;
    +    }
    +
    +  }
    +
    +  /**
    +   * Build Exprs for all columns with a list of filter conditions.
    +   *
    +   * For example, consider you have a partitioned table for three columns 
(i.e., col1, col2, col3).
    +   * Then, this methods will create three Exprs for (col1), (col2), (col3).
    +   *
    +   * Assume that an user gives a condition WHERE col1 ='A' and col3 = 'C'.
    +   * There is no filter condition corresponding to col2.
    +   * Then, the path filter conditions are corresponding to the followings:
    +   *
    +   * The first Expr: col1 = 'A'
    +   * The second Expr: col2 IS NOT NULL
    +   * The third Expr: col3 = 'C'
    +   *
    +   * 'IS NOT NULL' predicate is always true against the partition path.
    +   *
    +   *
    +   * @param partitionColumns
    +   * @param conjunctiveForms
    +   * @return
    +   */
    +  public static Expr[] getAccumulatedFiltersByExpr(String tableName,
    --- End diff --
    
    Method name is not intuitive. This method just rearrange the order of cnfs.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to