[SUPPORT] Hudi upsert fails with java.lang.ClassCastException: optional binary xx (STRING) is not a group
Describe the problem you faced
Getting java.lang.ClassCastException: optional binary xx (STRING) exception when a record get updated.
Also this issue specifically happening when a field is array of structs with one field.
But the issue is not happening when array of structs have more than one field.
To Reproduce
Steps to reproduce the behavior:
launch spark-shell
./spark-shell --conf "spark.serializer=org.apache.spark.serializer.KryoSerializer" \
--conf "spark.sql.hive.convertMetastoreParquet=false" \
--jars $HOME/.m2/repository/org/apache/hudi/hudi-spark3-bundle_2.12/0.10.0/hudi-spark3-bundle_2.12-0.10.0.jar,$HOME/.m2/repository/org/apache/spark/spark-avro_2.12/3.2.0/spark-avro_2.12-3.2.0.jar
import org.apache.hudi.QuickstartUtils._
import scala.collection.JavaConversions._
import org.apache.spark.sql.SaveMode._
import org.apache.hudi.DataSourceReadOptions._
import org.apache.hudi.DataSourceWriteOptions._
import org.apache.hudi.config.HoodieWriteConfig._
import org.apache.spark.sql.types._
import org.apache.spark.sql.Row
val tableName = "hudi_cow"
val basePath = "/tmp/hudi_cow"
val schema = StructType( Array(
| StructField("rowId", StringType,true),
| StructField("preComb", LongType,true),
| StructField("name", StringType,true),
| StructField("valObjs", ArrayType(StructType(Array(
| StructField("id", StringType)
| ))))
| ))
val data1 = Seq(Row("row_1", 0L, "test", Array()),
| Row("row_2", 0L, "test", Array()),
| Row("row_3", 0L, "test", Array()))
var dfFromData1 = spark.createDataFrame(data1, schema)
dfFromData1.printSchema
dfFromData1.show
dfFromData1.write.format("hudi").
| option(PRECOMBINE_FIELD_OPT_KEY, "preComb").
| option(RECORDKEY_FIELD_OPT_KEY, "rowId").
| option(TABLE_NAME, tableName).
| mode(Overwrite).
| save(basePath)
var snapshotDF1 = spark.read.format("hudi").load(basePath + "/*")
snapshotDF1.createOrReplaceTempView("hudi_snapshot")
spark.sql("select rowId, preComb, name from hudi_snapshot").show()
dfFromData1.write.format("hudi").
| options(getQuickstartWriteConfigs).
| option(PRECOMBINE_FIELD_OPT_KEY, "preComb").
| option(RECORDKEY_FIELD_OPT_KEY, "rowId").
| option(TABLE_NAME, tableName).
| mode(Append).
| save(basePath)
when updating records (second save) hudi throwing
22/06/27 14:56:41 ERROR BoundedInMemoryExecutor: error producing records
org.apache.hudi.exception.HoodieException: unable to read next record from parquet file
at org.apache.hudi.common.util.ParquetReaderIterator.hasNext(ParquetReaderIterator.java:54)
at org.apache.hudi.common.util.queue.IteratorBasedQueueProducer.produce(IteratorBasedQueueProducer.java:45)
at org.apache.hudi.common.util.queue.BoundedInMemoryExecutor.lambda$null$0(BoundedInMemoryExecutor.java:92)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
Caused by: java.lang.ClassCastException: optional binary id (STRING) is not a group
at org.apache.parquet.schema.Type.asGroupType(Type.java:248)
at org.apache.parquet.avro.AvroRecordConverter.newConverter(AvroRecordConverter.java:279)
at org.apache.parquet.avro.AvroRecordConverter.newConverter(AvroRecordConverter.java:232)
at org.apache.parquet.avro.AvroRecordConverter.access$100(AvroRecordConverter.java:78)
at org.apache.parquet.avro.AvroRecordConverter$AvroCollectionConverter$ElementConverter.<init>(AvroRecordConverter.java:536)
at org.apache.parquet.avro.AvroRecordConverter$AvroCollectionConverter.<init>(AvroRecordConverter.java:486)
at org.apache.parquet.avro.AvroRecordConverter.newConverter(AvroRecordConverter.java:289)
at org.apache.parquet.avro.AvroRecordConverter.<init>(AvroRecordConverter.java:141)
at org.apache.parquet.avro.AvroRecordConverter.<init>(AvroRecordConverter.java:95)
at org.apache.parquet.avro.AvroRecordMaterializer.<init>(AvroRecordMaterializer.java:33)
at org.apache.parquet.avro.AvroReadSupport.prepareForRead(AvroReadSupport.java:138)
at org.apache.parquet.hadoop.InternalParquetRecordReader.initialize(InternalParquetRecordReader.java:185)
at org.apache.parquet.hadoop.ParquetReader.initReader(ParquetReader.java:156)
at org.apache.parquet.hadoop.ParquetReader.read(ParquetReader.java:135)
at org.apache.hudi.common.util.ParquetReaderIterator.hasNext(ParquetReaderIterator.java:49)
... 8 more
weird thing is if we have more than one field in that array of structs field (valObjs), update works. for example this schema works with above example, please note added secondid field to valObjs
val schema = StructType( Array(
| StructField("rowId", StringType,true),
| StructField("preComb", LongType,true),
| StructField("name", StringType,true),
| StructField("valObjs", ArrayType(StructType(Array(
| StructField("id", StringType),
| StructField("secondid", StringType)
| ))))
| ))
Expected behavior
Update should work.
Environment Description
-
Hudi version : 0.10.1 & 0.11.1
-
Spark version : 3.2.0
-
Hadoop version : 2.7
-
Storage (HDFS/S3/GCS..) : Tested using local spark-shell and in emr
-
Running on Docker? (yes/no) : No. Running In Mac, also same error in EMR 6.6.0
@phillycoder Thanks for reporting the issue. I'll reproduce this on my end. Are you migrating from an older Hudi version that worked for the same upsert scenario?
We didn't use any older version for this project, so I am not sure if this worked with older version. we only started using version 0.10.1 version recently for our new project since it's been supported by EMR 6.6.0. Thanks for looking into it. Let me know if you need more details. I can try this same test with older Hudi version and let you know.
I am able to duplicate same issue in EMR 6.5.0 which comes with hudi 0.9.0
cc @minihippo
It's related to the Avro implementations. @fengjian428 It's the same problems that u are meeting, right? Could u give a workaround?
I have found an 'Avro field array not found' issue which is caused by ParquetReader can't read struct that only has one array type field. this is a bug of Parquet-Avro can not be fixed in Hudi. and the workaround is to add a dummy field into the struct. I'm not very sure you are facing the same issue but you can also give it a try @phillycoder
@fengjian428 Thanks for the update. Yes as I mentioned in my original post if I add a dummy field to that struct in the array, then the update works. Do you have link of GitHub issue or any reference to this Parquet-Avro bug?
@phillycoder this one https://issues.apache.org/jira/browse/PARQUET-1254
Thanks for looking into it. @fengjian428 @minihippo @yihua
Since this issue related to parquet-avro module and cannot be fixed in hudi, i close this issue.