dtenedor commented on code in PR #49210:
URL: https://github.com/apache/spark/pull/49210#discussion_r1904734280
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/randomExpressions.scala:
##########
@@ -330,7 +330,8 @@ object Uniform {
group = "string_funcs")
case class RandStr(
length: Expression, override val seedExpression: Expression, hideSeed:
Boolean)
- extends ExpressionWithRandomSeed with BinaryLike[Expression] with
Nondeterministic {
+ extends ExpressionWithRandomSeed with BinaryLike[Expression] with
Nondeterministic
+ with ExpectsInputTypes {
Review Comment:
Good question! In general I prefer to use `ImplicitCastInputTypes`. But here
I found that the existing `RAND` and `RANDN` functions extend
`ExpectsInputTypes` and return errors when we try to pass numeric values other
than `IntegerType` or `LongType`. So I figured that it would be consistent for
`RANDSTR` to do the same. Let me know if I should think differently.
```
-- !query
SELECT rand(0.1F)
-- !query schema
struct<>
-- !query output
org.apache.spark.sql.catalyst.ExtendedAnalysisException
{
"errorClass" : "DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE",
"sqlState" : "42K09",
"messageParameters" : {
"inputSql" : "\"0.1\"",
"inputType" : "\"FLOAT\"",
"paramIndex" : "first",
"requiredType" : "(\"INT\" or \"BIGINT\")",
"sqlExpr" : "\"rand(0.1)\""
},
"queryContext" : [ {
"objectType" : "",
"objectName" : "",
"startIndex" : 8,
"stopIndex" : 17,
"fragment" : "rand(0.1F)"
} ]
}
```
--
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]