Skip to content

WIP -- Allow setting partition column in Query and StagingQuery #366

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

Closed
wants to merge 5 commits into from

Conversation

varant-zlai
Copy link
Collaborator

@varant-zlai varant-zlai commented Feb 12, 2025

Summary

Allowing setting an explicit partition column in the Query, and in StagingQuery

Checklist

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

Summary by CodeRabbit

  • New Features

    • Added optional support for specifying a partition column in query configurations, giving users greater control over data partitioning.
  • Refactor

    • Consolidated partition management across data retrieval, join, group-by, and bootstrap operations to ensure consistent behavior.
    • Enhanced internal logging for clearer tracking of partition-related activity.
  • Tests

    • Updated and expanded test cases to validate the improved partition handling and data generation, ensuring robust operational behavior.

Copy link
Contributor

coderabbitai bot commented Feb 12, 2025

Walkthrough

This update introduces new optional fields to the API’s data models and refactors the codebase to use a unified default partition column. References to the old partition column have been replaced with the new default variant across multiple modules, including Spark core, utilities, and tests. Method signatures and parameter types have been updated to standardize partition handling and improve table metadata management via TableInfo.

Changes

File(s) Change Summary
api/thrift/api.thrift Added optional string partitionColumn fields to both Query and StagingQuery.
api/src/main/scala/ai/chronon/api/Builders.scala Updated Query.apply to accept new partitionColumn parameter and set it on the built object.
spark/src/main/scala/ai/chronon/spark/... Multiple core files (e.g., Analyzer.scala, BootstrapInfo.scala, Driver.scala, Extensions.scala, GroupBy.scala, Join.scala, JoinUtils.scala, LabelJoin.scala, StagingQuery.scala, TableUtils.scala, Format.scala, and stats modules) now use defaultPartitionColumn in place of partitionColumn; method signatures and table metadata handling updated to use TableInfo.
spark/src/main/scala/ai/chronon/spark/utils/... Utilities (InMemoryKvStore, InMemoryStream, PartitionRunner) modified to use defaultPartitionColumn and TableInfo for filtering and column dropping.
spark/src/test/scala/ai/chronon/spark/test/... Test files updated to reference defaultPartitionColumn and add optional parameters for data generation methods; some tests (e.g., JoinTest) now include new cases for partition column handling.
spark/src/main/scala/ai/chronon/spark/FastHashing.scala Enhanced key builder logging to append the list of keys.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant QB as Query Builder
    participant T as Thrift API
    C->>QB: Create Query (incl. partitionColumn)
    QB->>T: Call Query.apply(..., partitionColumn)
    T->>T: Build Query struct with partitionColumn field
    T-->>C: Return Query object
Loading
sequenceDiagram
    participant JP as Join Process
    participant TU as TableUtils
    participant DF as DataFrame
    JP->>TU: Request defaultPartitionColumn
    TU-->>JP: Return partition value
    JP->>DF: Apply partition filter in join & validation
Loading

Possibly related PRs

Suggested reviewers

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

Poem

In the code’s vast, twisting maze,
New partitions now light our ways.
Defaults shine where chaos once reigned,
With refactored lines smoothly maintained.
Cheers to clean code—bright and sustained! 🎉

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.


🪧 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.

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

842-845: Add input validation for table name.

Consider validating the table name parameter to prevent empty or malformed values.

 case class TableInfo(table: String, partitionColumn: Option[String] = None)(implicit tableUtils: TableUtils) {
+  require(table != null && table.trim.nonEmpty, "Table name cannot be null or empty")
   def getPartitionColumn: String =
     partitionColumn.getOrElse(tableUtils.defaultPartitionColumn)
 }
📜 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 aa32fea and 9b62e84.

📒 Files selected for processing (3)
  • spark/src/main/scala/ai/chronon/spark/GroupBy.scala (13 hunks)
  • spark/src/main/scala/ai/chronon/spark/LogFlattenerJob.scala (3 hunks)
  • spark/src/main/scala/ai/chronon/spark/TableUtils.scala (15 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • spark/src/main/scala/ai/chronon/spark/GroupBy.scala
  • spark/src/main/scala/ai/chronon/spark/LogFlattenerJob.scala
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: spark_tests
  • GitHub Check: non_spark_tests
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: enforce_triggered_workflows
🔇 Additional comments (2)
spark/src/main/scala/ai/chronon/spark/TableUtils.scala (2)

69-70: LGTM: Descriptive variable name.

The rename from partitionColumn to defaultPartitionColumn better reflects its role as a fallback value.


135-138: LGTM: Consistent refactoring to use TableInfo.

Methods have been systematically updated to use TableInfo, improving encapsulation of table-related data.

Also applies to: 140-144, 250-253, 255-284, 286-298

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

842-845: Add validation for table name.

Consider validating the table name parameter to ensure it's not empty or malformed.

 case class TableInfo(table: String, partitionColumn: Option[String] = None)(implicit tableUtils: TableUtils) {
+  require(table != null && table.trim.nonEmpty, "Table name cannot be null or empty")
   def getPartitionColumn: String =
     partitionColumn.getOrElse(tableUtils.defaultPartitionColumn)
 }
📜 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 9b62e84 and 52f3bd8.

📒 Files selected for processing (13)
  • api/src/main/scala/ai/chronon/api/Builders.scala (2 hunks)
  • spark/src/main/scala/ai/chronon/spark/Analyzer.scala (9 hunks)
  • spark/src/main/scala/ai/chronon/spark/BootstrapInfo.scala (5 hunks)
  • spark/src/main/scala/ai/chronon/spark/Extensions.scala (6 hunks)
  • spark/src/main/scala/ai/chronon/spark/FastHashing.scala (1 hunks)
  • spark/src/main/scala/ai/chronon/spark/GroupBy.scala (15 hunks)
  • spark/src/main/scala/ai/chronon/spark/Join.scala (5 hunks)
  • spark/src/main/scala/ai/chronon/spark/JoinBase.scala (9 hunks)
  • spark/src/main/scala/ai/chronon/spark/JoinUtils.scala (4 hunks)
  • spark/src/main/scala/ai/chronon/spark/LabelJoin.scala (6 hunks)
  • spark/src/main/scala/ai/chronon/spark/TableUtils.scala (15 hunks)
  • spark/src/test/scala/ai/chronon/spark/test/DataFrameGen.scala (4 hunks)
  • spark/src/test/scala/ai/chronon/spark/test/JoinTest.scala (5 hunks)
✅ Files skipped from review due to trivial changes (1)
  • spark/src/main/scala/ai/chronon/spark/FastHashing.scala
🚧 Files skipped from review as they are similar to previous changes (8)
  • spark/src/main/scala/ai/chronon/spark/BootstrapInfo.scala
  • spark/src/main/scala/ai/chronon/spark/LabelJoin.scala
  • spark/src/main/scala/ai/chronon/spark/GroupBy.scala
  • spark/src/test/scala/ai/chronon/spark/test/DataFrameGen.scala
  • spark/src/main/scala/ai/chronon/spark/Join.scala
  • spark/src/main/scala/ai/chronon/spark/Analyzer.scala
  • spark/src/main/scala/ai/chronon/spark/JoinBase.scala
  • spark/src/main/scala/ai/chronon/spark/Extensions.scala
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: non_spark_tests
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: spark_tests
  • GitHub Check: enforce_triggered_workflows
🔇 Additional comments (12)
api/src/main/scala/ai/chronon/api/Builders.scala (2)

49-50: LGTM! Method signature maintains backward compatibility.

The addition of partitionColumn with a default value of null ensures existing code continues to work.


63-63: LGTM! Consistent implementation pattern.

The setPartitionColumn call follows the established pattern for optional parameters.

spark/src/test/scala/ai/chronon/spark/test/JoinTest.scala (3)

58-58: LGTM! Simplified class inheritance.

The removal of TaggedFilterSuite trait simplifies the test class structure.


177-177: LGTM! Added partition column support.

The changes correctly implement partition column support in the test case:

  • Added partitionColumn parameter to DataFrameGen.events
  • Added partitionColumn field in the query configuration

Also applies to: 189-190


434-555: LGTM! Added comprehensive test for partition column functionality.

The new test case thoroughly validates the partition column feature by:

  • Testing partition column specification in data generation
  • Verifying partition column usage in queries
  • Validating join operations with custom partition columns
spark/src/main/scala/ai/chronon/spark/TableUtils.scala (3)

69-70: LGTM: Clear naming for default partition column.

The rename from partitionColumn to defaultPartitionColumn better reflects its role as a fallback value.


135-138: LGTM: Clean overloading pattern for isPartitioned.

The refactoring maintains backward compatibility while introducing the new TableInfo parameter.

Also applies to: 140-144


188-191: LGTM: Consistent refactoring of partitions method.

The method properly handles both string-based and TableInfo-based calls, with clear delegation pattern.

Also applies to: 193-209

spark/src/main/scala/ai/chronon/spark/JoinUtils.scala (4)

84-84: LGTM! Using query's effective partition column.

The change improves flexibility by using the query's partition column configuration.


118-118: LGTM! Using tableInfo for metadata access.

More consistent approach to accessing table metadata.


241-241: LGTM! Using default partition column.

Standardizes partition column usage across the codebase.


282-283:

✅ Verification successful

LGTM! Updated partition column assertions.

Maintains consistency in partition column validation.


🏁 Script executed:

#!/bin/bash
# Verify that all partition column references use defaultPartitionColumn
rg -A 2 "partitionColumn" --type scala

Length of output: 40522


Partition column assertions verified and consistent.
The changes in JoinUtils.scala (lines 282-283) now correctly enforce that the partition keys include both tableUtils.defaultPartitionColumn and Constants.LabelPartitionColumn, aligning well with tests and similar patterns across the repository.

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: 1

🧹 Nitpick comments (1)
spark/src/test/scala/ai/chronon/spark/test/JoinTest.scala (1)

129-130: Consider documenting the rationale for reducing entity count.

Reducing entities from 1000 to 300/50 might affect test coverage. If this is for performance, consider adding a comment explaining the decision.

📜 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 52f3bd8 and 9f1c1c1.

📒 Files selected for processing (3)
  • .bazelignore (1 hunks)
  • spark/src/main/scala/ai/chronon/spark/TableUtils.scala (13 hunks)
  • spark/src/test/scala/ai/chronon/spark/test/JoinTest.scala (27 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .bazelignore
🚧 Files skipped from review as they are similar to previous changes (1)
  • spark/src/main/scala/ai/chronon/spark/TableUtils.scala
🔇 Additional comments (2)
spark/src/test/scala/ai/chronon/spark/test/JoinTest.scala (2)

177-178: LGTM! Explicit partition column improves clarity.

The addition of explicit partitionColumn parameter makes the test setup more clear and aligns with the PR objectives.


434-555: LGTM! Well-structured test for partition column feature.

The new test case thoroughly verifies the partition column functionality with appropriate assertions and error checks.

@@ -55,7 +55,7 @@ object TestRow {
}

// Run as follows: sbt "spark/testOnly -- -n jointest"
class JoinTest extends AnyFlatSpec with TaggedFilterSuite {
class JoinTest extends AnyFlatSpec {
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider keeping TaggedFilterSuite.

Removing TaggedFilterSuite might affect the ability to filter and run specific tests using tags.


🏁 Script executed:

#!/bin/bash
# Check if TaggedFilterSuite is used in other test files
rg "extends.*TaggedFilterSuite" --type scala

Length of output: 485


TaggedFilterSuite Usage Inconsistency

  • JoinTest removed TaggedFilterSuite, yet other tests (CatalystUtilHiveUDFTest, FetcherTest, MutationsTest) still use it.
  • Reintroducing TaggedFilterSuite in JoinTest is recommended to keep test filtering consistent.

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.

2 participants