Skip to content

Conversation

@tchow-zlai
Copy link
Collaborator

@tchow-zlai tchow-zlai commented Jun 16, 2025

Summary

  • Batch node runner is the new driver. It runs on a spark session and kicks off a monolith join for now. Will be able to support other nodeContents in the future.

Checklist

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

Summary by CodeRabbit

  • New Features
    • Introduced a new batch processing runner for executing join operations in Spark environments.
  • Tests
    • Added tests to validate the execution and correctness of join operations using the new batch runner.
  • Improvements
    • Simplified the node runner interface for streamlined configuration handling.
    • Enhanced query planning by converting a key planner class to a case class.
    • Improved robustness in handling optional table dependencies during query planning.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 16, 2025

Warning

Rate limit exceeded

@tchow-zlai has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between a83235d and a024698.

📒 Files selected for processing (2)
  • api/src/main/scala/ai/chronon/api/planner/NodeRunner.scala (1 hunks)
  • spark/src/main/scala/ai/chronon/spark/batch/BatchNodeRunner.scala (1 hunks)

"""

Walkthrough

The changes remove the generic and context-based design from the NodeRunner trait, making it simpler and fixed to NodeContent. A new BatchNodeRunner object implements this interface, handling monolithic join nodes with Spark. Comprehensive tests for BatchNodeRunner are introduced, validating join execution on synthetic data.

Changes

File(s) Change Summary
api/.../planner/NodeRunner.scala Removed BatchRunContext and generic NodeRunner[Conf]; simplified NodeRunner to fixed NodeContent config.
spark/.../batch/BatchNodeRunner.scala Added BatchNodeRunner object implementing NodeRunner; processes monolith join nodes using Spark.
spark/.../test/batch/BatchNodeRunnerTest.scala Added tests for BatchNodeRunner running monolithic join nodes and verifying output correctness.
api/.../planner/StagingQueryPlanner.scala Changed StagingQueryPlanner from class to case class.
api/.../planner/TableDependencies.scala Made fromStagingQuery null-safe for tableDependencies.

Sequence Diagram(s)

sequenceDiagram
    participant Test as BatchNodeRunnerTest
    participant Runner as BatchNodeRunner
    participant Spark as SparkSession
    participant UnionJoin as UnionJoin

    Test->>Runner: run(metadata, nodeContent, partitionRange)
    Runner->>Spark: Initialize session
    Runner->>Runner: Inspect nodeContent
    alt MonolithJoin node
        Runner->>UnionJoin: computeJoinAndSave(...)
        UnionJoin-->>Runner: Join results saved
        Runner->>Spark: Create Join instance, computeJoin
        Spark-->>Runner: DataFrame (join results)
        Runner->>Runner: Show sample results
    else Unsupported node
        Runner->>Runner: Throw exception
    end
Loading

Suggested reviewers

  • nikhil-zlai
  • varant-zlai

Poem

In the land where nodes now simply run,
BatchNodeRunner rises—its work never done.
Joins are computed, partitions aligned,
Tests pass with data perfectly combined.
Old context and types bid a fond adieu,
Spark’s monolith joins now shine anew!

"""


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

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 (4)
spark/src/main/scala/ai/chronon/spark/batch/NodeRunner.scala (1)

12-16: readFiles is a no-op with unsafe return type

Stub returns Seq[Any], loses type safety and silently hides TODO.

-  def readFiles(folderPath: String): Seq[Any] = {
-    // read files from folder using metadata
-    Seq.empty
-  }
+  // TODO: implement
+  def readFiles(folderPath: String): Seq[YourTypedRow] = Seq.empty
spark/src/main/scala/ai/chronon/spark/batch/BatchNodeRunner.scala (2)

18-19: spark val unused

Built session isn’t referenced afterwards. Either use it or drop it.

-        val spark = SparkSessionBuilder.build(f"node-batch-${metadata.name}")
+        SparkSessionBuilder.build(f"node-batch-${metadata.name}") // returns implicit session

22-30: Typos in log strings

Extra ) at end of messages.

-          logger.info(s"Processing range $range)")
+          logger.info(s"Processing range $range")
...
-          logger.info(s"Wrote range $range)")
+          logger.info(s"Wrote range $range")
spark/src/test/scala/ai/chronon/spark/test/batch/BatchNodeRunnerTest.scala (1)

76-84: Double compute may waste minutes

Test runs computeJoinAndSave then reruns same join via BatchNodeRunner; second run isn’t needed for assertion.

-    UnionJoin.computeJoinAndSave(joinConf, dateRange)
-    val batchNodeRunner = new BatchNodeRunner()
+    val batchNodeRunner = new BatchNodeRunner()
@@
-    batchNodeRunner.run(joinConf.metaData, joinNodeContent, dateRange, tableUtils)
+    batchNodeRunner.run(joinConf.metaData, joinNodeContent, dateRange, tableUtils) // either/or
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a943103 and 0a956ea.

📒 Files selected for processing (4)
  • api/src/main/scala/ai/chronon/api/planner/NodeRunner.scala (0 hunks)
  • spark/src/main/scala/ai/chronon/spark/batch/BatchNodeRunner.scala (1 hunks)
  • spark/src/main/scala/ai/chronon/spark/batch/NodeRunner.scala (1 hunks)
  • spark/src/test/scala/ai/chronon/spark/test/batch/BatchNodeRunnerTest.scala (1 hunks)
💤 Files with no reviewable changes (1)
  • api/src/main/scala/ai/chronon/api/planner/NodeRunner.scala
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: cloud_gcp_tests
  • GitHub Check: service_commons_tests
  • GitHub Check: service_tests
  • GitHub Check: streaming_tests
  • GitHub Check: cloud_aws_tests
  • GitHub Check: api_tests
  • GitHub Check: groupby_tests
  • GitHub Check: analyzer_tests
  • GitHub Check: flink_tests
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: online_tests
  • GitHub Check: join_tests
  • GitHub Check: aggregator_tests
  • GitHub Check: fetcher_tests
  • GitHub Check: batch_tests
  • GitHub Check: spark_tests
  • GitHub Check: enforce_triggered_workflows

Comment on lines 11 to 44
class BatchNodeRunner extends NodeRunner {

override def run(metadata: MetaData, conf: NodeContent, range: PartitionRange, tableUtils: TableUtils): Unit =
conf.getSetField match {
case NodeContent._Fields.MONOLITH_JOIN => {
val monolithJoin = conf.getMonolithJoin
require(monolithJoin.isSetJoin, "MonolithJoinNode must have a join set")
val spark = SparkSessionBuilder.build(f"node-batch-${metadata.name}")
val joinConf = monolithJoin.join
val joinName = joinConf.metaData.name

if (tableUtils.sparkSession.conf.get("spark.chronon.join.backfill.mode.skewFree", "false").toBoolean) {
logger.info(s" >>> Running join backfill in skew free mode <<< ")

logger.info(s"Filling partitions for join:$joinName, partitions:[${range.start}, ${range.end}]")

logger.info(s"Processing range $range)")
UnionJoin.computeJoinAndSave(joinConf, range)(tableUtils)
logger.info(s"Wrote range $range)")

}

val join = new Join(
joinConf,
range.end,
tableUtils
)

val df = join.computeJoin(overrideStartPartition = Option(range.start))

df.show(numRows = 3, truncate = 0, vertical = true)
logger.info(s"\nShowing three rows of output above.\nQuery table `${joinName}` for more.\n")

}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Session never stopped

SparkSessionBuilder.build starts a new session but run never calls stop, leaking executors.

@@
-        SparkSessionBuilder.build(f"node-batch-${metadata.name}")
+        val spark = SparkSessionBuilder.build(f"node-batch-${metadata.name}")
@@
         logger.info(s"\nShowing three rows of output above.\nQuery table `${joinName}` for more.\n")
+
+        spark.stop()

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In spark/src/main/scala/ai/chronon/spark/batch/BatchNodeRunner.scala between
lines 11 and 44, the SparkSession created by SparkSessionBuilder.build is never
stopped, causing resource leaks. To fix this, ensure that after all processing
with the SparkSession is complete, you call spark.stop() to properly release
resources. Add spark.stop() at the end of the run method or use a try-finally
block to guarantee the session is stopped even if exceptions occur.

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

♻️ Duplicate comments (1)
spark/src/main/scala/ai/chronon/spark/batch/BatchNodeRunner.scala (1)

54-56: SparkSession never stopped

Previous review still applies → executors leak. Wrap the public run in try … finally and call spark.stop().

-    run(metadata, conf, range, tableUtils(metadata.name))
+    val spark = SparkSessionBuilder.build(s"batch-node-runner-${metadata.name}")
+    try {
+      val utils = TableUtils(spark)
+      run(metadata, conf, range, utils)
+    } finally {
+      spark.stop()
+    }
🧹 Nitpick comments (1)
spark/src/main/scala/ai/chronon/spark/batch/BatchNodeRunner.scala (1)

32-34: Log string typo

Extra closing ) muddles the message.

-          logger.info(s"Processing range $range)")
+          logger.info(s"Processing range $range")
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0a956ea and 1852571.

📒 Files selected for processing (3)
  • api/src/main/scala/ai/chronon/api/planner/NodeRunner.scala (1 hunks)
  • spark/src/main/scala/ai/chronon/spark/batch/BatchNodeRunner.scala (1 hunks)
  • spark/src/test/scala/ai/chronon/spark/test/batch/BatchNodeRunnerTest.scala (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/src/main/scala/ai/chronon/api/planner/NodeRunner.scala
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: streaming_tests
  • GitHub Check: groupby_tests
  • GitHub Check: analyzer_tests
  • GitHub Check: batch_tests
  • GitHub Check: fetcher_tests
  • GitHub Check: join_tests
  • GitHub Check: spark_tests
  • GitHub Check: online_tests
  • GitHub Check: cloud_gcp_tests
  • GitHub Check: cloud_aws_tests
  • GitHub Check: service_tests
  • GitHub Check: service_commons_tests
  • GitHub Check: api_tests
  • GitHub Check: aggregator_tests
  • GitHub Check: flink_tests
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: enforce_triggered_workflows
🔇 Additional comments (1)
spark/src/test/scala/ai/chronon/spark/test/batch/BatchNodeRunnerTest.scala (1)

61-61: Duplicating dataset doubles row-count silently

itemQueriesDf.union(itemQueriesDf) inflates data while the final assertion only checks equality with the duplicated DF, masking accidental blow-ups. Consider using the original count or explicit deduping.

Comment on lines +82 to +83
BatchNodeRunner.run(joinConf.metaData, joinNodeContent, dateRange, tableUtils)

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Test bypasses public API

Calling the package-private overload hides the Spark leak fixed above. Invoke BatchNodeRunner.run(metadata, content, range) instead.

🤖 Prompt for AI Agents
In spark/src/test/scala/ai/chronon/spark/test/batch/BatchNodeRunnerTest.scala at
lines 82 to 83, the test calls a package-private overload of
BatchNodeRunner.run, bypassing the public API and hiding a Spark leak fix.
Replace the call to BatchNodeRunner.run(joinConf.metaData, joinNodeContent,
dateRange, tableUtils) with the public API method BatchNodeRunner.run(metadata,
content, range) to ensure the test uses the intended public interface and
includes the leak fix.

@tchow-zlai tchow-zlai requested a review from chewy-zlai June 16, 2025 21:20
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 (2)
api/src/main/scala/ai/chronon/api/planner/TableDependencies.scala (2)

6-6: Prefer non-deprecated CollectionConverters

scala.collection.JavaConverters._ is deprecated since 2.13; switch to scala.jdk.CollectionConverters._ to avoid deprecation noise.

-import scala.collection.JavaConverters._
+import scala.jdk.CollectionConverters._

11-13: Minor: simplify Option handling

A tiny simplification—using fold removes the intermediate Option:

-  Option(stagingQuery.tableDependencies)
-    .map(_.asScala.toSeq)
-    .getOrElse(Seq.empty)
+  Option(stagingQuery.tableDependencies)
+    .fold(Seq.empty[api.TableInfo])(_.asScala.toSeq)

Not critical, but trims a map/GetOrElse pair.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ea41c62 and a83235d.

📒 Files selected for processing (1)
  • api/src/main/scala/ai/chronon/api/planner/TableDependencies.scala (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
api/src/main/scala/ai/chronon/api/planner/TableDependencies.scala (1)
api/src/main/java/ai/chronon/api/thrift/Option.java (1)
  • Option (25-143)
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: groupby_tests
  • GitHub Check: analyzer_tests
  • GitHub Check: join_tests
  • GitHub Check: streaming_tests
  • GitHub Check: fetcher_tests
  • GitHub Check: spark_tests
  • GitHub Check: batch_tests
  • GitHub Check: service_tests
  • GitHub Check: cloud_aws_tests
  • GitHub Check: cloud_gcp_tests
  • GitHub Check: service_commons_tests
  • GitHub Check: api_tests
  • GitHub Check: online_tests
  • GitHub Check: aggregator_tests
  • GitHub Check: flink_tests
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: enforce_triggered_workflows

import ai.chronon.api
import ai.chronon.api.PartitionRange
import ai.chronon.planner.NodeContent
trait NodeRunner {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this meant to be the same runner to trigger non batch workloads too? If so, we'll probably want range to be optional

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah we'll extend for non batch workloads so I'll make it optional. Although right now we use PartitionRange(null, null) to represent something unbounded.

val joinName = metadata.name

if (tableUtils.sparkSession.conf.get("spark.chronon.join.backfill.mode.skewFree", "false").toBoolean) {
logger.info(s" >>> Running join backfill in skew free mode <<< ")
Copy link
Contributor

Choose a reason for hiding this comment

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

probably worth including these / similar log lines in the skew join case too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@tchow-zlai tchow-zlai merged commit ad0b3a8 into main Jun 17, 2025
25 of 27 checks passed
@tchow-zlai tchow-zlai deleted the tchow/batch-node-runner branch June 17, 2025 17:42
@coderabbitai coderabbitai bot mentioned this pull request Jun 18, 2025
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.

4 participants