Skip to content

Conversation

@BoqianShi
Copy link
Member

@BoqianShi BoqianShi commented Oct 23, 2025

This PR enhances the BigQueryCatalog by adding support for specifying a project and location directly in the Spark configuration. This allows users to easily register and interact with BigQuery datasets from different projects and locations without having to override the global parentProjectId.

This makes it easier to work with datasets in different projects and regions. For example, you can now read from a public dataset in one project and write to a table in a specific location (e.g., "US") in your own project.

How to Use
Users can now configure a BigQuery catalog with a specific project and location like this:

spark.conf.set("spark.sql.catalog.my_catalog", "com.google.cloud.spark.bigquery.BigQueryCatalog")
spark.conf.set("spark.sql.catalog.my_catalog.projectId", "bigquery-public-data")
spark.conf.set("spark.sql.catalog.my_catalog.location", "US")

@BoqianShi
Copy link
Member Author

/gcbrun

@gemini-code-assist
Copy link

Summary of Changes

Hello @BoqianShi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the BigQueryCatalog by introducing support for per-catalog configuration of BigQuery project IDs and locations. This allows Spark users to define specific BigQuery projects and geographical regions for each registered catalog, providing greater flexibility when interacting with diverse BigQuery datasets. The change streamlines workflows that involve reading from public datasets in one project and writing to tables in a different project or region, eliminating the need to manage global overrides and simplifying complex data pipelines.

Highlights

  • Per-Catalog Project and Location Configuration: Users can now specify a dedicated BigQuery project ID and geographical location for each individual BigQueryCatalog registered in Spark. This allows for more granular control over data access and storage.
  • Enhanced BigQuery Client Integration: The underlying BigQuery client now prioritizes these per-catalog project and location settings for operations like dataset creation, falling back to global configurations if catalog-specific ones are not provided.
  • Improved Flexibility for Multi-Project/Region Workflows: This enhancement simplifies scenarios where users need to interact with BigQuery datasets residing in different projects or regions within a single Spark application, such as reading from public datasets and writing to private ones in a specific location.
  • Comprehensive Testing: New unit and integration tests have been added to validate the correct parsing, application, and functionality of these new per-catalog project and location configurations, ensuring robustness.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@BoqianShi
Copy link
Member Author

/gcbrun

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for per-catalog configuration of project and location for the BigQueryCatalog. The changes correctly plumb the new configuration options through to the BigQueryClient used by the catalog for namespace-level operations. However, there is a significant issue where these catalog-level configurations are not propagated to the Table objects returned by loadTable and createTable. This means that table-level operations, such as reads and writes, will not use the specified project or location from the catalog configuration, making the feature incomplete. I've added a detailed comment with a suggested fix for this issue.

@BoqianShi
Copy link
Member Author

/gcbrun

1 similar comment
@BoqianShi
Copy link
Member Author

/gcbrun

@BoqianShi
Copy link
Member Author

/gcbrun


public void createDataset(DatasetId datasetId, Map<String, String> metadata) {
DatasetInfo.Builder datasetInfo = DatasetInfo.newBuilder(datasetId);
Optional.ofNullable(bigQuery.getOptions().getLocation()).ifPresent(datasetInfo::setLocation);
Copy link
Member

Choose a reason for hiding this comment

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

Please add comment for this line explaining why it is there

Copy link
Member Author

Choose a reason for hiding this comment

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

In a non-catalog scenario, both BigQueryOptions.quotaProjectId and BigQueryOptions.projectId will be set to the parent projectId, as before.

config.parentProjectId =
getAnyOption(globalOptions, options, "parentProject").or(defaultBilledProject());
config.catalogProjectId = getOption(options, "projectId");
config.catalogLocation = getOption(options, "location");
Copy link
Member

Choose a reason for hiding this comment

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

Is the parameter location or bigquery_location?

com.google.common.base.Optional<String> temporaryGcsBucket = empty();
com.google.common.base.Optional<String> persistentGcsBucket = empty();
com.google.common.base.Optional<String> persistentGcsPath = empty();
com.google.common.base.Optional<String> catalogProjectId = empty();
Copy link
Member

Choose a reason for hiding this comment

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

add comment why do we need a separate set of properties

.setRetrySettings(config.getBigQueryClientRetrySettings())
.setUniverseDomain(bigQueryCredentialsSupplier.getUniverseDomain());

// Determine the project for data location (the catalog's project, if specified)
Copy link
Member

Choose a reason for hiding this comment

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

What happens if this is used in non-catalog scenario?

@BoqianShi
Copy link
Member Author

/gcbrun

1 similar comment
@BoqianShi
Copy link
Member Author

/gcbrun

@BoqianShi
Copy link
Member Author

/gcbrun

@BoqianShi
Copy link
Member Author

/gcbrun

1 similar comment
@BoqianShi
Copy link
Member Author

/gcbrun

@BoqianShi
Copy link
Member Author

/gcbrun

@BoqianShi BoqianShi force-pushed the catalog-config branch 2 times, most recently from 305ed1f to 5ec52be Compare November 7, 2025 03:27
@BoqianShi
Copy link
Member Author

/gcbrun

@BoqianShi
Copy link
Member Author

/gcbrun

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