dtenedor commented on code in PR #46594:
URL: https://github.com/apache/spark/pull/46594#discussion_r1624934239
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/statements.scala:
##########
@@ -142,9 +143,16 @@ case class QualifiedColType(
def getV2Default: ColumnDefaultValue = {
default.map { sql =>
val e = ResolveDefaultColumns.analyze(colName, dataType, sql, "ALTER
TABLE")
- assert(e.resolved && e.foldable,
- "The existence default value must be a simple SQL string that is
resolved and foldable, " +
- "but got: " + sql)
+ if (!e.resolved || !e.foldable) {
Review Comment:
Hey so I looked at this code with Wenchen in detail.
Ultimately, we should not hit his assertion error ever. This happens at
querying time, if any expression other than a literal value is stored in the
column existence default metadata. This should never happen.
Instead, we should return a proper error message earlier here [1], when we
try to run the ALTER TABLE ADD COLUMN command with a default value that we
cannot constant-fold.
I can make a more involved fix later; for now, can you just update that
location [1] to add a check if the result of the `ConstantFolding` is not a
literal? It be something like:
```
ConstantFolding(ReplaceExpressions(analyzed)) match {
case e: Literal => e
case _ =>
throw new AnalysisException(
errorClass = "COLUMN_DEFAULT_EXPRESSION_NOT_SUPPORTED",
...)
}
```
This error class can have some message to indicate that the requested
expression for the column default value is not supported by Spark, and the user
should use a different expression there or remove the default entirely and then
retry the command again.
[1]
https://github.com/apache/spark/blob/5baaa615ef852c2032342c5986b4aa15ccf74b25/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/ResolveDefaultColumnsUtil.scala#L292
--
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]