Skip to content

Conversation

@piyush-zlai
Copy link
Contributor

@piyush-zlai piyush-zlai commented Jan 31, 2025

Summary

Update the Flink job code on the tiling path to use the TileKey. I haven't wired up the KV store side of things yet (can do the write and read side of the KV store collaboratively with Thomas as they need to go together to keep the tests happy).
The tiling version of the Flink job isn't in use so these changes should be safe to go and keeps things incremental.

Checklist

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

Summary by CodeRabbit

  • New Features

    • Added a utility to determine the start timestamp for a defined time window.
  • Refactor/Enhancements

    • Streamlined time window handling by providing a default one-day resolution when none is specified.
    • Improved tiled data processing with consistent tiling window sizing and enriched metadata management.
  • Tests

    • Updated integration tests to validate the new tile processing and time window behavior.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 31, 2025

Walkthrough

The pull request updates several modules to streamline window resolution and tiling functionality. In the aggregator, a method now returns a guaranteed long value instead of an optional. In the API, a new utility method for computing window start times is added. The Flink components are refactored to pass tiling window size as a mandatory parameter and adjust tile key processing accordingly, with corresponding changes in integration tests.

Changes

File(s) Change Summary
aggregator/.../Resolution.scala Modified getSmallestWindowResolutionInMillis: signature changed from Option[Long] to Long, returning a default one-day value when absent.
api/.../Extensions.scala Added new method windowStartMillis to compute the start of a time window based on a timestamp and window size.
flink/.../AvroCodecFn.scala Added tilingWindowSizeMs parameter; renamed variable to entityKeyBytes; built and serialized a new TileKey with tiling metadata in the output.
flink/.../FlinkJob.scala Updated tilingWindowSizeInMillis from Option[Long] to Long and modified the TiledAvroCodecFn constructor call to pass a non-optional tiling value.
flink/.../FlinkJobIntegrationTest.scala Introduced import for TilingUtils and updated key decoding to deserialize a TileKey before extracting bytes.

Sequence Diagram(s)

sequenceDiagram
    participant Job as FlinkJob
    participant Codec as TiledAvroCodecFn
    participant Utils as Window/TilingUtils
    participant Test as IntegrationTest

    Job->>Codec: Construct with tilingWindowSizeMs
    Codec->>Utils: Call windowStartMillis(timestamp, windowSize)
    Codec->>Codec: Build and serialize TileKey
    Test->>Utils: Deserialize TileKey from keyBytes
    Test->>Codec: Decode key using keyCodec
Loading

Possibly related PRs

Suggested reviewers

  • nikhil-zlai
  • tchow-zlai

Poem

In code’s deep realm, windows now shine,
Options turn certain, by design.
Tiles and keys in rhythm are set,
A streamlined flow we won’t forget!
Cheers to changes—light and sublime!

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.

@piyush-zlai piyush-zlai force-pushed the piyush/flink_tiling_writes branch 2 times, most recently from 1579735 to b03cdcb Compare February 3, 2025 18:21
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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 1

🛑 Comments failed to post (1)
cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigTableKVStoreImpl.scala (1)

453-458: ⚠️ Potential issue

Fix row key construction bug.

The second assignment to baseRowKey overwrites the first one, causing the dayTs to be lost.

 def buildTiledRowKey(baseKeyBytes: Seq[Byte], dataset: String, ts: Long, tileSizeMs: Long): Array[Byte] = {
   val baseRowKey = s"$dataset#".getBytes(Charset.forName("UTF-8")) ++ baseKeyBytes
   val dayTs = ts - (ts % 1.day.toMillis)
-  baseRowKey ++ s"#$dayTs".getBytes(Charset.forName("UTF-8"))
-  baseRowKey ++ s"#$tileSizeMs".getBytes(Charset.forName("UTF-8"))
+  baseRowKey ++ s"#$dayTs#$tileSizeMs".getBytes(Charset.forName("UTF-8"))
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

  def buildTiledRowKey(baseKeyBytes: Seq[Byte], dataset: String, ts: Long, tileSizeMs: Long): Array[Byte] = {
    val baseRowKey = s"$dataset#".getBytes(Charset.forName("UTF-8")) ++ baseKeyBytes
    val dayTs = ts - (ts % 1.day.toMillis)
    baseRowKey ++ s"#$dayTs#$tileSizeMs".getBytes(Charset.forName("UTF-8"))
  }

@piyush-zlai piyush-zlai force-pushed the piyush/flink_tiling_writes branch from b03cdcb to a6053a3 Compare February 3, 2025 19:37
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)
flink/src/main/scala/ai/chronon/flink/AvroCodecFn.scala (1)

165-186: Consider performance and logging improvements.

Two suggestions:

  1. Avoid unnecessary List conversion of entityKeyBytes
  2. Include TileKey details in debug logging
-    tileKey.setKeyBytes(entityKeyBytes.toList.asJava.asInstanceOf[java.util.List[java.lang.Byte]])
+    // Use Arrays.asList for better performance
+    tileKey.setKeyBytes(java.util.Arrays.asList(entityKeyBytes:_*).asInstanceOf[java.util.List[java.lang.Byte]])

     logger.debug(
       s"""
         |Avro converting tile to PutRequest - tile=${in}
         |groupBy=${groupByServingInfoParsed.groupBy.getMetaData.getName} tsMills=$tsMills keys=$keys
         |keyBytes=${java.util.Base64.getEncoder.encodeToString(entityKeyBytes)}
         |valueBytes=${java.util.Base64.getEncoder.encodeToString(valueBytes)}
-        |streamingDataset=$streamingDataset""".stripMargin
+        |streamingDataset=$streamingDataset
+        |tileKey=$tileKey""".stripMargin
📜 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 1579735 and a6053a3.

📒 Files selected for processing (5)
  • aggregator/src/main/scala/ai/chronon/aggregator/windowing/Resolution.scala (1 hunks)
  • api/src/main/scala/ai/chronon/api/Extensions.scala (1 hunks)
  • flink/src/main/scala/ai/chronon/flink/AvroCodecFn.scala (3 hunks)
  • flink/src/main/scala/ai/chronon/flink/FlinkJob.scala (3 hunks)
  • flink/src/test/scala/ai/chronon/flink/test/FlinkJobIntegrationTest.scala (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • flink/src/test/scala/ai/chronon/flink/test/FlinkJobIntegrationTest.scala
  • aggregator/src/main/scala/ai/chronon/aggregator/windowing/Resolution.scala
  • flink/src/main/scala/ai/chronon/flink/FlinkJob.scala
  • api/src/main/scala/ai/chronon/api/Extensions.scala
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: no_spark_scala_tests
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: enforce_triggered_workflows
🔇 Additional comments (2)
flink/src/main/scala/ai/chronon/flink/AvroCodecFn.scala (2)

6-10: LGTM!

Required imports added for TileKey integration.


132-135: LGTM!

Constructor updated to include required tiling window size.

val tileKey = new TileKey()
val tileStart = WindowUtils.windowStartMillis(tsMills, tilingWindowSizeMs)
tileKey.setDataset(streamingDataset)
tileKey.setKeyBytes(entityKeyBytes.toList.asJava.asInstanceOf[java.util.List[java.lang.Byte]])
Copy link
Collaborator

Choose a reason for hiding this comment

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

might be better to box individually? eg.

keyBytes.map(java.lang.Byte.valueOf).toList.asJava

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with this as I thought it would be better to skip iterating over all the bytes in the key bytes list given Scala and Java bytes are equivalent - so we can just do a constant time operation of casting the top level types.
Seems to work in unit tests. Wdyt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

okay I thought it would have been an Exception but if it works in UT's that's good.


/**
* Find the smallest tail window resolution in a GroupBy. Returns None if the GroupBy does not define any windows.
* Find the smallest tail window resolution in a GroupBy. Returns 1D if the GroupBy does not define any windows (all-time aggregates).
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you expand on this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah so if a user creates a GroupBy with no windows we end up defaulting to all time windows in Chronon. Currently the Flink code will throw an error for this scenario (we return None here and in FlinkJob when we call .get it errors out). Instead of failing we go with a 1D tile size as thats the best option to help us compute the all time window (batch has the rest)

@piyush-zlai piyush-zlai merged commit 93a5810 into main Feb 4, 2025
6 checks passed
@piyush-zlai piyush-zlai deleted the piyush/flink_tiling_writes branch February 4, 2025 21:38
@coderabbitai coderabbitai bot mentioned this pull request Feb 13, 2025
4 tasks
kumar-zlai pushed a commit that referenced this pull request Apr 25, 2025
## Summary
Update the Flink job code on the tiling path to use the TileKey. I
haven't wired up the KV store side of things yet (can do the write and
read side of the KV store collaboratively with Thomas as they need to go
together to keep the tests happy).
The tiling version of the Flink job isn't in use so these changes should
be safe to go and keeps things incremental.

## Checklist
- [ ] Added Unit Tests
- [X] 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 a utility to determine the start timestamp for a defined time
window.

- **Refactor/Enhancements**
- Streamlined time window handling by providing a default one-day
resolution when none is specified.
- Improved tiled data processing with consistent tiling window sizing
and enriched metadata management.

- **Tests**
- Updated integration tests to validate the new tile processing and time
window behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
kumar-zlai pushed a commit that referenced this pull request Apr 29, 2025
## Summary
Update the Flink job code on the tiling path to use the TileKey. I
haven't wired up the KV store side of things yet (can do the write and
read side of the KV store collaboratively with Thomas as they need to go
together to keep the tests happy).
The tiling version of the Flink job isn't in use so these changes should
be safe to go and keeps things incremental.

## Checklist
- [ ] Added Unit Tests
- [X] 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 a utility to determine the start timestamp for a defined time
window.

- **Refactor/Enhancements**
- Streamlined time window handling by providing a default one-day
resolution when none is specified.
- Improved tiled data processing with consistent tiling window sizing
and enriched metadata management.

- **Tests**
- Updated integration tests to validate the new tile processing and time
window behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
chewy-zlai pushed a commit that referenced this pull request May 15, 2025
## Summary
Update the Flink job code on the tiling path to use the TileKey. I
haven't wired up the KV store side of things yet (can do the write and
read side of the KV store collaboratively with Thomas as they need to go
together to keep the tests happy).
The tiling version of the Flink job isn't in use so these changes should
be safe to go and keeps things incremental.

## Checklist
- [ ] Added Unit Tests
- [X] 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 a utility to determine the start timestamp for a defined time
window.

- **Refactor/Enhancements**
- Streamlined time window handling by providing a default one-day
resolution when none is specified.
- Improved tiled data processing with consistent tiling window sizing
and enriched metadata management.

- **Tests**
- Updated integration tests to validate the new tile processing and time
window behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
chewy-zlai pushed a commit that referenced this pull request May 15, 2025
## Summary
Update the Flink job code on the tiling path to use the TileKey. I
haven't wired up the KV store side of things yet (can do the write and
read side of the KV store collaboratively with Thomas as they need to go
together to keep the tests happy).
The tiling version of the Flink job isn't in use so these changes should
be safe to go and keeps things incremental.

## Checklist
- [ ] Added Unit Tests
- [X] 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 a utility to determine the start timestamp for a defined time
window.

- **Refactor/Enhancements**
- Streamlined time window handling by providing a default one-day
resolution when none is specified.
- Improved tiled data processing with consistent tiling window sizing
and enriched metadata management.

- **Tests**
- Updated integration tests to validate the new tile processing and time
window behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
chewy-zlai pushed a commit that referenced this pull request May 16, 2025
## Summary
Update the Flink job code on the tiling path to use the TileKey. I
haven't wired up the KV store side of things yet (can do the write and
read side of the KV store collaboratively with Thomas as they need to go
together to keep the tests happy).
The tiling version of the Flink job isn't in use so these changes should
be safe to go and keeps things incremental.

## Cheour clientslist
- [ ] Added Unit Tests
- [X] 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 a utility to determine the start timestamp for a defined time
window.

- **Refactor/Enhancements**
- Streamlined time window handling by providing a default one-day
resolution when none is specified.
- Improved tiled data processing with consistent tiling window sizing
and enriched metadata management.

- **Tests**
- Updated integration tests to validate the new tile processing and time
window behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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