You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/12/25 06:59:10 UTC
[GitHub] [spark] maropu commented on a change in pull request #30923: [SPARK-33909][SQL] Check rand functions seed is legal at analyer side
maropu commented on a change in pull request #30923:
URL: https://github.com/apache/spark/pull/30923#discussion_r548818404
##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/randomExpressions.scala
##########
@@ -49,8 +48,6 @@ abstract class RDG extends UnaryExpression with ExpectsInputTypes with Stateful
@transient protected lazy val seed: Long = seedExpression match {
case Literal(s, IntegerType) => s.asInstanceOf[Int]
case Literal(s, LongType) => s.asInstanceOf[Long]
Review comment:
Ur, we might need to update the two entries above like this;
```
case e if e.dataType == IntegerType => e.eval().asInstanceOf[Int]
case e if e.dataType == LongType => e.eval().asInstanceOf[Long]
```
Otherwise, we can hit a unmatch exception when excluding `ConstantFolding` and `ReorderAssociativeOperator`?
```
// v3.0.1
:$./bin/spark-shell --conf spark.sql.optimizer.excludedRules=org.apache.spark.sql.catalyst.optimizer.ConstantFolding,org.apache.spark.sql.catalyst.optimizer.ReorderAssociativeOperator
scala> sql("select rand(1 + 2)").show()
org.apache.spark.sql.AnalysisException: Input argument to rand must be an integer, long or null literal.;
at org.apache.spark.sql.catalyst.expressions.RDG.seed$lzycompute(randomExpressions.scala:49)
at org.apache.spark.sql.catalyst.expressions.RDG.seed(randomExpressions.scala:46)
at org.apache.spark.sql.catalyst.expressions.Rand.doGenCode(randomExpressions.scala:98)
at org.apache.spark.sql.catalyst.expressions.Expression.$anonfun$genCode$3(Expression.scala:146)
at scala.Option.getOrElse(Option.scala:189)
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org