You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "rkwagner (via GitHub)" <gi...@apache.org> on 2025/04/28 20:49:56 UTC

[I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

rkwagner opened a new issue, #13233:
URL: https://github.com/apache/hudi/issues/13233

   **_Tips before filing an issue_**
   
   - Have you gone through our [FAQs](https://hudi.apache.org/learn/faq/)?
   
   - Join the mailing list to engage in conversations and get faster support at dev-subscribe@hudi.apache.org.
   
   - If you have triaged this as a bug, then file an [issue](https://issues.apache.org/jira/projects/HUDI/issues) directly.
   
   **Describe the problem you faced**
   
   When upgrading our stack from Hudi 0.14.0 to 0.15.0, writes on new tables with columns defined as `logicalType: timestamp-millis` are written into Parquet as `timestamp`, which in Spark defaults to `micro`.  This means data read as the Long 1720631224939 (meant to represent 2024-07-10) will instead write back into the parquet as a date in January, 1970.
   
   **To Reproduce**
   
   Steps to reproduce the behavior:
   
   1.  Start up a clean Spark Session with zero defined tables, as we want the DeltaStreamer to auto generate the schema based on a Schema provider.
   2. Using the provider, set the source schema as reading from a column which represents a long, and contains the above value.
   3. Set the target schema to use type of Long, with logicalType as timestamp-millis.
   4. Have the dataframe generated do no data casting or anything to this so that it translates directly from a Long to a timestamp, and check the generated Parquet data.
   
   **Expected behavior**
   
   Parquet should have the resultant data read as some form or analog of (timezones might change this by up to a day)  Wednesday, July 10, 2024 5:07:04 PM
   
   **Environment Description**
   
   * Hudi version : 0.15.0
   
   * Spark version : 3.5.2 (3.4.1 produces the same result)
   
   * Hive version :
   
   * Hadoop version : common config v 3.0
   
   * Storage (HDFS/S3/GCS..) : S3
   
   * Running on Docker? (yes/no) : local & EKS same result
   
   
   **Additional context**
   
   I noticed that in the Data Object, the source and destination Schemas were present as expected.  I just couldn't find anywhere to inspect the actual data to see if the Schemas from the provider actually got passed along into the Write.
   This was something one of us noticed earlier: When upgrading to Hudi 15, the writer will always seem to use Spark's default Timestamp type (microsecond representation) instead of whatever we were passing in.
   
   
   **Stacktrace**
   
   N/A
   
   


-- 
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: commits-unsubscribe@hudi.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

Posted by "rangareddy (via GitHub)" <gi...@apache.org>.
rangareddy commented on issue #13233:
URL: https://github.com/apache/hudi/issues/13233#issuecomment-2837678606

   Hi @rkwagner 
   
   Could you please share sample reproducible code so I can investigate further?


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

Posted by "rkwagner (via GitHub)" <gi...@apache.org>.
rkwagner commented on issue #13233:
URL: https://github.com/apache/hudi/issues/13233#issuecomment-2839505456

   I've also pasted this into Hudi Slack, but this is the line of code where the loss of differentiation between millis and micros occurs:
   https://github.com/apache/hudi/blob/master/hudi-common/src/main/java/org/apache/hudi/internal/schema/convert/AvroInternalSchemaConverter.java#L356


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

Posted by "rkwagner (via GitHub)" <gi...@apache.org>.
rkwagner commented on issue #13233:
URL: https://github.com/apache/hudi/issues/13233#issuecomment-2839738516

   As far as "how did this happen", it looks like the part of the `StreamSync` code which used to only come into play on Hudi 14 in the case where a user provided target schema wasn't present, but now that function appears to be called in all cases.  This function, `getDeducedSchemaProvider`, in turn calls `UtilHelpers.getLatestTableSchema` which will get nothing on the first write of the table since it doesn't exist yet.  Finally, this will result in the Hudi code overwriting whatever target schema we want (for timestamps specifically) to always write as micros. 


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

Posted by "rkwagner (via GitHub)" <gi...@apache.org>.
rkwagner commented on issue #13233:
URL: https://github.com/apache/hudi/issues/13233#issuecomment-2839461561

   Worth noting this means the bug is current.


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

Posted by "danny0405 (via GitHub)" <gi...@apache.org>.
danny0405 commented on issue #13233:
URL: https://github.com/apache/hudi/issues/13233#issuecomment-2837186311

   can you share with us the data type in your SQL statement and also the field type in `.hoodie/hoodie.properties` create table property.


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

Posted by "rkwagner (via GitHub)" <gi...@apache.org>.
rkwagner commented on issue #13233:
URL: https://github.com/apache/hudi/issues/13233#issuecomment-2859909913

   I actually do use `logicalType: timestamp-millis` in both actual files.  When I threw a debug point in, I saw that Hudi was able to see these files and their contents, but overwrite the values to TimestampType and later timestamp-micros at these lines since the table itself wasn't defined.
   
   Recasting from millis to TimestampType:
   https://github.com/apache/hudi/blob/master/hudi-common/src/main/java/org/apache/hudi/internal/schema/convert/AvroInternalSchemaConverter.java#L356
   
   After that, Recasting from TimestampType to Micros:
   https://github.com/apache/hudi/blob/master/hudi-common/src/main/java/org/apache/hudi/internal/schema/convert/AvroInternalSchemaConverter.java#L546


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

Posted by "rkwagner (via GitHub)" <gi...@apache.org>.
rkwagner commented on issue #13233:
URL: https://github.com/apache/hudi/issues/13233#issuecomment-2839460829

   I think I've identified the source.
   There is a class in Hudi called Type.java.  It has no concept in Timestamp of millis or micros,
    so all timestamps are always in micros if they pass through this class by way of the AvroInternalSchemaConverter, 
   which is called in HoodieSchemaUtils.deduceWriterSchema if latestTableSchema is undefined (it always will be with a brand new Table),
   further called in StreamSync.getDeducedSchemaProvider,
   called in fetchNextBatchFromSource,
   called in streamFromSource,
   called in sync
   which is the main function used by DeltaStreamers.


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

Posted by "codope (via GitHub)" <gi...@apache.org>.
codope commented on issue #13233:
URL: https://github.com/apache/hudi/issues/13233#issuecomment-2843898376

   @rkwagner do you have `hoodie.schema.on.read.enable` enabled? From my understanding, the internal schema converter code gets exercised when this config is turned on. But, maybe this changed recently. I will have to check the code. It would really help if you can share all the write configs.


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

Posted by "deepakpanda93 (via GitHub)" <gi...@apache.org>.
deepakpanda93 closed issue #13233: [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect
URL: https://github.com/apache/hudi/issues/13233


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

Posted by "codope (via GitHub)" <gi...@apache.org>.
codope commented on issue #13233:
URL: https://github.com/apache/hudi/issues/13233#issuecomment-2845085241

   I can repro using the following script:
   ```
   wget https://repo1.maven.org/maven2/org/apache/hudi/hudi-utilities-bundle_2.12/0.15.0/hudi-utilities-bundle_2.12-0.15.0.jar
   
   mkdir -p /tmp/hudi_ts/{input,schema}
   cat <<EOF > /tmp/hudi_ts/input/data.json
   {"id": 1, "ts": 1720631224939}
   EOF
   
   
   cat <<EOF > /tmp/hudi_ts/schema/source.avsc
   {
     "type":"record","name":"Src",
     "fields":[
       {"name":"id","type":"long"},
       {"name":"ts","type":"long"}
     ]
   }
   EOF
   
   
   cat <<EOF > /tmp/hudi_ts/schema/target.avsc
   {
     "type":"record","name":"Tgt",
     "fields":[
       {"name":"id","type":"long"},
       {
         "name":"ts",
         "type":{
           "type":"long",
           "logicalType":"timestamp-millis"
         }
       }
     ]
   }
   EOF
   
   ./bin/spark-submit --jars ~/hudi/packaging/hudi-spark-bundle/target/hudi-spark3.5-bundle_2.12-1.1.0-SNAPSHOT.jar \
     --class org.apache.hudi.utilities.streamer.HoodieStreamer  ~/hudi/packaging/hudi-utilities-bundle/target/hudi-utilities-bundle_2.12-1.1.0-SNAPSHOT.jar \
     --table-type COPY_ON_WRITE \
     --source-class org.apache.hudi.utilities.sources.JsonDFSSource \
     --target-base-path file:///tmp/hudi_ts/output \
     --target-table ts_test \
     --schemaprovider-class org.apache.hudi.utilities.schema.FilebasedSchemaProvider \
     --source-ordering-field ts \
     --op UPSERT \
     --hoodie-conf hoodie.datasource.write.recordkey.field=id \
     --hoodie-conf hoodie.streamer.schemaprovider.source.schema.file=file:///tmp/hudi_ts/schema/source.avsc \
     --hoodie-conf hoodie.streamer.schemaprovider.target.schema.file=file:///tmp/hudi_ts/schema/target.avsc \
     --hoodie-conf hoodie.streamer.source.dfs.root=file:///tmp/hudi_ts/input
   ```
   
   The results when reading the data:
   ```
   ./bin/spark-shell --jars ~/hudi/packaging/hudi-spark-bundle/target/hudi-spark3.5-bundle_2.12-1.1.0-SNAPSHOT.jar \
   --conf 'spark.serializer=org.apache.spark.serializer.KryoSerializer' \
   --conf 'spark.sql.catalog.spark_catalog=org.apache.spark.sql.hudi.catalog.HoodieCatalog' \
   --conf 'spark.sql.extensions=org.apache.spark.sql.hudi.HoodieSparkSessionExtension' \
   --conf 'spark.kryo.registrator=org.apache.spark.HoodieSparkKryoRegistrar'
   
   
   val df = spark.read.parquet("file:///tmp/hudi_ts/output/")
   df.show(false)
   
   +-------------------+---------------------+------------------+----------------------+------------------------------------------------------------------------+---+--------------------------+
   |_hoodie_commit_time|_hoodie_commit_seqno |_hoodie_record_key|_hoodie_partition_path|_hoodie_file_name                                                       |id |ts                        |
   +-------------------+---------------------+------------------+----------------------+------------------------------------------------------------------------+---+--------------------------+
   |20250501133107326  |20250501133107326_0_0|1                 |                      |e0c06561-5b2a-45f3-ad07-f1d4bf650a56-0_0-26-29_20250501133107326.parquet|1  |1970-01-21 03:27:11.224939|
   +-------------------+---------------------+------------------+----------------------+------------------------------------------------------------------------+---+--------------------------+
   
   val hudiDf = spark.read.format("hudi").load("file:///tmp/hudi_ts/output/")
   hudiDf.show(false)
   
   +-------------------+---------------------+------------------+----------------------+------------------------------------------------------------------------+---+--------------------------+
   |_hoodie_commit_time|_hoodie_commit_seqno |_hoodie_record_key|_hoodie_partition_path|_hoodie_file_name                                                       |id |ts                        |
   +-------------------+---------------------+------------------+----------------------+------------------------------------------------------------------------+---+--------------------------+
   |20250501133107326  |20250501133107326_0_0|1                 |                      |e0c06561-5b2a-45f3-ad07-f1d4bf650a56-0_0-26-29_20250501133107326.parquet|1  |1970-01-21 03:27:11.224939|
   +-------------------+---------------------+------------------+----------------------+------------------------------------------------------------------------+---+--------------------------+
   
   
   scala> df.selectExpr("cast(ts as long) as raw_ts").show(false)
   +-------+
   |raw_ts |
   +-------+
   |1720631|
   +-------+
   ```
   
   Note that the long value in parquet file itself is correct. Schema is incorrect.
   ```
   (base) sagars@Sagars-MacBook-Pro spark-3.5.2-bin-hadoop3 % parquet-tools cat /tmp/hudi_ts/output/e0c06561-5b2a-45f3-ad07-f1d4bf650a56-0_0-26-29_20250501133107326.parquet
   _hoodie_commit_time = 20250501133107326
   _hoodie_commit_seqno = 20250501133107326_0_0
   _hoodie_record_key = 1
   _hoodie_partition_path =
   _hoodie_file_name = e0c06561-5b2a-45f3-ad07-f1d4bf650a56-0_0-26-29_20250501133107326.parquet
   id = 1
   ts = 1720631224939
   
   (base) sagars@Sagars-MacBook-Pro spark-3.5.2-bin-hadoop3 % parquet-tools schema /tmp/hudi_ts/output/e0c06561-5b2a-45f3-ad07-f1d4bf650a56-0_0-26-29_20250501133107326.parquet
   message Tgt {
     optional binary _hoodie_commit_time (STRING);
     optional binary _hoodie_commit_seqno (STRING);
     optional binary _hoodie_record_key (STRING);
     optional binary _hoodie_partition_path (STRING);
     optional binary _hoodie_file_name (STRING);
     required int64 id;
     required int64 ts (TIMESTAMP(MICROS,true));
   }
   ```
   


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

Posted by "codope (via GitHub)" <gi...@apache.org>.
codope commented on issue #13233:
URL: https://github.com/apache/hudi/issues/13233#issuecomment-2845145442

   As workaround maybe you could try giving the same logical type in source and target schema files.


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [SUPPORT] Hudi 0.15.0 Timestamp Write Precision Incorrect [hudi]

Posted by "rkwagner (via GitHub)" <gi...@apache.org>.
rkwagner commented on issue #13233:
URL: https://github.com/apache/hudi/issues/13233#issuecomment-2864220578

   What looks like happens is this:
   https://github.com/apache/hudi/blob/master/hudi-utilities/src/main/java/org/apache/hudi/utilities/streamer/StreamSync.java#L766
   
   Then infers that the target schema is a source schema rather than a target, which in turn calls this: 
   https://github.com/apache/hudi/blob/master/hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/HoodieSchemaUtils.scala#L110
   
   Which, just looking at the variable naming shows the issue.  This function call is taking the target schema and demoting it to the source schema, then promoting all data types to micros regardless of the write parameters the user sets.


-- 
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: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org