Skip to content

feat: pass in the schema to ParquetTable from bigquery #695

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 2 commits into from

Conversation

tchow-zlai
Copy link
Collaborator

@tchow-zlai tchow-zlai commented Apr 29, 2025

Summary

Checklist

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

Summary by CodeRabbit

  • New Features

    • Added the ability to convert BigQuery schemas to Spark SQL schemas for improved compatibility with external tables.
  • Refactor

    • Improved organization and grouping of import statements for better code clarity.
  • Bug Fixes

    • Enhanced handling of external BigQuery tables by explicitly passing converted schemas when creating Parquet tables.

Copy link

coderabbitai bot commented Apr 29, 2025

Walkthrough

This update reorganizes import statements for clarity in multiple files and introduces a new utility method, toSparkSchema, in SparkBQUtils for converting BigQuery schemas to Spark schemas. The DelegatingBigQueryMetastoreCatalog is modified to use this new method, passing an explicit schema when constructing a ParquetTable for external BigQuery tables. No changes are made to public API signatures or overall control flow, and no business logic outside schema handling is affected.

Changes

File(s) Change Summary
cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryNative.scala Consolidated and reordered import statements for clarity; no logic changes.
cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/DelegatingBigQueryMetastoreCatalog.scala Reorganized imports; in loadTable, now passes explicit schema using SparkBQUtils.toSparkSchema for ParquetTable.
cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/SparkBQUtils.scala Added toSparkSchema method to convert BigQuery Schema to Spark StructType; added supporting imports.

Sequence Diagram(s)

sequenceDiagram
    participant BigQuery as BigQuery External Table
    participant DelegatingCatalog as DelegatingBigQueryMetastoreCatalog
    participant SparkBQUtils as SparkBQUtils
    participant ParquetTable as ParquetTable

    DelegatingCatalog->>BigQuery: Get ExternalTableDefinition (with schema)
    DelegatingCatalog->>SparkBQUtils: toSparkSchema(bqSchema)
    SparkBQUtils-->>DelegatingCatalog: StructType (Spark schema)
    DelegatingCatalog->>ParquetTable: Create ParquetTable with explicit schema
Loading

Possibly related PRs

Suggested reviewers

  • nikhil-zlai
  • piyush-zlai

Poem

In the land where schemas roam,
Spark and BigQuery found a home.
Imports tidied, methods new,
ParquetTables know what to do!
With structure clear and code concise,
This update’s neat—a schema’s paradise.
🗃️✨

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.


📜 Recent 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 c888f74 and 278a9bb.

📒 Files selected for processing (3)
  • cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryNative.scala (1 hunks)
  • cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/DelegatingBigQueryMetastoreCatalog.scala (2 hunks)
  • cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/SparkBQUtils.scala (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryNative.scala
🚧 Files skipped from review as they are similar to previous changes (2)
  • cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/DelegatingBigQueryMetastoreCatalog.scala
  • cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/SparkBQUtils.scala
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: service_commons_tests
  • GitHub Check: cloud_gcp_tests
  • GitHub Check: cloud_aws_tests
  • GitHub Check: service_tests
  • GitHub Check: hub_tests
  • GitHub Check: aggregator_tests
  • GitHub Check: api_tests
  • GitHub Check: online_tests
  • GitHub Check: flink_tests
  • GitHub Check: service_tests
  • GitHub Check: hub_tests
  • GitHub Check: cloud_gcp_tests
  • GitHub Check: aggregator_tests
  • GitHub Check: api_tests
  • GitHub Check: cloud_aws_tests
  • GitHub Check: online_tests
  • GitHub Check: flink_tests
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: enforce_triggered_workflows

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

@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)
cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/SparkBQUtils.scala (1)

28-32: New utility method for schema conversion

Clean implementation of BigQuery to Spark schema conversion. Consider adding error handling for malformed schemas.

 def toSparkSchema(bqSchema: Schema): StructType = {
   val schemaConverters = SchemaConverters.from(SchemaConvertersConfiguration.createDefault())
-  schemaConverters.toSpark(bqSchema)
+  try {
+    schemaConverters.toSpark(bqSchema)
+  } catch {
+    case e: Exception => 
+      throw new RuntimeException(s"Failed to convert BigQuery schema: ${e.getMessage}", e)
+  }

 }
📜 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 2a1a28a and 5b2afb8.

📒 Files selected for processing (3)
  • cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryNative.scala (1 hunks)
  • cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/DelegatingBigQueryMetastoreCatalog.scala (2 hunks)
  • cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/SparkBQUtils.scala (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: service_tests
  • GitHub Check: service_tests
  • GitHub Check: service_commons_tests
  • GitHub Check: hub_tests
  • GitHub Check: hub_tests
  • GitHub Check: cloud_gcp_tests
  • GitHub Check: cloud_gcp_tests
  • GitHub Check: cloud_aws_tests
  • GitHub Check: cloud_aws_tests
  • GitHub Check: api_tests
  • GitHub Check: online_tests
  • GitHub Check: online_tests
  • GitHub Check: aggregator_tests
  • GitHub Check: flink_tests
  • GitHub Check: flink_tests
  • GitHub Check: aggregator_tests
  • GitHub Check: scala_compile_fmt_fix
  • GitHub Check: api_tests
  • GitHub Check: enforce_triggered_workflows
🔇 Additional comments (6)
cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/SparkBQUtils.scala (2)

6-7: Added imports for BigQuery schema handling

New imports needed for the schema conversion utility.


11-12: Added Spark StructType import

Required for the return type of the new utility method.

cloud_gcp/src/main/scala/ai/chronon/integrations/cloud_gcp/BigQueryNative.scala (1)

3-7: Reorganized imports for better readability

Imports are now more logically grouped.

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

3-11: Reorganized imports

Improved import organization.


15-15: Moved NoSuchTableException import

Relocated for better organization.


116-117:

✅ Verification successful

Added explicit schema conversion for ParquetTable

Now using the schema from BigQuery instead of None. This improves schema accuracy.


🏁 Script executed:

#!/bin/bash
# Check if there are any other ParquetTable instances missing schema conversion
rg "ParquetTable\(" -A 10 | grep -B 5 -A 5 "None" | grep -v "Option(SparkBQUtils"

Length of output: 81


🏁 Script executed:

#!/bin/bash
# List all ParquetTable instantiations with context to verify schema conversion consistency
rg "ParquetTable\(" -n -A5 -B5

Length of output: 1666


Explicit schema conversion for ParquetTable

– Now passing Option(SparkBQUtils.toSparkSchema(...)) instead of None for ParquetTable
– Verified no other ParquetTable instantiations lack schema conversion

@tchow-zlai tchow-zlai changed the title wip feat: pass in the schema to ParquetTable from bigquery Apr 29, 2025
@tchow-zlai tchow-zlai force-pushed the tchow/bigquery-catalog branch from e6d9666 to c888f74 Compare April 29, 2025 02:23
tchow-zlai and others added 2 commits April 28, 2025 19:23
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/bigquery-catalog branch from c888f74 to 278a9bb Compare April 29, 2025 02:23
@tchow-zlai tchow-zlai closed this Apr 30, 2025
@tchow-zlai tchow-zlai deleted the tchow/bigquery-catalog branch April 30, 2025 01:20
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.

1 participant