y2ksayed opened a new pull request, #20334: URL: https://github.com/apache/hudi/pull/20334
## Summary Adds Delta Lake style `VERSION AS OF` time-travel support to Hudi Spark SQL, closing a long-standing parity gap: until now, any version-based time-travel query (`VERSION AS OF`, `FOR VERSION AS OF`, `SYSTEM_VERSION AS OF`, `FOR SYSTEM_VERSION AS OF`) was explicitly rejected with `HoodieAnalysisException: Version expression is not supported for time travel`. Only `TIMESTAMP AS OF` worked, which forces users to know exact commit timestamps. With this change: ```sql SELECT * FROM my_hudi_table VERSION AS OF 0; -- state as of the first commit SELECT * FROM my_hudi_table VERSION AS OF 2; -- state as of the third commit ``` ## Design - Versions are **0-indexed**, matching Delta Lake semantics: version 0 is the table's first completed commit, version 1 the second, and so on. - The version is resolved in `ResolveReferences` (`HoodieSparkBaseAnalysis`) by reading the table's active timeline via `HoodieTableMetaClient` and mapping the version to the Nth completed commit/delta-commit instant in timeline order. The resolved instant then flows through the existing `TIME_TRAVEL_AS_OF_INSTANT` read path, so all existing snapshot-query machinery is reused untouched. - Only integer literals are accepted as the version (a clear error is raised otherwise); negative versions and out-of-range versions fail fast with actionable messages. - Archived (cleaned) commits are not addressable by version; this is documented in the code. ## Changes - `hudi-spark-datasource/hudi-spark-common/.../analysis/HoodieSparkBaseAnalysis.scala`: replaced the version-travel rejection with version-to-instant resolution (`resolveVersionToInstant`); guard against specifying both timestamp and version. - `hudi-spark-datasource/hudi-spark/src/test/.../dml/others/TestTimeTravelTable.scala`: new test `Test version based time travel` covering all four version spellings, versions 0 and 1 snapshot correctness, plus out-of-range, negative, and non-literal version error cases. Removed the old assertion that version travel is rejected. ## Testing - New test coverage in `TestTimeTravelTable` as described above. - Existing `TIMESTAMP AS OF` tests are untouched and continue to pass through the same code path. -- 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]
