parisni commented on PR #9071:
URL: https://github.com/apache/hudi/pull/9071#issuecomment-1623460500

   Hi @CTTY ,
   I ran your script and reproduced the error on athena v3, which is:
   ```
   HIVE_PARTITION_SCHEMA_MISMATCH: There is a mismatch between the table and 
partition schemas. The types are incompatible and cannot be coerced. The column 
'accountqueues' in table 'default.test_hudi_table_362' is declared as type 
'array<struct<estimateddequeuetime:bigint,estimatedtimeinqueue:bigint,senderenqueuingattempts:array<struct<arenafrom:string,arenato:string,delay:bigint,outcome:string,queuefrom:string,queuefromlength:int,queueto:string,reason:string,shardid:string>>>>',
 but partition 'type=1' declared column 'accountqueues' as type 
'array<struct<estimateddequeuetime:bigint,estimatedtimeinqueue:bigint,senderenqueuingattempts:array<struct<delay:bigint,outcome:string,queuefromlength:int,shardid:string>>>>'.
   ```
   
   I also tried to reproduce the error (see below script), and what I can tell  
the error **only** triggers when new fields in struct are added, changing the 
existing order. 
   
   I have added several comments on your PR accordingly
   
   ```
   from pyspark.sql.types import StructType, StructField, StringType, 
IntegerType
   data = [
           {"uuid":1, "user_id":"f5c2ebfd-f57b-4ff3-ac5c-f30674037b21", "mp": 
{"col1":"foo"}, "ts":"BC", "part":"C"},
           {"uuid":1, "user_id":"f5c2ebfd-f57b-4ff3-ac5c-f30674037b21", "mp": 
{"col1":"foo"}, "ts":"BC", "part":"D"},
   ]
   
   schema = StructType(
       [
           StructField("uuid", IntegerType(), True),
           StructField("user_id", StringType(), True),
           StructField(
               "mp",
               StructType([StructField("col1", StringType(), True)])
           ),
           StructField("ts", StringType(), True),
           StructField("part", StringType(), True),
       ]
   )
   df = spark.createDataFrame(data=data, schema=schema)
   
   bucket = ...
   tableName = "test_hudi_aws_part"
   basePath = f"s3://"+bucket+"/test/" + tableName
   
   hudi_options = {
       "hoodie.table.name": tableName,
       "hoodie.datasource.write.recordkey.field": "uuid",
       "hoodie.datasource.write.partitionpath.field": "part",
       "hoodie.datasource.write.table.name": tableName,
       "hoodie.datasource.write.operation": "upsert",
       "hoodie.datasource.write.precombine.field": "ts",
       "hoodie.upsert.shuffle.parallelism": 2,
       "hoodie.insert.shuffle.parallelism": 2,
       "hoodie.datasource.hive_sync.enable": "true",
       "hoodie.datasource.hive_sync.database": "default",
       "hoodie.datasource.hive_sync.table": tableName,
       "hoodie.datasource.hive_sync.mode": "jdbc",
       "hoodie.meta.sync.client.tool.class": 
"org.apache.hudi.aws.sync.AwsGlueCatalogSyncTool",
       "hoodie.datasource.hive_sync.partition_fields": "part",
       "hoodie.datasource.hive_sync.partition_extractor_class": 
"org.apache.hudi.hive.MultiPartKeysValueExtractor",
   }
   
(df.write.format("hudi").options(**hudi_options).mode("overwrite").save(basePath))
   
   # this works fine
   spark.table("default."+tableName).show()
   
   # Now evolve part
   data = [
           {"uuid":1, "user_id":"f5c2ebfd-f57b-4ff3-ac5c-f30674037b21", "mp": 
{"col1":"foo", "new_col":"bar"}, "ts":"BC", "part":"C"},
   ]
   
   schema = StructType(
       [
           StructField("uuid", IntegerType(), True),
           StructField("user_id", StringType(), True),
           StructField(
               "mp",
   # fail when order change   StructType([StructField("new_col", StringType(), 
True), StructField("col1", StringType(), True)])
               StructType([StructField("col1", StringType(), True), 
StructField("new_col", StringType(), True)])
           ),
           StructField("ts", StringType(), True),
           StructField("part", StringType(), True),
       ]
   )
   df = spark.createDataFrame(data=data, schema=schema)
   
(df.write.format("hudi").options(**hudi_options).mode("append").save(basePath))
   spark.table("default."+tableName).show()
   # HIVE_PARTITION_SCHEMA_MISMATCH: There is a mismatch between the table and 
partition schemas. The types are incompatible and cannot be coerced. The column 
'mp' in table 'default.test_hudi_aws_part' is declared as type 
'struct<new_col:string,col1:string>', but partition 'part=C' declared column 
'mp' as type 'struct<col1:string>'.
   
   ```


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