Skip to content

[HUDI-1610] Add SCALAR timestamp type coverage to TestCOWDataSource - #19945

Open
nanjeshramesh wants to merge 1 commit into
apache:masterfrom
nanjeshramesh:timestamp-keygen-cow-tests
Open

nanjeshramesh wants to merge 1 commit into
apache:masterfrom
nanjeshramesh:timestamp-keygen-cow-tests

Conversation

@nanjeshramesh

Copy link
Copy Markdown

Describe the issue this Pull Request addresses

Closes #14753.

PR #2431 added support for using Spark SQL's partitionBy() clause with TimestampBasedKeyGenerator, and minimal tests were added to TestCOWDataSource for it, but the issue asks for more coverage with respect to the timestamp based key gen than what exists there today.

Summary and Changelog

Adds testSparkPartitionByWithTimestampBasedKeyGeneratorScalar, covering the SCALAR timestamp type with an explicit INPUT_TIME_UNIT. This exercises a genuinely different code path in TimestampBasedAvroKeyGenerator than the existing EPOCHMILLISECONDS test right above it: SCALAR treats the field as a raw numeric value that needs an explicit unit to convert to a timestamp, rather than the unit being implied by the type name.

TestTimestampBasedKeyGenerator already unit-tests SCALAR at the key generator layer directly, but that does not exercise the Spark DataFrame write path, config option plumbing, and partition path resolution together the way this test class does for the other timestamp types, so this closes a real gap specific to TestCOWDataSource.

The new test mirrors the existing testSparkPartitionByWithTimestampBasedKeyGenerator immediately above it: same data, same assertion shape, same parameterization over AVRO/SPARK record types. Since current_ts is generated in epoch milliseconds, SCALAR with INPUT_TIME_UNIT=MILLISECONDS is expected to partition identically to the existing EPOCHMILLISECONDS test, which the assertion confirms.

Impact

None. Test-only change, no production code touched.

Risk Level

none

Documentation Update

none

Contributor's checklist

  • Read through contributor's guide
  • Enough context is provided in the sections above
  • Adequate tests were added if applicable

PR apache#2431 added support for leveraging Spark SQL's partitionBy() clause
with TimestampBasedKeyGenerator, and minimal tests were added to
TestCOWDataSource for it, but only the EPOCHMILLISECONDS timestamp
type is exercised at that write/read integration level.

Adds testSparkPartitionByWithTimestampBasedKeyGeneratorScalar,
covering the SCALAR timestamp type with an explicit INPUT_TIME_UNIT,
a genuinely different code path in TimestampBasedAvroKeyGenerator
(unit-based conversion rather than an implied epoch unit) that had no
coverage at this integration level. TestTimestampBasedKeyGenerator
already unit-tests SCALAR at the key-generator layer directly, but
that does not exercise the Spark DataFrame write path, config
plumbing, and partition path resolution together the way this test
class does for the other timestamp types.

The new test mirrors the existing
testSparkPartitionByWithTimestampBasedKeyGenerator immediately above
it: same data, same assertion shape, same parameterization over
AVRO/SPARK record types. Since current_ts is generated in epoch
milliseconds, SCALAR with INPUT_TIME_UNIT=MILLISECONDS is expected to
partition identically to the existing EPOCHMILLISECONDS test, which
the assertion confirms.
@github-actions github-actions Bot added the size:S PR with lines of changes in (10, 100] label Sep 14, 2026
@hudi-bot

Copy link
Copy Markdown
Collaborator

CI report:

Bot commands @hudi-bot supports the following commands:
  • @hudi-bot run azure re-run the last Azure build

@hudi-agent hudi-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 🤖 This review was generated by an AI agent and may contain mistakes. Please verify any suggestions before applying.

Thanks for the contribution! This PR adds a parameterized test in TestCOWDataSource covering the SCALAR timestamp type with an explicit INPUT_TIME_UNIT through the Spark partitionBy() + TimestampBasedKeyGenerator path. I traced the SCALAR branch in TimestampBasedAvroKeyGenerator and confirmed MILLISECONDS yields an identity conversion on the epoch-millis current_ts field, so the assertion against the yyyyMMdd UDF is consistent. No correctness issues found. A few style/readability suggestions in the inline comments. Please take a look, and this should be ready for a Hudi committer or PMC member to take it from here. Code looks clean overall — one minor naming nit, no blocking issues.

cc @yihua

assertTrue(recordsReadDF.filter(col("_hoodie_partition_path") =!= udf_date_format(col("current_ts"))).count() == 0)
}

@ParameterizedTest

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 nit: the method name doesn't make it clear this is testing the SCALAR + MILLISECONDS combo specifically vs just "scalar" generally — maybe testSparkPartitionByWithTimestampBasedKeyGeneratorScalarMillis to mirror the EPOCHMILLISECONDS test name pattern.

⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S PR with lines of changes in (10, 100]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add more tests to TestCOWDataSource for TimestampbasedKeyGen

3 participants