kunwp1 commented on code in PR #9207:
URL: https://github.com/apache/texera/pull/9207#discussion_r4438931217


##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/set/BinarySetOpExec.scala:
##########
@@ -17,46 +17,40 @@
  * under the License.
  */
 
-package org.apache.texera.amber.operator.difference
+package org.apache.texera.amber.operator.set
 
 import org.apache.texera.amber.core.executor.OperatorExecutor
 import org.apache.texera.amber.core.tuple.{Tuple, TupleLike}
 
 import scala.collection.mutable
 
-class DifferenceOpExec extends OperatorExecutor {
-  private var leftHashSet: mutable.HashSet[Tuple] = _
-  private var rightHashSet: mutable.HashSet[Tuple] = _
-  private var exhaustedCounter: Int = _
+abstract class BinarySetOpExec extends OperatorExecutor {
+  private val leftSet = new mutable.HashSet[Tuple]()
+  private val rightSet = new mutable.HashSet[Tuple]()
+  private var exhaustedCounter = 0
 
   override def open(): Unit = {
-    leftHashSet = new mutable.HashSet()
-    rightHashSet = new mutable.HashSet()
+    close()
     exhaustedCounter = 0
   }
 
   override def close(): Unit = {
-    leftHashSet.clear()
-    rightHashSet.clear()
+    leftSet.clear()
+    rightSet.clear()
   }
 
   override def processTuple(tuple: Tuple, port: Int): Iterator[TupleLike] = {
-    if (port == 1) { // right input
-      rightHashSet.add(tuple)
-    } else { // left input
-      leftHashSet.add(tuple)
-    }
+    (if (port == 0) leftSet else rightSet) += tuple
     Iterator()
-
   }
 
   override def onFinish(port: Int): Iterator[TupleLike] = {
     exhaustedCounter += 1
-    if (2 == exhaustedCounter) {
-      leftHashSet.diff(rightHashSet).iterator
-    } else {
-      Iterator()
-    }
+    if (exhaustedCounter == 2) combine(leftSet, rightSet) else Iterator()
   }
 
+  protected def combine(
+      leftSet: mutable.HashSet[Tuple],
+      rightSet: mutable.HashSet[Tuple]
+  ): Iterator[TupleLike]

Review Comment:
   This hands subclasses the live mutable sets. Typing the parameters as 
`scala.collection.Set[Tuple]` would keep `combine` read-only and stop tying it 
to `HashSet`, and `diff`, `intersect` and `union` all work there. I tried it 
locally: it compiles, the subclasses drop their `mutable` import, and the set 
specs still pass.



##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/set/BinarySetOpExec.scala:
##########
@@ -17,46 +17,40 @@
  * under the License.
  */
 
-package org.apache.texera.amber.operator.difference
+package org.apache.texera.amber.operator.set
 
 import org.apache.texera.amber.core.executor.OperatorExecutor
 import org.apache.texera.amber.core.tuple.{Tuple, TupleLike}
 
 import scala.collection.mutable
 
-class DifferenceOpExec extends OperatorExecutor {
-  private var leftHashSet: mutable.HashSet[Tuple] = _
-  private var rightHashSet: mutable.HashSet[Tuple] = _
-  private var exhaustedCounter: Int = _
+abstract class BinarySetOpExec extends OperatorExecutor {
+  private val leftSet = new mutable.HashSet[Tuple]()
+  private val rightSet = new mutable.HashSet[Tuple]()
+  private var exhaustedCounter = 0
 
   override def open(): Unit = {
-    leftHashSet = new mutable.HashSet()
-    rightHashSet = new mutable.HashSet()
+    close()
     exhaustedCounter = 0
   }

Review Comment:
   The description lists the `open`/`close` reset as pinned, but every spec 
builds a fresh executor in `before`, so no test reaches it. A short test that 
runs one instance twice (open, feed, finish both ports, close, then again with 
different tuples) would pin it. Alternatively, the engine builds a new executor 
rather than reopening one (see `UpdateExecutorHandler`), and the fields now 
start empty so this override could go along with that row of the table.



-- 
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]

Reply via email to