Skip to content

Add flag to skip repartition before writing. #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 27, 2025

Conversation

david-zlai
Copy link
Contributor

@david-zlai david-zlai commented Jan 17, 2025

Summary

Checklist

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

Summary by CodeRabbit

  • New Features

    • Added configurable repartitioning option for DataFrame writes.
    • Introduced a new configuration setting to control repartitioning behavior.
    • Enhanced test suite with functionality to handle empty DataFrames.
  • Chores

    • Improved code formatting and logging for DataFrame writing process.

@david-zlai david-zlai requested a review from tchow-zlai January 17, 2025 19:56
Copy link

coderabbitai bot commented Jan 17, 2025

Walkthrough

The pull request modifies the TableUtils.scala file to implement a conditional repartitioning mechanism based on the configuration setting spark.chronon.write.repartition. The repartitionAndWrite method now determines whether to repartition the DataFrame before writing it, while the repartitionInternal method has been updated to return a DataFrame. Additionally, the test suite is enhanced with a new case class and test case for handling empty DataFrames, along with simplified import statements.

Changes

File Change Summary
spark/src/main/scala/ai/chronon/spark/TableUtils.scala Implemented conditional repartitioning based on spark.chronon.write.repartition. Renamed repartitionAndWriteInternal to repartitionInternal, changing its signature to return a DataFrame. Updated logging messages.
spark/src/test/scala/ai/chronon/spark/test/TableUtilsTest.scala Added TestRecord case class and a test case for empty DataFrames. Simplified import statements.

Possibly related PRs

Suggested Reviewers

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

Poem

Partitions dance, config decides their fate
DataFrame's journey, no longer straight
A switch to skip, or repartition's might
Spark's flexibility shines ever so bright! 🚀✨

Warning

Review ran into problems

🔥 Problems

GitHub Actions: 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.


🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

(df.count(), 1)
}
val skipRepartitionBeforeWriting =
sparkSession.conf.get("spark.chronon.skip_repartition_before_writing", "false").toBoolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sparkSession.conf.get("spark.chronon.skip_repartition_before_writing", "false").toBoolean
sparkSession.conf.get("spark.chronon.write.repartition", "false").toBoolean

.drop(saltCol)
.sortWithinPartitions(partitionSortCols.map(col): _*)
.write
if (skipRepartitionBeforeWriting) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should add this switch in the insert(Partitions) or insert(UnPartitioned) methods

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved it to those methods

@david-zlai david-zlai marked this pull request as ready for review January 17, 2025 20:39
Copy link

@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 (2)
spark/src/main/scala/ai/chronon/spark/TableUtils.scala (2)

374-384: Extract configuration flag to a class-level constant.

The configuration flag is duplicated. Consider extracting it to avoid repetition.

 class TableUtils(@transient val sparkSession: SparkSession) extends Serializable {
+  private val skipRepartitionBeforeWriting =
+    sparkSession.conf.get("spark.chronon.write.repartition", "false").toBoolean
+
   // ... existing code ...
-    val skipRepartitionBeforeWriting =
-      sparkSession.conf.get("spark.chronon.write.repartition", "false").toBoolean

564-566: Fix indentation.

The indentation is inconsistent with the surrounding code.

-        } else {
-          (Seq(saltCol), sortByCols)
-        }
+      } else {
+        (Seq(saltCol), sortByCols)
+      }
📜 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 9ab9009 and ef9d272.

📒 Files selected for processing (1)
  • spark/src/main/scala/ai/chronon/spark/TableUtils.scala (5 hunks)
🔇 Additional comments (1)
spark/src/main/scala/ai/chronon/spark/TableUtils.scala (1)

444-453: 🛠️ Refactor suggestion

Remove duplicated configuration check.

This block duplicates the same logic as in insertPartitions. Use the extracted class-level constant.

-    val skipRepartitionBeforeWriting =
-      sparkSession.conf.get("spark.chronon.write.repartition", "false").toBoolean
     if (skipRepartitionBeforeWriting) {

Likely invalid or redundant comment.

@@ -431,7 +441,16 @@ class TableUtils(@transient val sparkSession: SparkSession) extends Serializable
tableProperties,
fileFormat)

repartitionAndWrite(df, tableName, saveMode, None)
val skipRepartitionBeforeWriting =
Copy link
Collaborator

Choose a reason for hiding this comment

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

wait let's just put this branch in the repartitionAndwrite method, there's other transformation logic we'd skip out if you have it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

do you mean the wrapWithCache on line 475 (old file)?

Comment on lines 375 to 376
val skipRepartitionBeforeWriting =
sparkSession.conf.get("spark.chronon.write.repartition", "false").toBoolean
Copy link
Contributor

Choose a reason for hiding this comment

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

make this class level member?

@@ -431,7 +441,16 @@ class TableUtils(@transient val sparkSession: SparkSession) extends Serializable
tableProperties,
fileFormat)

repartitionAndWrite(df, tableName, saveMode, None)
val skipRepartitionBeforeWriting =
sparkSession.conf.get("spark.chronon.write.repartition", "false").toBoolean
Copy link
Contributor

Choose a reason for hiding this comment

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

move this to be class level

@tchow-zlai tchow-zlai force-pushed the davidhan/skip_repartition branch from ef9d272 to 7edd765 Compare January 24, 2025 03:26
repartitionAndWriteInternal(df, tableName, saveMode, stats, sortByCols)
val dataPointer = DataPointer.from(tableName, sparkSession)
val repartitioned =
if (sparkSession.conf.get("spark.chronon.write.repartition", "false").toBoolean)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@nikhil-zlai | @david-zlai here's the conf guard.

@tchow-zlai tchow-zlai force-pushed the davidhan/skip_repartition branch from 48150b2 to bec3da7 Compare January 24, 2025 03:28
Copy link

@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/TableUtils.scala (1)

484-498: Consider making repartitioning enabled by default.

The new flag defaults to false, which means repartitioning is skipped. This could lead to suboptimal write performance for large datasets.

-        if (sparkSession.conf.get("spark.chronon.write.repartition", false.toString).toBoolean)
+        if (sparkSession.conf.get("spark.chronon.write.repartition", true.toString).toBoolean)
📜 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 ef9d272 and bec3da7.

📒 Files selected for processing (1)
  • spark/src/main/scala/ai/chronon/spark/TableUtils.scala (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: table_utils_delta_format_spark_tests
  • GitHub Check: other_spark_tests
  • GitHub Check: join_spark_tests
  • GitHub Check: fetcher_spark_tests
  • GitHub Check: mutation_spark_tests
  • GitHub Check: scala_compile_fmt_fix
🔇 Additional comments (1)
spark/src/main/scala/ai/chronon/spark/TableUtils.scala (1)

Line range hint 503-574: LGTM! Clean method refactoring.

The method has been correctly refactored to separate concerns between repartitioning and writing operations.

@tchow-zlai
Copy link
Collaborator

@david-zlai | @nikhil-zlai main difference in functionality here is that an empty dataframe is still going to trigger a spark action to attempt to write, rather than no action at all. I think that's better and more semantically correct, we would expect a new version of a table to be generated.

Copy link

@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/test/scala/ai/chronon/spark/test/TableUtilsTest.scala (1)

488-501: Nice test. Consider a quick schema check after the first insert.

📜 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 bec3da7 and dfe2ad8.

📒 Files selected for processing (2)
  • spark/src/main/scala/ai/chronon/spark/TableUtils.scala (2 hunks)
  • spark/src/test/scala/ai/chronon/spark/test/TableUtilsTest.scala (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: table_utils_delta_format_spark_tests
  • GitHub Check: other_spark_tests
  • GitHub Check: join_spark_tests
  • GitHub Check: mutation_spark_tests
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: fetcher_spark_tests
🔇 Additional comments (5)
spark/src/test/scala/ai/chronon/spark/test/TableUtilsTest.scala (2)

26-26: Looks good.


35-36: Fine addition.

spark/src/main/scala/ai/chronon/spark/TableUtils.scala (3)

484-499: Config default differs from prior suggestion. Should it be false by default?

#!/bin/bash
# Check references and merges for "spark.chronon.write.repartition" defaults
rg "spark\.chronon\.write\.repartition"

503-506: Return type improvement is good.


573-573: Zero-row shortcut is logical.

@tchow-zlai tchow-zlai changed the base branch from main to tchow/direct-writes January 27, 2025 19:38
@tchow-zlai tchow-zlai force-pushed the davidhan/skip_repartition branch from dfe2ad8 to f3f4a2e Compare January 27, 2025 19:38
Base automatically changed from tchow/direct-writes to main January 27, 2025 21:14
tchow-zlai and others added 4 commits January 27, 2025 13:14
Co-authored-by: Thomas Chow <[email protected]>

Co-authored-by: Thomas Chow <[email protected]>

Co-authored-by: Thomas Chow <[email protected]>
Co-authored-by: Thomas Chow <[email protected]>

Co-authored-by: Thomas Chow <[email protected]>

Co-authored-by: Thomas Chow <[email protected]>

Co-authored-by: Thomas Chow <[email protected]>
Co-authored-by: Thomas Chow <[email protected]>

Co-authored-by: Thomas Chow <[email protected]>

Co-authored-by: Thomas Chow <[email protected]>
Co-authored-by: Thomas Chow <[email protected]>

Co-authored-by: Thomas Chow <[email protected]>
@tchow-zlai tchow-zlai force-pushed the davidhan/skip_repartition branch from f3f4a2e to 20ef1dc Compare January 27, 2025 21:15
Copy link

@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/test/scala/ai/chronon/spark/test/TableUtilsTest.scala (1)

487-501: LGTM! Good edge case coverage.

Test verifies empty DataFrame handling and subsequent data insertion.

However, consider adding assertions for the schema and partition structure:

 assertEquals(0, res.count)
+assertEquals(Seq("ds", "id"), res.schema.fieldNames.toSeq)
+assertTrue(tableUtils.allPartitions(tableName).nonEmpty)
📜 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 dfe2ad8 and 20ef1dc.

📒 Files selected for processing (2)
  • spark/src/main/scala/ai/chronon/spark/TableUtils.scala (2 hunks)
  • spark/src/test/scala/ai/chronon/spark/test/TableUtilsTest.scala (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • spark/src/main/scala/ai/chronon/spark/TableUtils.scala
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: table_utils_delta_format_spark_tests
  • GitHub Check: fetcher_spark_tests
  • GitHub Check: other_spark_tests
  • GitHub Check: mutation_spark_tests
  • GitHub Check: join_spark_tests
  • GitHub Check: scala_compile_fmt_fix
🔇 Additional comments (1)
spark/src/test/scala/ai/chronon/spark/test/TableUtilsTest.scala (1)

34-35: LGTM! Well-structured case class.

Simple and clean case class definition with appropriate field types.

@tchow-zlai tchow-zlai merged commit 225e5af into main Jan 27, 2025
9 checks passed
@tchow-zlai tchow-zlai deleted the davidhan/skip_repartition branch January 27, 2025 21:47
nikhil-zlai pushed a commit that referenced this pull request Feb 4, 2025
## Summary

## 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**
  - Added configurable repartitioning option for DataFrame writes.
- Introduced a new configuration setting to control repartitioning
behavior.
  - Enhanced test suite with functionality to handle empty DataFrames.

- **Chores**
  - Improved code formatting and logging for DataFrame writing process.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- av pr metadata
This information is embedded by the av CLI when creating PRs to track
the status of stacks when using Aviator. Please do not delete or edit
this section of the PR.
```
{"parent":"main","parentHead":"","trunk":"main"}
```
-->

---------

Co-authored-by: tchow-zlai <[email protected]>
Co-authored-by: Thomas Chow <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request Mar 18, 2025
4 tasks
kumar-zlai pushed a commit that referenced this pull request Apr 25, 2025
## Summary

## 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**
  - Added configurable repartitioning option for DataFrame writes.
- Introduced a new configuration setting to control repartitioning
behavior.
  - Enhanced test suite with functionality to handle empty DataFrames.

- **Chores**
  - Improved code formatting and logging for DataFrame writing process.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- av pr metadata
This information is embedded by the av CLI when creating PRs to track
the status of stacks when using Aviator. Please do not delete or edit
this section of the PR.
```
{"parent":"main","parentHead":"","trunk":"main"}
```
-->

---------

Co-authored-by: tchow-zlai <[email protected]>
Co-authored-by: Thomas Chow <[email protected]>
kumar-zlai pushed a commit that referenced this pull request Apr 29, 2025
## Summary

## 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**
  - Added configurable repartitioning option for DataFrame writes.
- Introduced a new configuration setting to control repartitioning
behavior.
  - Enhanced test suite with functionality to handle empty DataFrames.

- **Chores**
  - Improved code formatting and logging for DataFrame writing process.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- av pr metadata
This information is embedded by the av CLI when creating PRs to track
the status of stacks when using Aviator. Please do not delete or edit
this section of the PR.
```
{"parent":"main","parentHead":"","trunk":"main"}
```
-->

---------

Co-authored-by: tchow-zlai <[email protected]>
Co-authored-by: Thomas Chow <[email protected]>
chewy-zlai pushed a commit that referenced this pull request May 15, 2025
## Summary

## 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**
  - Added configurable repartitioning option for DataFrame writes.
- Introduced a new configuration setting to control repartitioning
behavior.
  - Enhanced test suite with functionality to handle empty DataFrames.

- **Chores**
  - Improved code formatting and logging for DataFrame writing process.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- av pr metadata
This information is embedded by the av CLI when creating PRs to track
the status of stacks when using Aviator. Please do not delete or edit
this section of the PR.
```
{"parent":"main","parentHead":"","trunk":"main"}
```
-->

---------

Co-authored-by: tchow-zlai <[email protected]>
Co-authored-by: Thomas Chow <[email protected]>
chewy-zlai pushed a commit that referenced this pull request May 15, 2025
## Summary

## 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**
  - Added configurable repartitioning option for DataFrame writes.
- Introduced a new configuration setting to control repartitioning
behavior.
  - Enhanced test suite with functionality to handle empty DataFrames.

- **Chores**
  - Improved code formatting and logging for DataFrame writing process.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- av pr metadata
This information is embedded by the av CLI when creating PRs to track
the status of stacks when using Aviator. Please do not delete or edit
this section of the PR.
```
{"parent":"main","parentHead":"","trunk":"main"}
```
-->

---------

Co-authored-by: tchow-zlai <[email protected]>
Co-authored-by: Thomas Chow <[email protected]>
chewy-zlai pushed a commit that referenced this pull request May 16, 2025
## Summary

## 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**
  - Added configurable repartitioning option for DataFrame writes.
- Introduced a new configuration setting to control repartitioning
behavior.
  - Enhanced test suite with functionality to handle empty DataFrames.

- **Chores**
  - Improved code formatting and logging for DataFrame writing process.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- av pr metadata
This information is embedded by the av CLI when creating PRs to traour clients
the status of staour clientss when using Aviator. Please do not delete or edit
this section of the PR.
```
{"parent":"main","parentHead":"","trunk":"main"}
```
-->

---------

Co-authored-by: tchow-zlai <[email protected]>
Co-authored-by: Thomas Chow <[email protected]>
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.

3 participants