aglinxinyuan commented on code in PR #9683:
URL: https://github.com/apache/texera/pull/9683#discussion_r4690892754


##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/FilterSearchSpecSupport.scala:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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
+
+import org.apache.texera.amber.core.executor.{OpExecWithClassName, 
OperatorExecutor}
+import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema, 
Tuple}
+import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity, 
WorkflowIdentity}
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.amber.util.PythonTestSupport.{canImport, 
configuredPython, runSource}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+abstract class FilterSearchSpecSupport extends AnyFlatSpec with Matchers {
+
+  protected val bodyAttr: Attribute = new Attribute("body", 
AttributeType.STRING)
+  protected val bodySchema: Schema = Schema().add(bodyAttr)
+
+  protected def tuple(text: String): Tuple =
+    Tuple.builder(bodySchema).add(bodyAttr, text).build()
+
+  protected def assertMatches(exec: OperatorExecutor, text: String): Unit = {
+    val t = tuple(text)
+    assert(exec.processTuple(t, port = 0).toList == List(t))
+  }
+
+  protected def assertMisses(exec: OperatorExecutor, text: String): Unit =
+    assert(exec.processTuple(tuple(text), port = 0).toList.isEmpty)
+
+  protected def assertPhysicalOpWired(op: LogicalOp, expectedClassName: 
String): Unit = {
+    val physical = op.getPhysicalOp(WorkflowIdentity(1L), 
ExecutionIdentity(1L))
+    physical.opExecInitInfo match {
+      case OpExecWithClassName(className, descString) =>
+        className shouldBe expectedClassName
+        descString should not be empty
+      case other => fail(s"expected OpExecWithClassName, got $other")
+    }
+    // Pin the actual port identities (not just counts).
+    physical.inputPorts.keySet shouldBe 
op.operatorInfo.inputPorts.map(_.id).toSet
+    physical.outputPorts.keySet shouldBe 
op.operatorInfo.outputPorts.map(_.id).toSet
+  }
+
+  protected def assertStandaloneParity[D <: StandaloneCodeGenerator](
+      prefix: String,
+      flagName: String,
+      cases: Seq[(String, Boolean, Seq[String])],
+      extraPreamble: Seq[String] = Nil
+  )(buildDesc: (String, Boolean) => D)(buildExec: String => OperatorExecutor): 
Unit = {
+    val python = configuredPython().getOrElse(cancel("No runnable python 
executable"))
+    if (!canImport(python, "pandas")) cancel(s"'$python' cannot import pandas")
+
+    val schema = Schema().add("v", AttributeType.STRING).add("i", 
AttributeType.INTEGER)
+    val runs = cases.map {
+      case (needle, flag, values) =>
+        val desc = buildDesc(needle, flag)
+        val exec = buildExec(objectMapper.writeValueAsString(desc))
+        exec.open()
+        val kept = values.zipWithIndex.flatMap {
+          case (v, i) => exec.processTuple(Tuple(schema, Array[Any](v, i)), 0)
+        }
+        exec.close()
+        val label = s"'$needle' $flagName=$flag"
+        val engine = s"$label: ${kept.map(_.getFields(1)).mkString(" ")}"
+        val code = (desc.standaloneHelpers() :+
+          desc.generateStandaloneCode(Map(PortIdentity() -> 
schema))).mkString("\n")
+        val script =
+          s"""in1df = pd.DataFrame({"v": 
pd.Series(${objectMapper.writeValueAsString(
+            values
+          )}, dtype=object)})
+             |in1df["i"] = range(len(in1df))
+             |ns = {"pd": pd, "in1df": in1df}
+             |exec(${objectMapper.writeValueAsString(code)}, ns)
+             |print(${objectMapper.writeValueAsString(
+            label + ":"
+          )}, " ".join(str(i) for i in ns["out1df"]["i"]))""".stripMargin
+        (engine, script)
+    }
+
+    val driver = (("import pandas as pd" +: extraPreamble) ++ 
runs.map(_._2)).mkString("\n")

Review Comment:
   Moved the `null = None` shim into the shared driver and dropped 
`extraPreamble` in 87f304a378, so a substring case with a missing value would 
compare the engines too.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
   



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/aggregate/AggregateOpDescSpec.scala:
##########
@@ -120,52 +121,88 @@ class AggregateOpDescSpec extends AnyFlatSpec with 
Matchers {
     // fast rather than propagate a null-typed output.
     val input = Schema().add("v", AttributeType.LONG)
     assertThrows[Exception] {
-      descWith(List.empty, aggOp(AggregationFunction.SUM, "", "total"))
-        .getExternalOutputSchemas(Map(PortIdentity() -> input))
+      outputSchemasFor(input, List.empty, aggOp(AggregationFunction.SUM, "", 
"total"))
     }
   }
 
-  // The integers behind a timestamp column mean microseconds or nanoseconds
-  // depending on the resolution it was read at, and a nanosecond total leaves
-  // the range of a 64-bit integer after a handful of modern dates.
-  it should "read a timestamp as epoch milliseconds at either resolution" 
taggedAs NeedsPythonPackages in {
-    val python = resolvePython().getOrElse(cancel("No runnable python 
executable"))
-    if (!canImportPandas(python)) cancel(s"'$python' cannot import pandas")
+  private def requirePandasPython(): String = {
+    val python = configuredPython().getOrElse(cancel("No runnable python 
executable"))
+    if (!canImport(python, "pandas", "numpy")) cancel(s"'$python' cannot 
import pandas")
+    python
+  }

Review Comment:
   Added `requirePython(modules: String*)` to `PythonTestSupport` in 
87f304a378; `SetRows`, the aggregate spec, `FilterSearchSpecSupport` and 
`IntersectOpDescSpec` now call it with the modules each checked before.
   
   _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
   



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