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


##########
spark/src/main/scala/org/apache/comet/serde/maps.scala:
##########
@@ -132,6 +132,28 @@ object CometMapExtract extends 
CometExpressionSerde[GetMapValue] {
   }
 }
 
+/**
+ * Shared gate for the native map builders, `map_from_arrays` and 
`map_from_entries`, which tell
+ * keys apart by their bits. Spark's `ArrayBasedMapBuilder` finds a duplicate 
`FLOAT` or `DOUBLE`
+ * key in a `HashMap` of boxed values, where every NaN is one key, and a 
duplicate struct or array
+ * key in a `TreeMap` in Spark's SQL ordering, where `-0.0` equals `0.0` too. 
From Spark 4.0 it
+ * also normalizes a `FLOAT` or `DOUBLE` key before the lookup, unless
+ * `spark.sql.legacy.disableMapKeyNormalization` is set, so the two zeros are 
one key and
+ * `map_from_entries` stores `0.0`. A key type that holds a float at any depth 
is therefore
+ * `Incompatible` on every version.
+ */
+private object MapBuilderKeySupport {
+  val floatingPointReason: String =
+    "Spark finds duplicate map keys that hold a `FLOAT` or `DOUBLE` by value, 
so NaNs with " +
+      "different bits are one key, and so are `-0.0` and `0.0` inside a struct 
or array key. " +
+      "From Spark 4.0, a `-0.0` key is also normalized to `0.0`, unless " +
+      "`spark.sql.legacy.disableMapKeyNormalization` is set. Comet's native 
map construction " +
+      "compares the keys' bits 
([#6549](https://github.com/apache/datafusion-comet/issues/6549))."

Review Comment:
   Changed the PR description to `Part of #6549`, so the issue stays open until 
#6682 lands. The reason string keeps its link to #6549, which is still the 
right place for the open difference.



##########
spark/src/main/scala/org/apache/comet/serde/maps.scala:
##########
@@ -132,6 +132,28 @@ object CometMapExtract extends 
CometExpressionSerde[GetMapValue] {
   }
 }
 
+/**
+ * Shared gate for the native map builders, `map_from_arrays` and 
`map_from_entries`, which tell
+ * keys apart by their bits. Spark's `ArrayBasedMapBuilder` finds a duplicate 
`FLOAT` or `DOUBLE`
+ * key in a `HashMap` of boxed values, where every NaN is one key, and a 
duplicate struct or array
+ * key in a `TreeMap` in Spark's SQL ordering, where `-0.0` equals `0.0` too. 
From Spark 4.0 it
+ * also normalizes a `FLOAT` or `DOUBLE` key before the lookup, unless
+ * `spark.sql.legacy.disableMapKeyNormalization` is set, so the two zeros are 
one key and
+ * `map_from_entries` stores `0.0`. A key type that holds a float at any depth 
is therefore
+ * `Incompatible` on every version.
+ */
+private object MapBuilderKeySupport {
+  val floatingPointReason: String =
+    "Spark finds duplicate map keys that hold a `FLOAT` or `DOUBLE` by value, 
so NaNs with " +
+      "different bits are one key, and so are `-0.0` and `0.0` inside a struct 
or array key. " +
+      "From Spark 4.0, a `-0.0` key is also normalized to `0.0`, unless " +
+      "`spark.sql.legacy.disableMapKeyNormalization` is set. Comet's native 
map construction " +
+      "compares the keys' bits 
([#6549](https://github.com/apache/datafusion-comet/issues/6549))."
+
+  def hasFloatingPointKey(dataType: MapType): Boolean =

Review Comment:
   Corrected in ee66473fd. The `MapKeySupport` reason and scaladoc no longer 
say the builder normalizes keys. They now say the lookup uses Spark's SQL 
ordering, where `-0.0` equals `0.0` and all NaNs are equal, on every version, 
and point at `MapBuilderKeySupport` for how the builder differs by version. I 
kept the two objects separate rather than folding them, because one gates 
lookups and the other gates construction. The builder explanation now lives 
only in `MapBuilderKeySupport.floatingPointReason`. Three fixtures and 
`CometMapExpressionSuite` matched the old reason text, so I updated those.



##########
spark/src/main/scala/org/apache/comet/serde/maps.scala:
##########
@@ -132,6 +132,28 @@ object CometMapExtract extends 
CometExpressionSerde[GetMapValue] {
   }
 }
 
+/**

Review Comment:
   The scaladoc on `MapBuilderKeySupport` now says only why the gate lives 
there and points at `floatingPointReason`. The "Map construction" section in 
`floating-point.md` is down to the user-facing result, with a link to the 
expression compatibility guide for the reason. The audit entries and the 
contributor guide rule still describe the builder behavior, since those are the 
places a reader looks for the audit trail, so they will need updating when 
#6682 lifts the gate.



##########
spark/src/test/resources/sql-tests/expressions/map/map_builders_float_keys.sql:
##########
@@ -0,0 +1,94 @@
+-- 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.
+
+-- Map keys that hold a FLOAT or DOUBLE (#6549). Spark finds a duplicate 
top-level key in a HashMap

Review Comment:
   Renamed in ee66473fd to `map_builders_float_key_gate.sql`, 
`map_builders_float_key_gate_legacy.sql` and 
`map_builders_float_key_gate_spark_4_0.sql`, so none of the names match the 
files in #6682. When #6682 lifts the gate these three should be deleted or 
folded into its fixtures, since they assert dispatch and the other PR asserts 
native behavior.



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