gupta-sahil01 commented on code in PR #8484:
URL: https://github.com/apache/texera/pull/8484#discussion_r4544540871
##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/filter/SpecializedFilterOpDesc.scala:
##########
@@ -29,9 +30,14 @@ import org.apache.texera.amber.util.JSONUtils.objectMapper
class SpecializedFilterOpDesc extends FilterOpDesc {
@JsonProperty(value = "predicates", required = true)
- @JsonPropertyDescription("multiple predicates in OR")
+ @JsonPropertyDescription("multiple predicates to be combined")
var predicates: List[FilterPredicate] = List.empty
+ @JsonProperty(required = true, defaultValue = "any (OR)")
+ @JsonSchemaTitle("Combine Predicates With")
+ @JsonPropertyDescription("how to combine multiple predicates")
+ var predicateCombinator: PredicateCombinator = PredicateCombinator.OR
Review Comment:
Done: made it optional (not in the schema's required list) and moved it
above predicates. I also added @JsonSetter(nulls = Nulls.SKIP) so an explicit
null keeps the OR default instead of reaching the executor as null.
##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/filter/SpecializedFilterOpExec.scala:
##########
@@ -25,5 +25,11 @@ import org.apache.texera.amber.util.JSONUtils.objectMapper
class SpecializedFilterOpExec(descString: String) extends FilterOpExec {
private val desc: SpecializedFilterOpDesc =
objectMapper.readValue(descString, classOf[SpecializedFilterOpDesc])
- setFilterFunc((tuple: Tuple) => desc.predicates.exists(_.evaluate(tuple)))
+ setFilterFunc((tuple: Tuple) =>
+ desc.predicateCombinator match {
+ case PredicateCombinator.AND =>
+ desc.predicates.nonEmpty && desc.predicates.forall(_.evaluate(tuple))
+ case _ => desc.predicates.exists(_.evaluate(tuple))
+ }
+ )
Review Comment:
Done: both cases are named, and the function is chosen once.
##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/filter/SpecializedFilterOpExecSpec.scala:
##########
@@ -135,4 +139,65 @@ class SpecializedFilterOpExecSpec extends AnyFlatSpec with
BeforeAndAfter {
opExec.close()
})
}
+
+ it should "keep a tuple under OR when only one predicate matches" in {
+ opDesc.predicates = List(
+ new FilterPredicate("int", ComparisonType.EQUAL_TO, "0"),
+ new FilterPredicate("string", ComparisonType.EQUAL_TO, "world")
+ )
+ opDesc.predicateCombinator = PredicateCombinator.OR
+ val opExec = new
SpecializedFilterOpExec(objectMapper.writeValueAsString(opDesc))
+ opExec.open()
+ assert(opExec.processTuple(nonNullTuple, inputPort).nonEmpty)
+ opExec.close()
+ }
+
+ it should "drop a tuple under AND when only one predicate matches" in {
Review Comment:
Added the reversed-order AND test and removed the no-op line.
##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/filter/SpecializedFilterOpDescSpec.scala:
##########
@@ -70,4 +75,27 @@ class SpecializedFilterOpDescSpec extends AnyFlatSpec with
Matchers {
restored shouldBe a[SpecializedFilterOpDesc]
restored.asInstanceOf[SpecializedFilterOpDesc].predicates shouldBe empty
}
+
+ "SpecializedFilterOpDesc" should
Review Comment:
Added both: 'xor' fails with a ValueInstantiationException naming the field,
and a null combinator behaves as OR.
##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/filter/PredicateCombinator.java:
##########
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.amber.operator.filter;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonValue;
+
+public enum PredicateCombinator {
+ OR("any (OR)"),
+
+ AND("all (AND)");
+
+ private final String name;
+
+ private PredicateCombinator(String name) {
+ this.name = name;
+ }
+
+ // use the name string instead of enum string in JSON
+ @JsonValue
+ public String getName() {
+ return this.name;
+ }
+
+ // Handle custom deserialization for enum
Review Comment:
Kept it to match ComparisonType. It also gives the
ValueInstantiationException the bad-input test checks for.
##########
docs/reference/operators/data-cleaning/filter.md:
##########
@@ -31,10 +31,11 @@ tags: [data-cleaning]
| Property | Requirement | Type | Default | Description |
|----------|-------------|------|---------|-------------|
-| Predicates | ✓ | List<Filter Predicate> | - | Multiple predicates in OR |
+| Predicates | ✓ | List<Filter Predicate> | - | Multiple predicates to be
combined |
| ↳ Attribute | ✓ | String | - | |
| ↳ Condition | ✓ | =, >, >=, <, <=, !=, is null,<br>is not null | - | |
| ↳ Value | | String | - | |
+| Combine Predicates With | ✓ | any (OR), all (AND) | any (OR) | How to
combine multiple predicates |
Review Comment:
Done: dropped the check mark, moved the row above Predicates, and added a
line saying that 'all (AND)' with no predicates keeps no rows. Also fixed
_index.md.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]