Skip to content

Conversation

@varant-zlai
Copy link
Collaborator

@varant-zlai varant-zlai commented Apr 2, 2025

Summary

spark optimizations

Checklist

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

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration option that lets users control time range validation during join backfill operations, providing more consistent data processing.
    • Added a method for converting partition ranges to time ranges, enhancing flexibility in time range handling.
    • Added a new test case for data generation and validation during join operations.
  • Refactor

    • Optimized the way data merging queries are constructed and how time ranges are applied during join operations, ensuring enhanced precision and performance across event data processing.
    • Simplified method signatures by removing unnecessary parameters, streamlining the process of generating Bloom filters.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 2, 2025

Walkthrough

This pull request introduces a new method, toTimeRange, in the API to convert a PartitionRange to a TimeRange by shifting the end value. In the Spark module, the left DataFrame querying in JoinPartJob.scala is updated to build queries dynamically and to use the new conversion method, with a variable rename from unfilledTimeRange to unfilledPartitionRange. Additionally, TableUtils.scala now retrieves a checkLeftTimeRange configuration parameter from the Spark session.

Changes

File Path Change Summary
api/src/main/scala/ai/chronon/api/DataRange.scala Added new public method toTimeRange(partitionRange: PartitionRange): TimeRange to convert a PartitionRange into a TimeRange by adjusting the end value by one millisecond.
spark/src/main/scala/ai/chronon/spark/JoinPartJob.scala Modified left DataFrame query construction. Renamed unfilledTimeRange to unfilledPartitionRange and updated time range handling to use the new toTimeRange method, including logging and conditional validation.
spark/src/main/scala/ai/chronon/spark/TableUtils.scala Introduced a new configuration parameter checkLeftTimeRange retrieved from the Spark session, setting default behavior for join backfill time range checks.
spark/src/main/scala/ai/chronon/spark/JoinUtils.scala Removed leftRowCount parameter from genBloomFilterIfNeeded method and its associated logging statement, simplifying method signature and logging output.
spark/src/test/scala/ai/chronon/spark/test/streaming/MutationsTest.scala Updated SparkSession configuration to include spark.chronon.join.backfill.check.left_time_range set to "true" and added a new test case for data generation and join operations.

Possibly related PRs

Suggested reviewers

  • nikhil-zlai
  • piyush-zlai
  • david-zlai

Poem

In the realm of code, a new method is born,
Converting ranges until the day is done.
Queries dynamically flow with grace,
While logs trace steps in data’s embrace.
A tune of config and refined design—
CodeRabbit’s magic, simply divine!
🚀✨

Warning

Review ran into problems

🔥 Problems

GitHub Actions and Pipeline Checks: Resource not accessible by integration - https://docs.github.com/rest/actions/workflow-runs#list-workflow-runs-for-a-repository.

Please grant the required permissions to the CodeRabbit GitHub App under the organization or repository settings.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between b27f964 and bb4dd21.

📒 Files selected for processing (1)
  • spark/src/main/scala/ai/chronon/spark/JoinPartJob.scala (7 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
spark/src/main/scala/ai/chronon/spark/JoinPartJob.scala (4)
api/src/main/scala/ai/chronon/api/DataRange.scala (4)
  • PartitionRange (38-128)
  • PartitionRange (130-174)
  • toTimeRange (169-173)
  • shift (99-105)
api/src/main/scala/ai/chronon/api/Extensions.scala (4)
  • rightToLeft (744-754)
  • query (337-345)
  • dataModel (320-325)
  • dataModel (456-463)
spark/src/main/scala/ai/chronon/spark/TableUtils.scala (1)
  • scanDf (593-613)
spark/src/main/scala/ai/chronon/spark/JoinUtils.scala (2)
  • JoinUtils (37-618)
  • genBloomFilterIfNeeded (333-368)
⏰ Context from checks skipped due to timeout of 90000ms (14)
  • GitHub Check: groupby_tests
  • GitHub Check: spark_tests
  • GitHub Check: streaming_tests
  • GitHub Check: join_tests
  • GitHub Check: analyzer_tests
  • GitHub Check: groupby_tests
  • GitHub Check: fetcher_tests
  • GitHub Check: fetcher_tests
  • GitHub Check: spark_tests
  • GitHub Check: non_spark_tests
  • GitHub Check: non_spark_tests
  • GitHub Check: analyzer_tests
  • GitHub Check: join_tests
  • GitHub Check: enforce_triggered_workflows
🔇 Additional comments (6)
spark/src/main/scala/ai/chronon/spark/JoinPartJob.scala (6)

5-6: Added necessary import for time range conversion

Added import for the new toTimeRange method to convert PartitionRange to TimeRange.


46-53: Optimized query building to select only relevant columns

Query now selects only required columns from left DataFrame: join columns, partition column, and time column (for Events only). This reduces data transfer and improves performance.


68-68: Using dateRange for bloom filter generation

Updated to use dateRange parameter instead of previous variable for bloom filter generation.


213-213: Updated partition range shift to use new variable

Using unfilledPartitionRange directly for shift operation to maintain consistency with renamed variable.


226-226: Using new toTimeRange conversion method

Simplified code by using the new utility method to convert PartitionRange to TimeRange.


170-177:

❓ Verification inconclusive

Added configuration toggle for time range checking

Time range checking is now disabled by default via tableUtils.checkLeftTimeRange. When disabled, uses dateRange directly instead of inferring from DF, improving performance.


🏁 Script executed:

#!/bin/bash
# Verify default value of checkLeftTimeRange config
rg "def\s+checkLeftTimeRange" --include "*.scala" -A 5

Length of output: 498


🏁 Script executed:

#!/bin/bash
# Revised: Search for checkLeftTimeRange config definition in Scala files.
rg 'def\s+checkLeftTimeRange' -t scala -A 5

Length of output: 45


Time Range Check Config: Confirm Default Behavior
The code correctly toggles time range checking based on tableUtils.checkLeftTimeRange. However, our automated search couldn’t locate an explicit definition or assignment indicating that the default is disabled (i.e., set to false). Please manually verify that the default configuration for checkLeftTimeRange is indeed disabled—whether it’s defined in Scala or in an external configuration file—and ensure that it aligns with the performance improvement rationale.

  • Verify the default value for tableUtils.checkLeftTimeRange is set to false.
  • Confirm the configuration’s definition in its proper location.

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
spark/src/main/scala/ai/chronon/spark/JoinPartJob.scala (1)

170-177: Feature toggle for time range checking.

This conditional logic implements the PR objective of turning off time range checks by default, which should improve performance but may affect accuracy in some cases.

Consider adding a comment explaining when time range checking should be enabled vs. disabled for better maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 687d73a and b27f964.

📒 Files selected for processing (3)
  • spark/src/main/scala/ai/chronon/spark/JoinPartJob.scala (7 hunks)
  • spark/src/main/scala/ai/chronon/spark/JoinUtils.scala (0 hunks)
  • spark/src/test/scala/ai/chronon/spark/test/streaming/MutationsTest.scala (2 hunks)
💤 Files with no reviewable changes (1)
  • spark/src/main/scala/ai/chronon/spark/JoinUtils.scala
🧰 Additional context used
🧬 Code Definitions (1)
spark/src/main/scala/ai/chronon/spark/JoinPartJob.scala (3)
api/src/main/scala/ai/chronon/api/Extensions.scala (5)
  • rightToLeft (744-754)
  • query (337-345)
  • toPartitionRange (1244-1248)
  • dataModel (320-325)
  • dataModel (456-463)
spark/src/main/scala/ai/chronon/spark/TableUtils.scala (1)
  • scanDf (593-613)
spark/src/main/scala/ai/chronon/spark/JoinUtils.scala (2)
  • JoinUtils (37-618)
  • genBloomFilterIfNeeded (333-368)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: streaming_tests
  • GitHub Check: join_tests
  • GitHub Check: groupby_tests
  • GitHub Check: analyzer_tests
  • GitHub Check: non_spark_tests
  • GitHub Check: spark_tests
  • GitHub Check: fetcher_tests
  • GitHub Check: non_spark_tests
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: streaming_tests
  • GitHub Check: fetcher_tests
  • GitHub Check: groupby_tests
  • GitHub Check: analyzer_tests
  • GitHub Check: join_tests
  • GitHub Check: spark_tests
  • GitHub Check: enforce_triggered_workflows
🔇 Additional comments (8)
spark/src/test/scala/ai/chronon/spark/test/streaming/MutationsTest.scala (2)

38-42: Configuration setup looks good.

The SparkSession configuration includes setting "spark.chronon.join.backfill.check.left_time_range" to "true", which aligns with the changes in JoinPartJob.scala.


827-827: Line formatting looks fine.

Simple whitespace addition that improves readability.

spark/src/main/scala/ai/chronon/spark/JoinPartJob.scala (6)

5-6: Import statements updated appropriately.

Added toTimeRange function import and Builders class to support the new implementation.


46-53: Efficiency improvement by selecting only relevant columns.

Instead of fetching all columns, the code now selects only columns needed for the join operation, which should reduce I/O and memory usage.


68-68: Simplified bloom filter generation.

Directly using dateRange parameter instead of a variable reference.


120-121: Enhanced logging.

Added elapsed time information to the log output for better debugging and monitoring.


213-213: Variable usage updated for consistency.

Using the new unfilledPartitionRange variable for shifting operations.


226-226: Cleaner time range conversion.

Using the new toTimeRange utility function provides a more maintainable approach to converting partition ranges to time ranges.

@tchow-zlai tchow-zlai merged commit 9a28a70 into main Apr 2, 2025
19 checks passed
@tchow-zlai tchow-zlai deleted the vz--spark-optimizations branch April 2, 2025 05:17
kumar-zlai pushed a commit that referenced this pull request Apr 25, 2025
…ant cols from left (#577)

## Summary

spark optimizations

## Checklist
- [ ] Added Unit Tests
- [ ] Covered by existing CI
- [ ] Integration tested
- [ ] Documentation update



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new configuration option that lets users control time
range validation during join backfill operations, providing more
consistent data processing.
- Added a method for converting partition ranges to time ranges,
enhancing flexibility in time range handling.
- Added a new test case for data generation and validation during join
operations.

- **Refactor**
- Optimized the way data merging queries are constructed and how time
ranges are applied during join operations, ensuring enhanced precision
and performance across event data processing.
- Simplified method signatures by removing unnecessary parameters,
streamlining the process of generating Bloom filters.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: ezvz <[email protected]>
kumar-zlai pushed a commit that referenced this pull request Apr 29, 2025
…ant cols from left (#577)

## Summary

spark optimizations

## Checklist
- [ ] Added Unit Tests
- [ ] Covered by existing CI
- [ ] Integration tested
- [ ] Documentation update



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new configuration option that lets users control time
range validation during join backfill operations, providing more
consistent data processing.
- Added a method for converting partition ranges to time ranges,
enhancing flexibility in time range handling.
- Added a new test case for data generation and validation during join
operations.

- **Refactor**
- Optimized the way data merging queries are constructed and how time
ranges are applied during join operations, ensuring enhanced precision
and performance across event data processing.
- Simplified method signatures by removing unnecessary parameters,
streamlining the process of generating Bloom filters.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: ezvz <[email protected]>
chewy-zlai pushed a commit that referenced this pull request May 15, 2025
…ant cols from left (#577)

## Summary

spark optimizations

## Checklist
- [ ] Added Unit Tests
- [ ] Covered by existing CI
- [ ] Integration tested
- [ ] Documentation update



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new configuration option that lets users control time
range validation during join backfill operations, providing more
consistent data processing.
- Added a method for converting partition ranges to time ranges,
enhancing flexibility in time range handling.
- Added a new test case for data generation and validation during join
operations.

- **Refactor**
- Optimized the way data merging queries are constructed and how time
ranges are applied during join operations, ensuring enhanced precision
and performance across event data processing.
- Simplified method signatures by removing unnecessary parameters,
streamlining the process of generating Bloom filters.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: ezvz <[email protected]>
chewy-zlai pushed a commit that referenced this pull request May 15, 2025
…ant cols from left (#577)

## Summary

spark optimizations

## Checklist
- [ ] Added Unit Tests
- [ ] Covered by existing CI
- [ ] Integration tested
- [ ] Documentation update



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new configuration option that lets users control time
range validation during join backfill operations, providing more
consistent data processing.
- Added a method for converting partition ranges to time ranges,
enhancing flexibility in time range handling.
- Added a new test case for data generation and validation during join
operations.

- **Refactor**
- Optimized the way data merging queries are constructed and how time
ranges are applied during join operations, ensuring enhanced precision
and performance across event data processing.
- Simplified method signatures by removing unnecessary parameters,
streamlining the process of generating Bloom filters.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: ezvz <[email protected]>
chewy-zlai pushed a commit that referenced this pull request May 16, 2025
…nly relevant cols from left (#577)

## Summary

spark optimizations

## Cheour clientslist
- [ ] Added Unit Tests
- [ ] Covered by existing CI
- [ ] Integration tested
- [ ] Documentation update



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new configuration option that lets users control time
range validation during join baour clientsfill operations, providing more
consistent data processing.
- Added a method for converting partition ranges to time ranges,
enhancing flexibility in time range handling.
- Added a new test case for data generation and validation during join
operations.

- **Refactor**
- Optimized the way data merging queries are constructed and how time
ranges are applied during join operations, ensuring enhanced precision
and performance across event data processing.
- Simplified method signatures by removing unnecessary parameters,
streamlining the process of generating Bloom filters.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: ezvz <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request May 30, 2025
Closed
4 tasks
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