hudi icon indicating copy to clipboard operation
hudi copied to clipboard

Unable to write the Array with null values

Open sidnakoppa opened this issue 7 years ago • 8 comments

While saving this data of type Array i.e, revArray[null] to hudi The record is failing with null pointer exception.

In current use case the Array[null] is expected scenario. Could you please guide

sidnakoppa avatar Dec 29 '18 08:12 sidnakoppa

can you paste the schema or stacktrace to go on?

vinothchandar avatar Dec 31 '18 18:12 vinothchandar

ds_030001161010.select("at_unique_id","id","multicomp").printSchema root |-- at_unique_id: array (nullable = true) | |-- element: string (containsNull = true) |-- id: string (nullable = true) |-- multicomp: string (nullable = true)

scala> ds_030001161010.select("at_unique_id","id","multicomp").show

+------------+--------------+---------+
|at_unique_id|            id|multicomp|
+------------+--------------+---------+
|      [null]|030001161010  |KI00110T00|
+------------+--------------+---------+

scala> ds_030001161010.select("at_unique_id","id","multicomp").write.format("com.uber.hoodie").option(HoodieWriteConfig.TABLE_NAME,"hoodie_full_account").option(DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY,"id") .option(DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY, "multicomp").option(DataSourceWriteOptions.PRECOMBINE_FIELD_OPT_KEY, "multicomp").mode(SaveMode.Append).save("/apps/hive/warehouse/hoodie_full_account");

ERROR HoodieCreateHandle: Error writing record from HoodieRecord{key=HoodieKey { recordKey=030001161010 partitionPath=KI00110T00}, currentLocation='null', newLocation='null'} java.lang.NullPointerException at com.uber.hoodie.org.apache.parquet.avro.AvroWriteSupport.fromAvroString(AvroWriteSupport.java:281) at com.uber.hoodie.org.apache.parquet.avro.AvroWriteSupport.writeValue(AvroWriteSupport.java:260) at com.uber.hoodie.org.apache.parquet.avro.AvroWriteSupport.access$400(AvroWriteSupport.java:46) at com.uber.hoodie.org.apache.parquet.avro.AvroWriteSupport$TwoLevelListWriter.writeCollection(AvroWriteSupport.java:456) at com.uber.hoodie.org.apache.parquet.avro.AvroWriteSupport$ListWriter.writeList(AvroWriteSupport.java:305) at com.uber.hoodie.org.apache.parquet.avro.AvroWriteSupport.writeValue(AvroWriteSupport.java:266) at com.uber.hoodie.org.apache.parquet.avro.AvroWriteSupport.writeRecordFields(AvroWriteSupport.java:167) at com.uber.hoodie.org.apache.parquet.avro.AvroWriteSupport.write(AvroWriteSupport.java:142) at com.uber.hoodie.org.apache.parquet.hadoop.InternalParquetRecordWriter.write(InternalParquetRecordWriter.java:121) at com.uber.hoodie.org.apache.parquet.hadoop.ParquetWriter.write(ParquetWriter.java:288) at com.uber.hoodie.io.storage.HoodieParquetWriter.writeAvroWithMetadata(HoodieParquetWriter.java:90) at com.uber.hoodie.io.HoodieCreateHandle.write(HoodieCreateHandle.java:100) at com.uber.hoodie.func.CopyOnWriteLazyInsertIterable$CopyOnWriteInsertHandler.consumeOneRecord(CopyOnWriteLazyInsertIterable.java:146) at com.uber.hoodie.func.CopyOnWriteLazyInsertIterable$CopyOnWriteInsertHandler.consumeOneRecord(CopyOnWriteLazyInsertIterable.java:119) at com.uber.hoodie.common.util.queue.BoundedInMemoryQueueConsumer.consume(BoundedInMemoryQueueConsumer.java:38) at com.uber.hoodie.common.util.queue.BoundedInMemoryExecutor.lambda$null$2(BoundedInMemoryExecutor.java:124) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

sidnakoppa avatar Jan 01 '19 05:01 sidnakoppa

The

AvroConversionUtils.scala

can be edited to manage the datatypes/values thanks

sidnakoppa avatar Jan 07 '19 12:01 sidnakoppa

do you mind sharing your change? if its generally applicable, we can incorporate it back to the project @sidnakoppa

vinothchandar avatar Jan 11 '19 00:01 vinothchandar

We have not changed yet ,but the planned change is to mock the null String value to empty. To mock null for other types default to be determined. def createConverterToAvro:

case ArrayType(elementType, _) =>
val elementConverter = createConverterToAvro( elementType, structName, getNewRecordNamespace(elementType, recordNamespace, structName)) (item: Any) => { //check element type if string if (item == null) { "null" or "any default " } else { //existing flow } }

but put on hold as the date and timestamp types are converted to long.

sidnakoppa avatar Jan 11 '19 05:01 sidnakoppa

Hi , Just try changing the value of WRITE_OLD_LIST_STRUCTURE_DEFAULT parameter from true to false in AvroWriteSupport class. static final boolean WRITE_OLD_LIST_STRUCTURE_DEFAULT = false; It will allow array with null values.

anchalkataria avatar Aug 14 '19 18:08 anchalkataria

@anchalkataria interesting.. there also seems to be a flag to flip it? https://github.com/apache/parquet-mr/blob/master/parquet-avro/src/main/java/org/apache/parquet/avro/AvroWriteSupport.java#L60

vinothchandar avatar Aug 15 '19 12:08 vinothchandar

Closing due to inactivity

vinothchandar avatar Dec 02 '19 19:12 vinothchandar