dejankrak-db commented on code in PR #56238:
URL: https://github.com/apache/spark/pull/56238#discussion_r3337905789
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TableOutputResolver.scala:
##########
@@ -327,7 +327,25 @@ object TableOutputResolver extends SQLConfHelper with
Logging {
tableName, newColPath.quoted
)
}
- Some(applyColumnMetadata(defaultExpr.get, expectedCol))
+ // Apply CHAR/VARCHAR length check to the default expression so that
non-foldable
+ // defaults (e.g. current_user()) that exceed the column length are
caught at runtime.
+ // Uses getRawType so it works for both V1 and V2 tables.
+ val checkedExpr = defaultExpr.map { expr =>
+ val rawType = CharVarcharUtils.getRawType(expectedCol.metadata)
+ .getOrElse(expectedCol.dataType)
+ if (!conf.charVarcharAsString &&
CharVarcharUtils.hasCharVarchar(rawType)) {
+ expr match {
+ case a: Alias =>
+ a.copy(child = CharVarcharUtils.stringLengthCheck(a.child,
rawType))(
Review Comment:
Dead code collapsed - the helper drops the pointless Alias-field
preservation (`applyColumnMetadata` strips + re-wraps anyway) and the dead case
other branch; it just wraps the default's value with stringLengthCheck
--
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]