Skip to content

Conversation

@tchow-zlai
Copy link
Collaborator

@tchow-zlai tchow-zlai commented Mar 13, 2025

Summary

  • This PR cleans up a few abstractions in the GCPFormatProvider
  • Clean up some projectId handling
  • In the unit tests, sent a commented example configuration set for multiple catalogs.

Checklist

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

Summary by CodeRabbit

  • Refactor

    • Streamlined BigQuery integration with improved table identifier parsing and project recognition.
    • Enhanced error messaging, now providing clearer feedback when database information is missing.
    • Simplified the process for detecting table formats for more consistent data access.
    • Consolidated import statements for better organization.
  • New Features

    • Introduced a new utility for converting table names into a structured format.
  • Tests

    • Added a new test case to verify table name parsing consistency.
    • Updated Spark SQL catalog configuration to ensure reliable referencing of external tables.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2025

Walkthrough

This PR refactors and streamlines the BigQuery integration and related Spark components. The BigQueryFormat is converted from a case class to a case object with removed constructor parameters and a newly introduced lazy value for options. The GcpFormatProvider now directly parses table IDs, removing redundant methods. Additionally, the Spark SQL catalog test configuration is updated, and minor import reorganizations and method removals are applied in Spark utilities and traits.

Changes

File(s) Change Summary
cloud_gcp/.../BigQueryFormat.scala
cloud_gcp/.../GcpFormatProvider.scala
Refactored BigQueryFormat from case class to object (removed parameters, added lazy bqOptions, updated partition method) and restructured GcpFormatProvider by modifying readFormat and removing redundant methods (resolveTableName, format).
cloud_gcp/.../BigQueryCatalogTest.scala Updated Spark SQL catalog settings: removed outdated configuration lines and adjusted the external table reference to "default_bigquery.data.checkouts_parquet".
spark/.../TableUtils.scala
spark/.../format/FormatProvider.scala
Consolidated import statements in TableUtils and removed the redundant resolveTableName method from FormatProvider trait.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant GcpFormatProvider
    participant BigQueryUtil
    participant BigQueryClient
    participant Definition

    Caller->>GcpFormatProvider: readFormat(tableName)
    GcpFormatProvider->>BigQueryUtil: parseTableId(tableName)
    BigQueryUtil-->>GcpFormatProvider: TableId(project, dataset, table)
    GcpFormatProvider->>BigQueryClient: getTable(TableId)
    BigQueryClient-->>GcpFormatProvider: Table definition
    GcpFormatProvider->>Definition: getFormat(definition)
    Definition-->>GcpFormatProvider: Format info
    GcpFormatProvider-->>Caller: Format Option
Loading

Possibly related PRs

Suggested reviewers

  • nikhil-zlai
  • piyush-zlai
  • varant-zlai

Poem

In code we refactored, crisp and neat,
BigQuery now stands on unyielding feet.
Providers streamline with a fresh new flow,
Spark’s settings updated—onward we go!
Cheers to clean code, a joyous light 🌟
Where logic dances through the night!

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

tchow-zlai and others added 3 commits March 13, 2025 10:43
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 tchow/no-delegating branch from cfceeff to a0d29ef Compare March 13, 2025 17:43
@tchow-zlai tchow-zlai changed the title feat: Use multiple catalogs instead of a delegating catalog feat: Use project id that's specified in the table name for the bigquery connector Mar 13, 2025
Copy link
Contributor

@david-zlai david-zlai left a comment

Choose a reason for hiding this comment

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

couple of questions but makes sense

Comment on lines 29 to 30
val multipartIdentifier =
sparkSession.sessionState.sqlParser.parseMultipartIdentifier(tableName)
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this?

Copy link
Collaborator Author

@tchow-zlai tchow-zlai Mar 13, 2025

Choose a reason for hiding this comment

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

this would be to make things consistent with spark. For example, using backticks in spark:

`etsy-zipline-dev`.search.table_name

would be handled differently in the bigquery parser and the spark sql parser. Ideally we just want to use spark syntax and pass the results to bigquery.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

let me write a test for this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

import ai.chronon.api.Query
import ai.chronon.api.QueryUtils
import ai.chronon.api.TsUtils
import ai.chronon.api.{Constants, PartitionRange, PartitionSpec, Query, QueryUtils, TsUtils}
Copy link
Contributor

Choose a reason for hiding this comment

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

which convention should we be using haha

feel like mine has been breaking them out individually

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I feel like it makes more sense to bracket them but no strong opinions.

Copy link
Contributor

@david-zlai david-zlai left a comment

Choose a reason for hiding this comment

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

@tchow-zlai - let's run an integration test if we can beforehand though

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

🧹 Nitpick comments (1)
cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryFormat.scala (1)

64-95: Consider refactoring partition format handling

The TODO comment about partition format indicates this is a temporary solution.

Should we address this now or track it as a separate issue?

📜 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 a0d29ef and 7cc4b23.

📒 Files selected for processing (4)
  • cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryFormat.scala (4 hunks)
  • cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/GcpFormatProvider.scala (4 hunks)
  • cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/SparkBQUtils.scala (1 hunks)
  • cloud_gcp/src/test/scala/ai/chronon/integrations/cloud_gcp/BigQueryCatalogTest.scala (4 hunks)
🧰 Additional context used
🧠 Learnings (3)
cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/SparkBQUtils.scala (1)
Learnt from: tchow-zlai
PR: zipline-ai/chronon#263
File: cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryFormat.scala:29-60
Timestamp: 2025-03-12T15:28:06.350Z
Learning: In BigQuery integration, table existence check is performed outside the BigQueryFormat.createTable method, at a higher level in TableUtils.createTable.
cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryFormat.scala (2)
Learnt from: tchow-zlai
PR: zipline-ai/chronon#263
File: cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryFormat.scala:29-60
Timestamp: 2025-03-12T15:28:06.350Z
Learning: In BigQuery integration, table existence check is performed outside the BigQueryFormat.createTable method, at a higher level in TableUtils.createTable.
Learnt from: tchow-zlai
PR: zipline-ai/chronon#263
File: cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryFormat.scala:56-57
Timestamp: 2025-03-12T15:28:06.350Z
Learning: For BigQuery table creation operations in BigQueryFormat.scala, allow exceptions to propagate directly without wrapping them in try-catch blocks, as the original BigQuery exceptions provide sufficient context.
cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/GcpFormatProvider.scala (2)
Learnt from: tchow-zlai
PR: zipline-ai/chronon#263
File: cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryFormat.scala:29-60
Timestamp: 2025-03-12T15:28:06.350Z
Learning: In BigQuery integration, table existence check is performed outside the BigQueryFormat.createTable method, at a higher level in TableUtils.createTable.
Learnt from: tchow-zlai
PR: zipline-ai/chronon#263
File: cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryFormat.scala:56-57
Timestamp: 2025-03-12T15:28:06.350Z
Learning: For BigQuery table creation operations in BigQueryFormat.scala, allow exceptions to propagate directly without wrapping them in try-catch blocks, as the original BigQuery exceptions provide sufficient context.
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: streaming_tests
  • GitHub Check: join_tests
  • GitHub Check: streaming_tests
  • GitHub Check: groupby_tests
  • GitHub Check: groupby_tests
  • GitHub Check: analyzer_tests
  • GitHub Check: fetcher_tests
  • GitHub Check: fetcher_tests
  • GitHub Check: analyzer_tests
  • GitHub Check: spark_tests
  • GitHub Check: join_tests
  • GitHub Check: spark_tests
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: non_spark_tests
  • GitHub Check: non_spark_tests
🔇 Additional comments (9)
cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/SparkBQUtils.scala (1)

8-15: LGTM - Clean utility implementation

This utility method correctly handles table name parsing for BigQuery, addressing project ID requirements.

cloud_gcp/src/test/scala/ai/chronon/integrations/cloud_gcp/BigQueryCatalogTest.scala (2)

69-82: LGTM - Thorough table name parsing test

Test verifies proper handling of project IDs with backticks for Spark compatibility.


107-107: LGTM - Updated external table reference

External table reference now includes catalog prefix.

cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/GcpFormatProvider.scala (3)

25-28: LGTM - Simplified table lookup using SparkBQUtils

Refactored code now directly parses table names using the new utility method.


45-52: LGTM - Simplified property access

Direct property access from definition improves code readability.


58-58: LGTM - Removed unnecessary parameters

BigQueryFormat is now a case object with no parameters.

cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryFormat.scala (3)

10-11: LGTM - Converted to case object

Changed from case class to case object and removed constructor parameters.


28-33: LGTM - Uses table identifier to determine project

Correctly retrieves project from table identifier or falls back to default.


38-38: LGTM - Updated project reference in queries

SQL queries now use providedProject from TableId.

Also applies to: 59-59, 71-71

Comment on lines +41 to 54
"spark.sql.catalogImplementation" -> "in-memory",

// "spark.sql.defaultCatalog" -> "default_iceberg",
// "spark.sql.catalog.default_iceberg" -> classOf[SparkCatalog].getName,
// "spark.sql.catalog.default_iceberg.catalog-impl" -> classOf[BQMSCatalog].getName,
// "spark.sql.catalog.default_iceberg.io-impl" -> classOf[ResolvingFileIO].getName,
// "spark.sql.catalog.default_iceberg.warehouse" -> "gs://zipline-warehouse-canary/data/tables/",
// "spark.sql.catalog.default_iceberg.gcp_location" -> "us-central1",
// "spark.sql.catalog.default_iceberg.gcp_project" -> "canary-443022",
//
//
// "spark.sql.catalogImplementation" -> "in-memory",
// "spark.kryo.registrator" -> classOf[ChrononIcebergKryoRegistrator].getName,
// "spark.sql.defaultUrlStreamHandlerFactory.enabled" -> false.toString,
//
// "spark.sql.catalog.default_bigquery" -> classOf[BigQueryCatalog].getName,
))
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 uncommenting catalog configurations

The Spark SQL catalog configurations are now commented out. Verify if they should remain this way.


🏁 Script executed:

#!/bin/bash
# Verify if catalog configurations are used elsewhere
rg "spark.sql.catalog" --type scala -A 2 -B 2

Length of output: 6581


Action: Clarify Catalog Config in BigQuery Test

The test intentionally uses "spark.sql.catalogImplementation" -> "in-memory". The legacy, commented-out catalog configurations (for default_iceberg/default_bigquery) aren’t active anywhere. Please either remove these lines to reduce noise or add comments explaining their intended future use.

@tchow-zlai
Copy link
Collaborator Author

@tchow-zlai - let's run an integration test if we can beforehand though

Done - had to update the additional-confs.yaml

@tchow-zlai tchow-zlai merged commit e7d9933 into main Mar 14, 2025
18 of 34 checks passed
@tchow-zlai tchow-zlai deleted the tchow/no-delegating branch March 14, 2025 04:55
@coderabbitai coderabbitai bot mentioned this pull request Mar 14, 2025
4 tasks
@coderabbitai coderabbitai bot mentioned this pull request Apr 18, 2025
4 tasks
kumar-zlai pushed a commit that referenced this pull request Apr 25, 2025
…ery connector (#500)

## Summary

- This PR cleans up a few abstractions in the GCPFormatProvider
- Clean up some projectId handling
- In the unit tests, sent a commented example configuration set for
multiple catalogs.


## 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

- **Refactor**
- Streamlined BigQuery integration with improved table identifier
parsing and project recognition.
- Enhanced error messaging, now providing clearer feedback when database
information is missing.
- Simplified the process for detecting table formats for more consistent
data access.
  - Consolidated import statements for better organization.

- **New Features**
- Introduced a new utility for converting table names into a structured
format.

- **Tests**
  - Added a new test case to verify table name parsing consistency.
- Updated Spark SQL catalog configuration to ensure reliable referencing
of external tables.
<!-- 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: Thomas Chow <[email protected]>
kumar-zlai pushed a commit that referenced this pull request Apr 29, 2025
…ery connector (#500)

## Summary

- This PR cleans up a few abstractions in the GCPFormatProvider
- Clean up some projectId handling
- In the unit tests, sent a commented example configuration set for
multiple catalogs.


## 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

- **Refactor**
- Streamlined BigQuery integration with improved table identifier
parsing and project recognition.
- Enhanced error messaging, now providing clearer feedback when database
information is missing.
- Simplified the process for detecting table formats for more consistent
data access.
  - Consolidated import statements for better organization.

- **New Features**
- Introduced a new utility for converting table names into a structured
format.

- **Tests**
  - Added a new test case to verify table name parsing consistency.
- Updated Spark SQL catalog configuration to ensure reliable referencing
of external tables.
<!-- 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: Thomas Chow <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request May 6, 2025
4 tasks
chewy-zlai pushed a commit that referenced this pull request May 15, 2025
…ery connector (#500)

## Summary

- This PR cleans up a few abstractions in the GCPFormatProvider
- Clean up some projectId handling
- In the unit tests, sent a commented example configuration set for
multiple catalogs.


## 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

- **Refactor**
- Streamlined BigQuery integration with improved table identifier
parsing and project recognition.
- Enhanced error messaging, now providing clearer feedback when database
information is missing.
- Simplified the process for detecting table formats for more consistent
data access.
  - Consolidated import statements for better organization.

- **New Features**
- Introduced a new utility for converting table names into a structured
format.

- **Tests**
  - Added a new test case to verify table name parsing consistency.
- Updated Spark SQL catalog configuration to ensure reliable referencing
of external tables.
<!-- 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: Thomas Chow <[email protected]>
chewy-zlai pushed a commit that referenced this pull request May 15, 2025
…ery connector (#500)

## Summary

- This PR cleans up a few abstractions in the GCPFormatProvider
- Clean up some projectId handling
- In the unit tests, sent a commented example configuration set for
multiple catalogs.


## 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

- **Refactor**
- Streamlined BigQuery integration with improved table identifier
parsing and project recognition.
- Enhanced error messaging, now providing clearer feedback when database
information is missing.
- Simplified the process for detecting table formats for more consistent
data access.
  - Consolidated import statements for better organization.

- **New Features**
- Introduced a new utility for converting table names into a structured
format.

- **Tests**
  - Added a new test case to verify table name parsing consistency.
- Updated Spark SQL catalog configuration to ensure reliable referencing
of external tables.
<!-- 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: Thomas Chow <[email protected]>
chewy-zlai pushed a commit that referenced this pull request May 16, 2025
…ery connector (#500)

## Summary

- This PR cleans up a few abstractions in the GCPFormatProvider
- Clean up some projectId handling
- In the unit tests, sent a commented example configuration set for
multiple catalogs.


## 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

- **Refactor**
- Streamlined BigQuery integration with improved table identifier
parsing and project recognition.
- Enhanced error messaging, now providing clearer feedbaour clients when database
information is missing.
- Simplified the process for detecting table formats for more consistent
data access.
  - Consolidated import statements for better organization.

- **New Features**
- Introduced a new utility for converting table names into a structured
format.

- **Tests**
  - Added a new test case to verify table name parsing consistency.
- Updated Spark SQL catalog configuration to ensure reliable referencing
of external tables.
<!-- 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: 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