aglinxinyuan commented on code in PR #8484:
URL: https://github.com/apache/texera/pull/8484#discussion_r4394514026
##########
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:
Two things here:
- `required = true` puts `predicateCombinator` in the schema's `required`
list.
- Workflows saved before this PR don't have that key, and nothing fills in
schema defaults when a workflow loads.
- The frontend validator then rejects every existing Filter: Run shows
"Invalid Workflow" until someone opens each Filter's property panel, and Form
View readers can't fix it at all.
- Projection's `isDrop` and Keyword Search's `isCaseSensitive` went in the
same way, but here it's free to avoid. Making it optional keeps the default and
the preselected dropdown, like `Histogram2DOpDesc`'s normalization property
does.
- Could you declare it above `predicates`, as #6939 proposed? Right now the
dropdown renders below every predicate row and the add button, so with several
predicates you can't see which mode applies.
```suggestion
@JsonProperty(required = false, defaultValue = "any (OR)")
@JsonSchemaTitle("Combine Predicates With")
@JsonPropertyDescription("how to combine multiple predicates")
var predicateCombinator: PredicateCombinator = PredicateCombinator.OR
@JsonProperty(value = "predicates", required = true)
@JsonPropertyDescription("multiple predicates to be combined")
var predicates: List[FilterPredicate] = List.empty
```
##########
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:
Nit: with `case _`, a future third combinator would silently run as OR.
Naming `OR` explicitly gets a compiler warning instead, and choosing the
function once avoids re-matching on every tuple. No null case is needed:
`getPhysicalOp` serializes without nulls, so the executor always gets the OR
default.
```suggestion
setFilterFunc(desc.predicateCombinator match {
case PredicateCombinator.AND =>
(tuple: Tuple) => desc.predicates.nonEmpty &&
desc.predicates.forall(_.evaluate(tuple))
case PredicateCombinator.OR =>
(tuple: Tuple) => desc.predicates.exists(_.evaluate(tuple))
})
```
##########
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:
Could you also test bad input at this level? Two cases:
- `"predicateCombinator": "xor"` read as `LogicalOp` should fail with a
`ValueInstantiationException` that names the field.
- An executor built from JSON with `"predicateCombinator": null` should
behave as OR.
AGENTS.md's test rules ask for bad-input coverage on user input.
##########
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:
Every AND case puts `int = 0` first, and that predicate is true for
`nonNullTuple`. So no test shows the first predicate can reject a row under
AND: `predicates.tail.forall(...)` or `predicates.last.evaluate(...)` would
pass the whole suite. Could you add the same pair in the other order?
```scala
it should "drop a tuple under AND when the first predicate fails" in {
opDesc.predicates = List(
new FilterPredicate("string", ComparisonType.EQUAL_TO, "world"),
new FilterPredicate("int", ComparisonType.EQUAL_TO, "0")
)
opDesc.predicateCombinator = PredicateCombinator.AND
val opExec = new
SpecializedFilterOpExec(objectMapper.writeValueAsString(opDesc))
opExec.open()
assert(opExec.processTuple(nonNullTuple, inputPort).isEmpty)
opExec.close()
}
```
Minor: line 148 does nothing, because the `before` hook already resets the
combinator to 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:
Optional: Jackson already reads a `@JsonValue` enum back from its value, and
most enums in this module (`JoinType`, for example) don't have this creator.
Fine to keep if you'd rather match `ComparisonType`.
##########
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:
If the property becomes optional, drop the ✓, and if it moves above
Predicates, move this row up too. Also worth one line saying that "all (AND)"
with no predicates keeps no rows, since most people expect "all" of nothing to
keep everything.
--
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]