in parquet-generator/src/main/java/org/apache/parquet/filter2/IncrementallyUpdatedFilterPredicateGenerator.java [382:540]
private void addContainsBegin() throws IOException {
add(" private abstract static class ContainsPredicate extends DelegatingValueInspector {\n"
+ " ContainsPredicate(ValueInspector... delegates) {\n"
+ " super(delegates);\n"
+ " }\n"
+ "\n"
+ " abstract ContainsPredicate not();\n"
+ " }\n"
+ "\n"
+ " private static class ContainsSinglePredicate extends ContainsPredicate {\n"
+ " private final boolean isNot;\n"
+ " \n"
+ " private ContainsSinglePredicate(ValueInspector inspector, boolean isNot) {\n"
+ " super(inspector);\n"
+ " this.isNot = isNot;\n"
+ " }\n\n"
+ " @Override\n"
+ " ContainsPredicate not() {\n"
+ " return new ContainsSinglePredicate(getDelegates().iterator().next(), true);\n"
+ " }\n"
+ "\n"
+ " @Override\n"
+ " void onUpdate() {\n"
+ " if (isKnown()) {\n"
+ " return;\n"
+ " }\n"
+ "\n"
+ " for (ValueInspector inspector : getDelegates()) {\n"
+ " if (inspector.isKnown() && inspector.getResult()) {\n"
+ " setResult(!isNot);\n"
+ " return;\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "\n"
+ " @Override\n"
+ " void onNull() {\n"
+ " setResult(isNot);\n"
+ " }\n"
+ " }\n\n");
add(" private static class ContainsAndPredicate extends ContainsPredicate {\n"
+ " private ContainsAndPredicate(ContainsPredicate left, ContainsPredicate right) {\n"
+ " super(left, right);\n"
+ " }\n"
+ "\n"
+ " @Override\n"
+ " void onUpdate() {\n"
+ " if (isKnown()) { return; }\n"
+ "\n"
+ " boolean allKnown = true;\n"
+ " for (ValueInspector delegate : getDelegates()) {\n"
+ " if (delegate.isKnown() && !delegate.getResult()) {\n"
+ " setResult(false);\n"
+ " return;\n"
+ " }\n"
+ " allKnown = allKnown && delegate.isKnown();\n"
+ " }\n"
+ " \n"
+ " if (allKnown) {\n"
+ " setResult(true);\n"
+ " }\n"
+ " }\n"
+ "\n"
+ " @Override\n"
+ " void onNull() {\n"
+ " for (ValueInspector delegate : getDelegates()) {\n"
+ " if (!delegate.getResult()) {\n"
+ " setResult(false);\n"
+ " return;\n"
+ " }\n"
+ " }\n"
+ " setResult(true);\n"
+ " }\n"
+ "\n"
+ " @Override\n"
+ " ContainsPredicate not() {\n"
+ " Iterator<ValueInspector> it = getDelegates().iterator();\n"
+ " return new ContainsAndPredicate(((ContainsPredicate) it.next()).not(), ((ContainsPredicate) it.next()).not());\n"
+ " }\n"
+ " }\n\n");
add(" private static class ContainsOrPredicate extends ContainsPredicate {\n"
+ " private ContainsOrPredicate(ContainsPredicate left, ContainsPredicate right) {\n"
+ " super(left, right);\n"
+ " }\n"
+ "\n"
+ " @Override\n"
+ " void onUpdate() {\n"
+ " if (isKnown()) { return; }\n"
+ "\n"
+ " for (ValueInspector delegate : getDelegates()) {\n"
+ " if (delegate.isKnown() && delegate.getResult()) {\n"
+ " setResult(true);\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "\n"
+ " @Override\n"
+ " void onNull() {\n"
+ " for (ValueInspector delegate : getDelegates()) {\n"
+ " if (delegate.getResult()) {\n"
+ " setResult(true);\n"
+ " return;\n"
+ " }\n"
+ " }\n"
+ " setResult(false);\n"
+ " }\n"
+ "\n"
+ " @Override\n"
+ " ContainsPredicate not() {\n"
+ " Iterator<ValueInspector> it = getDelegates().iterator();\n"
+ " return new ContainsOrPredicate(((ContainsPredicate) it.next()).not(), ((ContainsPredicate) it.next()).not());\n"
+ " }\n"
+ " }\n\n");
add(" private class ContainsInspectorVisitor implements FilterPredicate.Visitor<ContainsPredicate> {\n\n"
+ " @Override\n"
+ " public <T extends Comparable<T>> ContainsPredicate visit(Contains<T> contains) {\n"
+ " return contains.filter(this, ContainsAndPredicate::new, ContainsOrPredicate::new, ContainsPredicate::not);\n"
+ " }\n");
addContainsInspectorVisitor("Eq");
addContainsInspectorVisitor("NotEq");
addContainsInspectorVisitor("Lt");
addContainsInspectorVisitor("LtEq");
addContainsInspectorVisitor("Gt");
addContainsInspectorVisitor("GtEq");
addContainsInspectorVisitor("In");
addContainsInspectorVisitor("NotIn");
add(" @Override\n"
+ " public ContainsPredicate visit(Operators.And pred) {\n"
+ " throw new UnsupportedOperationException(\"Operators.And not supported for Contains predicate\");\n"
+ " }\n"
+ "\n"
+ " @Override\n"
+ " public ContainsPredicate visit(Operators.Or pred) {\n"
+ " throw new UnsupportedOperationException(\"Operators.Or not supported for Contains predicate\");\n"
+ " }\n"
+ "\n"
+ " @Override\n"
+ " public ContainsPredicate visit(Operators.Not pred) {\n"
+ " throw new UnsupportedOperationException(\"Operators.Not not supported for Contains predicate\");\n"
+ " }"
+ " @Override\n"
+ " public <T extends Comparable<T>, U extends UserDefinedPredicate<T>> ContainsPredicate visit(\n"
+ " UserDefined<T, U> pred) {\n"
+ " throw new UnsupportedOperationException(\"UserDefinedPredicate not supported for Contains predicate\");\n"
+ " }\n"
+ "\n"
+ " @Override\n"
+ " public <T extends Comparable<T>, U extends UserDefinedPredicate<T>> ContainsPredicate visit(\n"
+ " LogicalNotUserDefined<T, U> pred) {\n"
+ " throw new UnsupportedOperationException(\"LogicalNotUserDefined not supported for Contains predicate\");\n"
+ " }\n"
+ " }\n"
+ "\n");
}