Copilot commented on code in PR #4778:
URL: https://github.com/apache/texera/pull/4778#discussion_r3177480011


##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/map/MapOpExecSpec.scala:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.map
+
+import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema, 
Tuple}
+import org.scalatest.flatspec.AnyFlatSpec
+
+class MapOpExecSpec extends AnyFlatSpec {
+
+  private val schema: Schema =
+    Schema().add(new Attribute("v", AttributeType.INTEGER))
+
+  private def tuple(v: Int): Tuple =
+    Tuple.builder(schema).add(new Attribute("v", AttributeType.INTEGER), 
Integer.valueOf(v)).build()

Review Comment:
   The `tuple(v)` helper builds tuples by calling `builder.add(new 
Attribute("v", AttributeType.INTEGER), ...)`. Because 
`Tuple.Builder.add(Attribute, field)` validates the field against the 
*passed-in* Attribute (not the schema's Attribute), this can accidentally 
construct tuples whose `schema` and field types diverge if the schema changes. 
Prefer using `schema.getAttribute("v")` (or `addSequentially`) so the helper is 
always consistent with the schema under test.
   



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/map/MapOpExecSpec.scala:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.map
+
+import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema, 
Tuple}
+import org.scalatest.flatspec.AnyFlatSpec
+
+class MapOpExecSpec extends AnyFlatSpec {
+
+  private val schema: Schema =
+    Schema().add(new Attribute("v", AttributeType.INTEGER))
+
+  private def tuple(v: Int): Tuple =
+    Tuple.builder(schema).add(new Attribute("v", AttributeType.INTEGER), 
Integer.valueOf(v)).build()
+
+  private class TestMap extends MapOpExec
+
+  "MapOpExec.processTuple" should "emit exactly one tuple per input by 
applying the configured mapFunc" in {
+    val exec = new TestMap()
+    exec.setMapFunc((t: Tuple) => tuple(t.getField[Int]("v") * 2))
+
+    val out = exec.processTuple(tuple(3), 0).toList
+    assert(out == List(tuple(6)))
+  }
+
+  it should "preserve identity when mapFunc returns the input tuple" in {
+    val exec = new TestMap()
+    exec.setMapFunc((t: Tuple) => t)
+
+    val input = tuple(7)
+    val out = exec.processTuple(input, 0).toList
+    assert(out.size == 1)
+    assert(out.head.asInstanceOf[Tuple] == input)

Review Comment:
   This test case is titled as an identity check, but it currently asserts 
structural equality (`==`) rather than reference identity. If you want to 
verify the contract that `processTuple` returns the *same instance* when 
`mapFunc` returns the input tuple, assert referential equality (e.g., `eq`) and 
avoid the `asInstanceOf[Tuple]` cast so failures are reported as assertion 
failures rather than `ClassCastException`.
   



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