hudi icon indicating copy to clipboard operation
hudi copied to clipboard

Date type converted to long

Open sidnakoppa opened this issue 7 years ago • 6 comments

I have saved the data of ordered_date But while retrieving I am getting the ordered_date as long type Though the dataset field is of type Date the hudi is treating it as long when ds.write.format is performed

Could you guide in saving the Date by preserving the type

sidnakoppa avatar Dec 29 '18 08:12 sidnakoppa

You can not preserve the type without changing the source code. You can check HoodieSparkSqlWriter -> val schema = AvroConversionUtils.convertStructTypeToAvroSchema(df.schema, structName, nameSpace) which used spark-avro package.

louisliu318 avatar Dec 29 '18 09:12 louisliu318

Thanks for the reply. So there is no support for saving Date or TimeStamp type in hudi?

PFB the datatype in Dataset before writing to hudi and after reading the data from hudi

Field --- date_last_cr_cust

*******Before saving ******

scala> data_to_be_written.select("date_last_cr_cust").printSchema

root |-- date_last_cr_cust: date (nullable = true)

When the saved data is read from HDFS**

 spark.read.format("com.uber.hoodie").load("/apps/hive/warehouse/hoodie_full_account/KI0010200/*")
 .select("date_last_cr_cust").
  printSchema

root |-- date_last_cr_cust: long (nullable = true)

sidnakoppa avatar Jan 01 '19 13:01 sidnakoppa

@sidnakoppa look this https://github.com/uber/hudi/issues/517#issuecomment-448506773 I also found this question. I changed some code in spark-avro and then it transed to LogicalType. But in Hive 1.2.1, Hive still think it is longType(LogicalType is an ubattribute under base type like long, so Hive recognize it to long). In Hive 1.2.1's lib, Hive use parquet 1.6, date/timestamp/decimal are supported in avro1.8 and parquet1.8.

cdmikechen avatar Jan 02 '19 01:01 cdmikechen

By the way, In parquet 1.8 or earlier, it doesn't have date type. It just has int96(nanotime type) and stores as bytes. If you want a long type date, you can use getTime() to save a long, and read by using timestamp function to trans to timestamp type(build like this optional int64 timestamp (TIMESTAMP_MILLIS);).

cdmikechen avatar Jan 02 '19 09:01 cdmikechen

@sidnakoppa , please follow #547 .. We can follow up there, with all the great analysis @cdmikechen has done already..

Separately, I recommend upgrading to Hive 2.x as much as possible. Speaking from experience at Uber, we had to deal with so many issues on Hive 1.x around schema evolution/data types, since parquet support was pretty raw back then... Is this something that's feasible for you? (all cloud stores for e.g, spin up Hive 2.x by default)

vinothchandar avatar Jan 11 '19 22:01 vinothchandar

add a comment in https://issues.apache.org/jira/browse/HUDI-91

cdmikechen avatar Jun 24 '19 01:06 cdmikechen