This is an automated email from the ASF dual-hosted git repository.

yikf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new 4400f2b0d6 [VL][TEST] Cover map and map_from_entries under both map 
key dedup policies (#13677)
4400f2b0d6 is described below

commit 4400f2b0d676796e174b35db078605041a3f4c79
Author: Anshul Baliga <[email protected]>
AuthorDate: Thu Nov 19 08:34:22 2026 +0530

    [VL][TEST] Cover map and map_from_entries under both map key dedup policies 
(#13677)
    
    Velox reimplemented the key resolution of map() and map_from_entries to 
follow
    spark.sql.mapKeyDedupPolicy the way Spark's map builder does, and Gluten
    offloads both. Only map_from_arrays, transform_keys and str_to_map had a 
test
    that gives them a repeated key. map() had no test with repeated keys at all,
    and the map_from_entries test never repeated a key.
    
    Add one test for each, shaped like the existing map_from_arrays test. Under
    EXCEPTION a query without a repeated key offloads and matches vanilla Spark,
    and a query with a repeated key offloads and raises the duplicate key error.
    Under LAST_WIN the same query offloads and matches vanilla Spark, including
    the order of map_keys, which pins that a repeated key keeps the position of 
its
    first occurrence and takes the value of its last.
    
    The keys come from a table because Spark rejects repeated literal keys while
    planning, before the query reaches Velox.
---
 .../functions/ScalarFunctionsValidateSuite.scala   | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git 
a/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala
 
b/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala
index e92ff7c888..ea114f0a04 100644
--- 
a/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala
+++ 
b/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala
@@ -757,6 +757,83 @@ class ScalarFunctionsValidateSuite extends 
FunctionsValidateSuite {
     }
   }
 
+  test("map offloads to Velox under both mapKeyDedupPolicy values") {
+    // l_orderkey is repeated. The keys must come from a table: Spark rejects 
repeated literal keys
+    // while planning, before the query reaches Velox.
+    val duplicateKeys =
+      "map(l_orderkey, l_partkey, l_orderkey + 1, l_suppkey, l_orderkey, 
l_linenumber)"
+    val duplicateKeyQuery =
+      s"select $duplicateKeys as m, map_keys($duplicateKeys) as k from 
lineitem limit 10"
+
+    // l_orderkey is not repeated.
+    val distinctKeyQuery =
+      "select map(l_orderkey, l_partkey, l_orderkey + 1, l_suppkey) from 
lineitem limit 10"
+
+    withSQLConf(SQLConf.MAP_KEY_DEDUP_POLICY.key -> 
SQLConf.MapKeyDedupPolicy.EXCEPTION.toString) {
+      // EXCEPTION policy passes when there is no duplicate.
+      runQueryAndCompare(distinctKeyQuery) {
+        checkGlutenPlan[ProjectExecTransformer]
+      }
+
+      // EXCEPTION policy raises on a duplicate.
+      val df = sql(duplicateKeyQuery)
+      checkGlutenPlan[ProjectExecTransformer](df)
+      val e = intercept[SparkException] {
+        df.collect()
+      }
+      assert(e.getMessage.contains("Duplicate map key"))
+    }
+
+    withSQLConf(SQLConf.MAP_KEY_DEDUP_POLICY.key -> 
SQLConf.MapKeyDedupPolicy.LAST_WIN.toString) {
+      // LAST_WIN policy keeps the duplicate's first position and its last 
value.
+      runQueryAndCompare(duplicateKeyQuery) {
+        checkGlutenPlan[ProjectExecTransformer]
+      }
+    }
+  }
+
+  test("map_from_entries offloads to Velox under both mapKeyDedupPolicy 
values") {
+    // l_orderkey is repeated. The fields are named and the values cast so 
that all entries have the
+    // same struct type: struct() would name the first field after the column 
only when the key is
+    // a bare column, which makes the entries differ.
+    val duplicateEntries =
+      "array(named_struct('k', l_orderkey, 'v', cast(l_partkey as bigint)), " +
+        "named_struct('k', l_orderkey + 1, 'v', cast(l_suppkey as bigint)), " +
+        "named_struct('k', l_orderkey, 'v', cast(l_linenumber as bigint)))"
+    val duplicateKeyQuery =
+      s"select map_from_entries($duplicateEntries) as m, " +
+        s"map_keys(map_from_entries($duplicateEntries)) as k from lineitem 
limit 10"
+
+    // l_orderkey is not repeated.
+    val distinctKeyQuery =
+      "select map_from_entries(array(" +
+        "named_struct('k', l_orderkey, 'v', cast(l_partkey as bigint)), " +
+        "named_struct('k', l_orderkey + 1, 'v', cast(l_suppkey as bigint)))) " 
+
+        "from lineitem limit 10"
+
+    withSQLConf(SQLConf.MAP_KEY_DEDUP_POLICY.key -> 
SQLConf.MapKeyDedupPolicy.EXCEPTION.toString) {
+      // EXCEPTION policy passes when there is no duplicate.
+      runQueryAndCompare(distinctKeyQuery) {
+        checkGlutenPlan[ProjectExecTransformer]
+      }
+
+      // EXCEPTION policy raises on a duplicate.
+      val df = sql(duplicateKeyQuery)
+      checkGlutenPlan[ProjectExecTransformer](df)
+      val e = intercept[SparkException] {
+        df.collect()
+      }
+      assert(e.getMessage.contains("Duplicate map key"))
+    }
+
+    withSQLConf(SQLConf.MAP_KEY_DEDUP_POLICY.key -> 
SQLConf.MapKeyDedupPolicy.LAST_WIN.toString) {
+      // LAST_WIN policy keeps the duplicate's first position and its last 
value.
+      runQueryAndCompare(duplicateKeyQuery) {
+        checkGlutenPlan[ProjectExecTransformer]
+      }
+    }
+  }
+
   test("raise_error, assert_true") {
     runQueryAndCompare("""SELECT assert_true(l_orderkey >= 1), l_orderkey
                          | from lineitem limit 100""".stripMargin) {


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

Reply via email to