Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-49987][SQL] Fix the error prompt when seedExpression is non-foldable in randstr #48490

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.apache.spark.SparkException
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry, TypeCheckResult, UnresolvedSeed}
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.DataTypeMismatch
import org.apache.spark.sql.catalyst.expressions.ExpectsInputTypes.{ordinalNumber, toSQLExpr, toSQLType}
import org.apache.spark.sql.catalyst.expressions.ExpectsInputTypes.{ordinalNumber, toSQLExpr, toSQLId, toSQLType}
import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, CodeGenerator, ExprCode, FalseLiteral}
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
import org.apache.spark.sql.catalyst.trees.{BinaryLike, TernaryLike, UnaryLike}
Expand Down Expand Up @@ -263,7 +263,7 @@ case class Uniform(min: Expression, max: Expression, seedExpression: Expression,
result = DataTypeMismatch(
errorSubClass = "NON_FOLDABLE_INPUT",
messageParameters = Map(
"inputName" -> name,
"inputName" -> toSQLId(name),
"inputType" -> requiredType,
"inputExpr" -> toSQLExpr(expr)))
} else expr.dataType match {
Expand Down Expand Up @@ -374,14 +374,14 @@ case class RandStr(
var result: TypeCheckResult = TypeCheckResult.TypeCheckSuccess
def requiredType = "INT or SMALLINT"
Seq((length, "length", 0),
(seedExpression, "seedExpression", 1)).foreach {
(seedExpression, "seed", 1)).foreach {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is an id, could you quote it using to toSQLId(), please at:

                "inputName" -> toSQLId(name),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this, let me update Uniform's name in this PR as well:

case (expr: Expression, name: String, index: Int) =>
if (result == TypeCheckResult.TypeCheckSuccess) {
if (!expr.foldable) {
result = DataTypeMismatch(
errorSubClass = "NON_FOLDABLE_INPUT",
messageParameters = Map(
"inputName" -> name,
"inputName" -> toSQLId(name),
"inputType" -> requiredType,
"inputExpr" -> toSQLExpr(expr)))
} else expr.dataType match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException
"sqlState" : "42K09",
"messageParameters" : {
"inputExpr" : "\"col\"",
"inputName" : "seed",
"inputName" : "`seed`",
"inputType" : "integer or floating-point",
"sqlExpr" : "\"uniform(10, 20, col)\""
},
Expand All @@ -211,7 +211,7 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException
"sqlState" : "42K09",
"messageParameters" : {
"inputExpr" : "\"col\"",
"inputName" : "min",
"inputName" : "`min`",
"inputType" : "integer or floating-point",
"sqlExpr" : "\"uniform(col, 10, 0)\""
},
Expand Down Expand Up @@ -436,7 +436,7 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException
"sqlState" : "42K09",
"messageParameters" : {
"inputExpr" : "\"col\"",
"inputName" : "length",
"inputName" : "`length`",
"inputType" : "INT or SMALLINT",
"sqlExpr" : "\"randstr(col, 0)\""
},
Expand All @@ -459,7 +459,7 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException
"sqlState" : "42K09",
"messageParameters" : {
"inputExpr" : "\"col\"",
"inputName" : "seedExpression",
"inputName" : "`seed`",
"inputType" : "INT or SMALLINT",
"sqlExpr" : "\"randstr(10, col)\""
},
Expand Down
8 changes: 4 additions & 4 deletions sql/core/src/test/resources/sql-tests/results/random.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException
"sqlState" : "42K09",
"messageParameters" : {
"inputExpr" : "\"col\"",
"inputName" : "seed",
"inputName" : "`seed`",
"inputType" : "integer or floating-point",
"sqlExpr" : "\"uniform(10, 20, col)\""
},
Expand All @@ -265,7 +265,7 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException
"sqlState" : "42K09",
"messageParameters" : {
"inputExpr" : "\"col\"",
"inputName" : "min",
"inputName" : "`min`",
"inputType" : "integer or floating-point",
"sqlExpr" : "\"uniform(col, 10, 0)\""
},
Expand Down Expand Up @@ -520,7 +520,7 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException
"sqlState" : "42K09",
"messageParameters" : {
"inputExpr" : "\"col\"",
"inputName" : "length",
"inputName" : "`length`",
"inputType" : "INT or SMALLINT",
"sqlExpr" : "\"randstr(col, 0)\""
},
Expand All @@ -545,7 +545,7 @@ org.apache.spark.sql.catalyst.ExtendedAnalysisException
"sqlState" : "42K09",
"messageParameters" : {
"inputExpr" : "\"col\"",
"inputName" : "seedExpression",
"inputName" : "`seed`",
"inputType" : "INT or SMALLINT",
"sqlExpr" : "\"randstr(10, col)\""
},
Expand Down