Copilot commented on code in PR #1938:
URL: https://github.com/apache/auron/pull/1938#discussion_r2925245262


##########
spark-extension/src/main/scala/org/apache/spark/sql/auron/NativeConverters.scala:
##########
@@ -849,6 +849,15 @@ object NativeConverters extends Logging {
       case e: Hex => buildScalarFunction(pb.ScalarFunction.Hex, e.children, 
e.dataType)
       case e: IsNaN =>
         buildExtScalarFunction("Spark_IsNaN", e.children, e.dataType)
+      case e: Randn =>
+        val seed = e.child match {
+          case Literal(s: Long, _) => s
+          case Literal(s: Int, _) => s.toLong
+          case _ => 0L
+        }
+        buildExprNode {
+          _.setSparkRandnExpr(pb.SparkRandnExprNode.newBuilder().setSeed(seed))
+        }

Review Comment:
   `Randn` seed extraction only handles `Literal` Int/Long; any other (still 
foldable) seed expression (e.g., `randn(cast(42 as bigint))`, arithmetic, etc.) 
will silently be treated as `0L`, changing semantics vs Spark. Instead of 
defaulting to 0, consider evaluating foldable seeds to a Long (or falling back 
to Spark execution when the seed isn't a supported constant).
   ```suggestion
           val seedOpt: Option[Long] = e.child match {
             case Literal(s: Long, _) => Some(s)
             case Literal(s: Int, _) => Some(s.toLong)
             case expr if expr.foldable =>
               Option(expr.eval(null)).collect { case n: Number => 
n.longValue() }
             case _ => None
           }
           seedOpt
             .map { seed =>
               buildExprNode {
                 
_.setSparkRandnExpr(pb.SparkRandnExprNode.newBuilder().setSeed(seed))
               }
             }
             .getOrElse(fallback(e))
   ```



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