Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,32 @@ public String toString() {
return "OR(" + Arrays.toString(preds) + ")";
}
}

/** An AND predicate that can be evaluated by the OrcInputFormat. */
public static class And extends Predicate {
private final Predicate[] preds;

/**
* Creates an AND predicate.
*
* @param predicates The disjunctive predicates.
*/
public And(Predicate... predicates) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds the java doc of the constructor which style follows the OR, NOT etc:

/**
   * Creates an AND predicate.
   *
   * @param predicates The disjunctive predicates.
   */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @SteNicholas Done

this.preds = predicates;
}

@Override
public SearchArgument.Builder add(SearchArgument.Builder builder) {
SearchArgument.Builder withAnd = builder.startAnd();
for (Predicate pred : preds) {
withAnd = pred.add(withAnd);
}
return withAnd.end();
}

@Override
public String toString() {
return "AND(" + Arrays.toString(preds) + ")";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,16 @@ public Optional<OrcFilters.Predicate> visitNotIn(FieldRef fieldRef, List<Object>

@Override
public Optional<OrcFilters.Predicate> visitAnd(List<Optional<OrcFilters.Predicate>> children) {
return Optional.empty();
if (children.size() != 2) {
throw new RuntimeException("Illegal and children: " + children.size());
}

Optional<OrcFilters.Predicate> c1 = children.get(0);
if (!c1.isPresent()) {
return Optional.empty();
}
Optional<OrcFilters.Predicate> c2 = children.get(1);
return c2.map(value -> new OrcFilters.And(c1.get(), value));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ public void testApplyPredicate() {
new OrcFilters.Equals("long1", PredicateLeaf.Type.LONG, 1),
new OrcFilters.Equals("long1", PredicateLeaf.Type.LONG, 2)),
new OrcFilters.Equals("long1", PredicateLeaf.Type.LONG, 3)));

test(
builder.between(0, 1L, 3L),
new OrcFilters.And(
new OrcFilters.Not(
new OrcFilters.LessThan("long1", PredicateLeaf.Type.LONG, 1)),
new OrcFilters.LessThanEquals("long1", PredicateLeaf.Type.LONG, 3)));

test(
builder.notIn(0, Arrays.asList(1L, 2L, 3L)),
new OrcFilters.And(
new OrcFilters.And(
new OrcFilters.Not(
new OrcFilters.Equals("long1", PredicateLeaf.Type.LONG, 1)),
new OrcFilters.Not(
new OrcFilters.Equals(
"long1", PredicateLeaf.Type.LONG, 2))),
new OrcFilters.Not(
new OrcFilters.Equals("long1", PredicateLeaf.Type.LONG, 3))));
}

private void test(Predicate predicate, OrcFilters.Predicate orcPredicate) {
Expand Down