Skip to content

chore: Use referenced_property_graphs api to get property graph name for schema view#16174

Draft
ericfe-google wants to merge 8 commits intomainfrom
referenced_property_graphs
Draft

chore: Use referenced_property_graphs api to get property graph name for schema view#16174
ericfe-google wants to merge 8 commits intomainfrom
referenced_property_graphs

Conversation

@ericfe-google
Copy link
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@ericfe-google ericfe-google changed the title Referenced property graphs chore: Use referenced_property_graphs api to get property graph name for schema view Mar 25, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 introduces significant improvements to how BigQuery property graphs are identified and managed within the BigQuery client library and BigQuery Magics. By adding a dedicated PropertyGraphReference object and a referenced_property_graphs property to QueryJob, the system now programmatically accesses property graph metadata directly from BigQuery job statistics. This change enhances the accuracy and robustness of graph schema retrieval, moving away from string parsing to a more integrated API-driven approach.

Highlights

  • New PropertyGraphReference Class: Introduced a new PropertyGraphReference class within the google-cloud-bigquery library to provide a structured representation for BigQuery property graph references, including project, dataset, and graph IDs.
  • Enhanced QueryJob Property: Added a referenced_property_graphs property to the QueryJob class, allowing direct retrieval of property graph references from BigQuery job statistics, improving data access and reliability.
  • Refactored Graph Schema Retrieval in BigQuery Magics: Updated BigQuery Magics to leverage the new referenced_property_graphs property for fetching graph schema, replacing the previous regex-based parsing of query text for more robust identification.
  • Updated Testing Suite: Expanded unit tests to cover the new property graph reference functionality, including scenarios for zero, single, and multiple referenced graphs, and adjusted existing graph-related tests to align with the new schema retrieval mechanism.
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.

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.

Copy link
Contributor

@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 enhances the BigQuery client libraries to support Property Graph queries. It introduces a new PropertyGraphReference class and adds a referenced_property_graphs property to the QueryJob object, allowing retrieval of property graph metadata from query job statistics. The bigquery-magics package is updated to utilize this new client library functionality, replacing manual parsing of GRAPH queries with the more robust referenced_property_graphs property. This includes refactoring the _get_graph_schema function and updating/adding several unit tests to cover the new logic. Additionally, some test assertions for user agents were updated to use startswith, and a retry mechanism initialization was modified in a test. A review comment suggests improving the mocking strategy in some tests by using mock.create_autospec and directly manipulating the _properties dictionary for QueryJob to enhance test robustness.

Comment on lines +1236 to +1245
query_job = mock.Mock()
query_job.configuration.destination.project = "p"
query_job.configuration.destination.dataset_id = "d"
query_job.configuration.destination.table_id = "t"

graph_ref = mock.Mock()
graph_ref.project = "p"
graph_ref.dataset_id = "my_dataset"
graph_ref.property_graph_id = "my_graph"
query_job.referenced_property_graphs = [graph_ref]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Using mock.Mock() is less safe than mock.create_autospec as it doesn't enforce the mocked object's interface. It's better to stick with create_autospec for better test robustness. You can mock the referenced_property_graphs property by setting the underlying _properties dictionary, which is how the property gets its data. This is more aligned with how the actual QueryJob object works.

This feedback also applies to test_add_graph_widget_no_graph_name and test_add_graph_widget_schema_not_found.

Suggested change
query_job = mock.Mock()
query_job.configuration.destination.project = "p"
query_job.configuration.destination.dataset_id = "d"
query_job.configuration.destination.table_id = "t"
graph_ref = mock.Mock()
graph_ref.project = "p"
graph_ref.dataset_id = "my_dataset"
graph_ref.property_graph_id = "my_graph"
query_job.referenced_property_graphs = [graph_ref]
query_job = mock.create_autospec(bigquery.job.QueryJob, instance=True)
query_job.configuration.destination.project = "p"
query_job.configuration.destination.dataset_id = "d"
query_job.configuration.destination.table_id = "t"
graph_ref_resource = {
"projectId": "p",
"datasetId": "my_dataset",
"propertyGraphId": "my_graph",
}
query_job._properties = {
"statistics": {
"query": {"referencedPropertyGraphs": [graph_ref_resource]}
}
}

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