cloud-fan commented on code in PR #52046:
URL: https://github.com/apache/spark/pull/52046#discussion_r2282179236


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/package.scala:
##########
@@ -95,23 +95,92 @@ package object expressions  {
       StructType(attrs.map(a => StructField(a.name, a.dataType, a.nullable, 
a.metadata)))
     }
 
+    // Compute min and max expression IDs in a single pass
+    @transient private lazy val minMaxExprId: (Long, Long) = {
+      if (attrs.isEmpty) {
+        (0L, -1L)
+      } else {
+        var min = Long.MaxValue
+        var max = Long.MinValue
+        attrs.foreach { attr =>
+          val id = attr.exprId.id
+          if (id < min) min = id
+          if (id > max) max = id
+        }
+        (min, max)
+      }
+    }
+
+    // Extract as primitive fields to avoid boxing on access
+    @transient private lazy val minExprId: Long = minMaxExprId._1
+    @transient private lazy val maxExprId: Long = minMaxExprId._2
+
+    // Create a method that either uses a direct indexed array with the min
+    // and max expression IDs as an offset or a hash map.
+    @transient private lazy val ordinalArrays: (Long => Int, Array[Attribute]) 
= {

Review Comment:
   how about
   ```
   ... lazy val exprIdToOrdinal: Long => Int = {
     if (attrs.isEmpty) {
       exprId => -1
     } else if (not overflow and not too parse) {
       ...
       exprId => ...
     } else {
       ... build hash map
       exprId => map.getOrElse(exprId, -1)
     }
   }
   ```



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to