andygrove commented on code in PR #5225:
URL: https://github.com/apache/datafusion-comet/pull/5225#discussion_r3721821918


##########
spark/src/test/scala/org/apache/spark/sql/comet/CometDecimalPromotionSuite.scala:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.spark.sql.comet
+
+import org.apache.spark.sql.CometTestBase
+import org.apache.spark.sql.catalyst.expressions.{ArrayContains, 
AttributeReference, Divide, EvalMode}
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.types.{DecimalType, IntegerType}
+
+import org.apache.comet.serde.{CometDivide, ExprOuterClass, QueryPlanSerde, 
Unsupported}
+
+class CometDecimalPromotionSuite extends CometTestBase {
+
+  private case class Operation(
+      name: String,
+      symbol: String,
+      hasProto: ExprOuterClass.Expr => Boolean)
+
+  private case class TestMode(name: String, ansiEnabled: Boolean, failOnError: 
Boolean)
+
+  test("issue #5190: decimal promotion is idempotent during recursive 
serialization") {
+    val left = "CAST(id AS DECIMAL(10, 0))"
+    val right = "CAST(id + 1 AS DECIMAL(10, 0))"
+    val divide = Operation(name = "divide", symbol = "/", hasProto = 
_.hasDivide)
+    val operations = Seq(
+      Operation(name = "add", symbol = "+", hasProto = _.hasAdd),
+      Operation(name = "subtract", symbol = "-", hasProto = _.hasSubtract),
+      Operation(name = "multiply", symbol = "*", hasProto = _.hasMultiply),
+      divide,
+      Operation(name = "remainder", symbol = "%", hasProto = _.hasRemainder))
+    val legacy = TestMode(name = "LEGACY", ansiEnabled = false, failOnError = 
false)
+    val ansi = TestMode(name = "ANSI", ansiEnabled = true, failOnError = true)
+
+    def check(operation: Operation, mode: TestMode, arithmetic: String): Unit 
= {
+      val name = s"${operation.name} ${mode.name}"
+      withSQLConf(SQLConf.ANSI_ENABLED.key -> mode.ansiEnabled.toString) {
+        val plan = spark
+          .sql(s"SELECT array_contains(array($arithmetic), $arithmetic) FROM 
range(1, 4)")

Review Comment:
   One thing worth guarding against here. The re-promotion this test exercises 
only happens because `CometArrayContains` serializes its children through the 
public `exprToProto`. That is exactly what #5248 proposes to change. Once 
someone switches `arrays.scala` to `exprToProtoInternal`, the `array_contains` 
half of this test stops covering the duplicate-wrapper path and keeps passing 
silently.
   
   Could you add a short comment naming that dependency and linking #5248, so 
whoever picks up that work knows this regression needs re-pointing? The 
`promote(promote(e)) == promote(e)` assertion below is independent and will 
still hold, so it is only the proto-shape half that is at risk.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to