rahil-c commented on code in PR #18540:
URL: https://github.com/apache/hudi/pull/18540#discussion_r3143723485


##########
hudi-client/hudi-spark-client/src/main/scala/org/apache/spark/sql/avro/HoodieSparkSchemaConverters.scala:
##########
@@ -278,10 +282,22 @@ object HoodieSparkSchemaConverters extends 
SparkAdapterSupport {
             metadataBuilder.putString(HoodieSchema.TYPE_METADATA_FIELD, 
HoodieSchema.Blob.TYPE_DESCRIPTOR)
           }
           val metadata = metadataBuilder.build()
-          StructField(f.name(), schemaType.dataType, schemaType.nullable, 
metadata)
+          // For BLOB: force nullable-everywhere at the Spark type layer. The 
RFC-100
+          // canonical schema declares `type`, `reference.external_path`, and
+          // `reference.managed` as strictly non-null, but that contract is 
conditional
+          // ("required when parent is present") and Spark's type system can't 
model it.
+          // Projecting BLOB as nullable-everywhere for Spark avoids 
downstream pain
+          // (Cast / TableOutputResolver / Cast.canCast rewrites); the on-disk 
physical
+          // schema stays RFC-100 compliant because the write path goes through
+          // HoodieSchema.Blob.createBlob(), which uses the canonical fields 
verbatim.
+          if (isBlob) {
+            StructField(f.name(), withAllFieldsNullable(schemaType.dataType), 
nullable = true, metadata)

Review Comment:
   @voonhous @yihua Does the change for now mean that then users can provide 
something like this, where user can pass null type?
   
   ```
     ▎ CREATE TABLE blob_t (id BIGINT, payload BLOB) USING hudi                 
         
     ▎   TBLPROPERTIES (primaryKey = 'id');
     ▎                                                                          
         
     ▎ -- type=null: Spark side BLOB.type is now nullable, so analysis passes.  
         
     ▎ -- Avro side BLOB.type is the non-null enum {INLINE, OUT_OF_LINE} → 
fails at      
     ▎ encode.                                                                  
         
     ▎ INSERT INTO blob_t VALUES (
     ▎   1,                                                                     
         
     ▎   named_struct(
     ▎     'type', cast(null as string),
     ▎     'data', cast(X'010203' as binary),
     ▎     'reference', cast(null as                                            
         
     ▎ 
struct<external_path:string,offset:bigint,length:bigint,managed:boolean>)       
  
     ▎   )  
   ```



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

Reply via email to