Skip to content

Conversation

@piyush-zlai
Copy link
Contributor

@piyush-zlai piyush-zlai commented Jul 22, 2025

Summary

We recently switched to querying partitions to persist table partition info during batch job runs. This results in the GBU jobs failing as they don't write out partitioned data and they use the 'ds' field to partition (and not the user configured table utils partition col). This PR extends the GBU jobs to write out data partitioned by ds as well as fixing the Iceberg table format to pass through the partition column that is passed as part of retrieving partitions (currently it is discarded and tableUtils.partitionColumn is what is used).

The alternative approach here is to swap the GBU & upload to kv jobs to use the user configured partition column as part of the writes. Chose the current approach as it seemed simpler and these GBU tables are internal to Chronon so we don't need to adhere to a user partitioning scheme.

Was able to get a successful set of runs with this change in our canary (gbu -> upload to kv -> streaming).

Checklist

  • Added Unit Tests
  • Covered by existing CI
  • Integration tested
  • Documentation update

Summary by CodeRabbit

  • Bug Fixes

    • Ensured upload operations use daily partitioning, improving consistency in data partitioning and table metadata.
    • Adjusted job latency metrics for more accurate reporting and added log statements for job duration.
  • Tests

    • Enhanced tests to verify that upload nodes correctly use daily partition specifications.
  • Refactor

    • Updated internal methods to improve clarity and correctness in partition handling logic.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 22, 2025

Walkthrough

This change updates partition specification handling in the group-by upload planning and execution flow. It explicitly passes a daily partition spec in planner logic, adjusts tests to verify this, ensures upload saves partition by "ds", and refactors partition column handling in Iceberg catalog utilities.

Changes

Files / Areas Change Summary
api/src/main/scala/ai/chronon/api/planner/GroupByPlanner.scala Explicitly passes PartitionSpec.daily to MetaDataUtils.layer in uploadNode.
api/src/test/scala/ai/chronon/api/test/planner/GroupByPlannerTest.scala Adds assertions that upload node uses daily partition spec in output table info.
spark/src/main/scala/ai/chronon/spark/GroupByUpload.scala Saves DataFrame partitioned by "ds"; refines upload latency metric calculation and logging.
spark/src/main/scala/ai/chronon/spark/catalog/Iceberg.scala Refactors getIcebergPartitions to accept and use partitionColumn instead of partitionFilters.

Sequence Diagram(s)

sequenceDiagram
    participant Planner
    participant MetaDataUtils
    participant UploadJob
    participant IcebergCatalog

    Planner->>MetaDataUtils: layer(..., PartitionSpec.daily, ...)
    MetaDataUtils-->>Planner: Metadata Layered
    Planner->>UploadJob: Plan upload node with daily partition spec
    UploadJob->>IcebergCatalog: getIcebergPartitions(table, "ds")
    IcebergCatalog-->>UploadJob: List of partitions by "ds"
    UploadJob->>UploadJob: Save DataFrame partitioned by "ds"
    UploadJob->>UploadJob: Log job duration in seconds
Loading

Estimated code review effort

2 (~15 minutes)

Possibly related PRs

Suggested reviewers

  • tchow-zlai
  • nikhil-zlai

Poem

Partition by day, the code now sings,
"ds" leads the way, as upload takes wings.
Tests check and smile,
Iceberg walks the aisle—
A tidy refactor, with daily things!
⏳🧊📅


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 018c840 and 78ca2f9.

📒 Files selected for processing (4)
  • api/src/main/scala/ai/chronon/api/planner/GroupByPlanner.scala (1 hunks)
  • api/src/test/scala/ai/chronon/api/test/planner/GroupByPlannerTest.scala (1 hunks)
  • spark/src/main/scala/ai/chronon/spark/GroupByUpload.scala (2 hunks)
  • spark/src/main/scala/ai/chronon/spark/catalog/Iceberg.scala (4 hunks)
🧠 Learnings (4)
📓 Common learnings
Learnt from: david-zlai
PR: zipline-ai/chronon#222
File: cloud_gcp/src/main/resources/additional-confs.yaml:3-3
Timestamp: 2025-01-15T21:00:35.574Z
Learning: The GCS bucket configuration `spark.chronon.table.gcs.temporary_gcs_bucket: "zl-warehouse"` should remain in the main `additional-confs.yaml` file, not in dev-specific configs.
api/src/test/scala/ai/chronon/api/test/planner/GroupByPlannerTest.scala (1)

Learnt from: piyush-zlai
PR: #33
File: cloud_aws/src/test/scala/ai/chronon/integrations/aws/DynamoDBKVStoreTest.scala:175-175
Timestamp: 2024-10-07T15:09:51.567Z
Learning: Hardcoding future timestamps in tests within DynamoDBKVStoreTest.scala is acceptable when data is generated and queried within the same time range, ensuring the tests remain valid over time.

spark/src/main/scala/ai/chronon/spark/catalog/Iceberg.scala (3)

Learnt from: nikhil-zlai
PR: #70
File: service/src/main/java/ai/chronon/service/ApiProvider.java:6-6
Timestamp: 2024-12-03T04:04:33.809Z
Learning: The import scala.util.ScalaVersionSpecificCollectionsConverter in service/src/main/java/ai/chronon/service/ApiProvider.java is correct and should not be flagged in future reviews.

Learnt from: tchow-zlai
PR: #192
File: spark/src/main/scala/ai/chronon/spark/GroupBy.scala:296-299
Timestamp: 2025-01-09T17:57:34.451Z
Learning: In Spark SQL date handling:

  • date_format() converts dates to strings (used for partition columns which need string format)
  • to_date() converts strings to DateType (used when date operations are needed)
    These are opposites and should not be standardized to use the same function.

Learnt from: piyush-zlai
PR: #53
File: hub/app/controllers/TimeSeriesController.scala:224-224
Timestamp: 2024-10-29T15:21:58.102Z
Learning: In the mocked data implementation in hub/app/controllers/TimeSeriesController.scala, potential NumberFormatException exceptions due to parsing errors (e.g., when using val featureId = name.split("_").last.toInt) are acceptable and will be addressed when adding the concrete backend.

spark/src/main/scala/ai/chronon/spark/GroupByUpload.scala (1)

Learnt from: nikhil-zlai
PR: #50
File: spark/src/main/scala/ai/chronon/spark/stats/drift/SummaryUploader.scala:19-47
Timestamp: 2024-11-03T14:51:40.825Z
Learning: In Scala, the grouped method on collections returns an iterator, allowing for efficient batch processing without accumulating all records in memory.

🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: david-zlai
PR: zipline-ai/chronon#222
File: cloud_gcp/src/main/resources/additional-confs.yaml:3-3
Timestamp: 2025-01-15T21:00:35.574Z
Learning: The GCS bucket configuration `spark.chronon.table.gcs.temporary_gcs_bucket: "zl-warehouse"` should remain in the main `additional-confs.yaml` file, not in dev-specific configs.
api/src/test/scala/ai/chronon/api/test/planner/GroupByPlannerTest.scala (1)

Learnt from: piyush-zlai
PR: #33
File: cloud_aws/src/test/scala/ai/chronon/integrations/aws/DynamoDBKVStoreTest.scala:175-175
Timestamp: 2024-10-07T15:09:51.567Z
Learning: Hardcoding future timestamps in tests within DynamoDBKVStoreTest.scala is acceptable when data is generated and queried within the same time range, ensuring the tests remain valid over time.

spark/src/main/scala/ai/chronon/spark/catalog/Iceberg.scala (3)

Learnt from: nikhil-zlai
PR: #70
File: service/src/main/java/ai/chronon/service/ApiProvider.java:6-6
Timestamp: 2024-12-03T04:04:33.809Z
Learning: The import scala.util.ScalaVersionSpecificCollectionsConverter in service/src/main/java/ai/chronon/service/ApiProvider.java is correct and should not be flagged in future reviews.

Learnt from: tchow-zlai
PR: #192
File: spark/src/main/scala/ai/chronon/spark/GroupBy.scala:296-299
Timestamp: 2025-01-09T17:57:34.451Z
Learning: In Spark SQL date handling:

  • date_format() converts dates to strings (used for partition columns which need string format)
  • to_date() converts strings to DateType (used when date operations are needed)
    These are opposites and should not be standardized to use the same function.

Learnt from: piyush-zlai
PR: #53
File: hub/app/controllers/TimeSeriesController.scala:224-224
Timestamp: 2024-10-29T15:21:58.102Z
Learning: In the mocked data implementation in hub/app/controllers/TimeSeriesController.scala, potential NumberFormatException exceptions due to parsing errors (e.g., when using val featureId = name.split("_").last.toInt) are acceptable and will be addressed when adding the concrete backend.

spark/src/main/scala/ai/chronon/spark/GroupByUpload.scala (1)

Learnt from: nikhil-zlai
PR: #50
File: spark/src/main/scala/ai/chronon/spark/stats/drift/SummaryUploader.scala:19-47
Timestamp: 2024-11-03T14:51:40.825Z
Learning: In Scala, the grouped method on collections returns an iterator, allowing for efficient batch processing without accumulating all records in memory.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (16)
  • GitHub Check: cloud_gcp_tests
  • GitHub Check: cloud_aws_tests
  • GitHub Check: service_tests
  • GitHub Check: service_commons_tests
  • GitHub Check: streaming_tests
  • GitHub Check: analyzer_tests
  • GitHub Check: api_tests
  • GitHub Check: groupby_tests
  • GitHub Check: aggregator_tests
  • GitHub Check: flink_tests
  • GitHub Check: spark_tests
  • GitHub Check: online_tests
  • GitHub Check: batch_tests
  • GitHub Check: join_tests
  • GitHub Check: fetcher_tests
  • GitHub Check: scala_compile_fmt_fix
🔇 Additional comments (6)
api/src/test/scala/ai/chronon/api/test/planner/GroupByPlannerTest.scala (1)

44-46: Test assertions correctly validate daily partitioning.

These assertions properly verify that upload nodes use the daily partition specification as intended by the PR changes.

spark/src/main/scala/ai/chronon/spark/GroupByUpload.scala (2)

280-280: Correctly implements partitioning by 'ds' field.

This change aligns with the PR objective to partition GBU data by the 'ds' field instead of relying on default table utils partition column.


297-299: Improved job duration calculation and logging.

Better approach to calculate duration in seconds first, then convert to minutes for metrics, plus added logging for completion time.

api/src/main/scala/ai/chronon/api/planner/GroupByPlanner.scala (1)

57-57: Explicit daily partition spec ensures consistent behavior.

Good change to explicitly pass PartitionSpec.daily instead of relying on implicit partitioning, making the behavior predictable.

spark/src/main/scala/ai/chronon/spark/catalog/Iceberg.scala (2)

19-19: Correctly passes partition column parameter.

Good fix to pass the actual partitionColumn parameter instead of partitionFilters to the helper method.


29-29: Fixes Iceberg partition column handling.

Correct changes to use the passed partitionColumn parameter instead of defaulting to tableUtils.partitionColumn, addressing the PR objective for Iceberg table format fixes.

Also applies to: 43-43, 52-52


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@piyush-zlai piyush-zlai merged commit 9c0e3d2 into main Jul 22, 2025
20 checks passed
@piyush-zlai piyush-zlai deleted the piyush/gbu_partitioned branch July 22, 2025 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants