aokolnychyi commented on PR #40206:
URL: https://github.com/apache/spark/pull/40206#issuecomment-1447651920

   @cloud-fan, are thinking of passing raw types all the way? I actually 
considered that but my worry was we will have to modify `checkField` casting 
logic as it seems we can't use the raw type there.
   
   ```
     private def checkField(
         tableAttr: Attribute,
         queryExpr: NamedExpression,
         byName: Boolean,
         conf: SQLConf,
         addError: String => Unit,
         colPath: Seq[String]): Option[NamedExpression] = {
   
       val storeAssignmentPolicy = conf.storeAssignmentPolicy
       lazy val outputField = if 
(tableAttr.dataType.sameType(queryExpr.dataType) &&
         tableAttr.name == queryExpr.name &&
         tableAttr.metadata == queryExpr.metadata) {
         Some(queryExpr)
       } else {
         val casted = storeAssignmentPolicy match {
           case StoreAssignmentPolicy.ANSI =>
             val cast = Cast(queryExpr, tableAttr.dataType, 
Option(conf.sessionLocalTimeZone),
               ansiEnabled = true)
             cast.setTagValue(Cast.BY_TABLE_INSERTION, ())
             checkCastOverflowInTableInsert(cast, colPath.quoted)
           case StoreAssignmentPolicy.LEGACY =>
             Cast(queryExpr, tableAttr.dataType, 
Option(conf.sessionLocalTimeZone),
               ansiEnabled = false)
           case _ =>
             Cast(queryExpr, tableAttr.dataType, 
Option(conf.sessionLocalTimeZone))
         }
         val exprWithStrLenCheck = if (conf.charVarcharAsString) {
           casted
         } else {
           CharVarcharUtils.stringLengthCheck(casted, tableAttr)
         }
         // Renaming is needed for handling the following cases like
         // 1) Column names/types do not match, e.g., INSERT INTO TABLE tab1 
SELECT 1, 2
         // 2) Target tables have column metadata
         Some(Alias(exprWithStrLenCheck, tableAttr.name)(explicitMetadata = 
Some(tableAttr.metadata)))
       }
   
       storeAssignmentPolicy match {
         case StoreAssignmentPolicy.LEGACY =>
           outputField
   
         case StoreAssignmentPolicy.STRICT | StoreAssignmentPolicy.ANSI =>
           // run the type check first to ensure type errors are present
           val canWrite = DataType.canWrite(
             queryExpr.dataType, tableAttr.dataType, byName, conf.resolver, 
colPath.quoted,
             storeAssignmentPolicy, addError)
           if (queryExpr.nullable && !tableAttr.nullable) {
             addError(s"Cannot write nullable values to non-null column 
'${colPath.quoted}'")
             None
   
           } else if (!canWrite) {
             None
   
           } else {
             outputField
           }
       }
     }
   ```


-- 
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]

Reply via email to