Conversation
We now only include query results directly in the html when the query results are less than 100 KB. For larger query results, we store only the reference to the destination table in the HTML, and have the python code re-read the query results from the destination table during the callback. Also, added a hard limit of 5 MB in the query result size, beyond which, graph visualization is not supported altogether.
…d Spanner. This avoids clashes if the same notebook uses visualizers for both BigQuery graphs and Spanner graphs, which can cause malfunctions in the visualizers.
Summary of ChangesHello @ericfe-google, 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 enhances the BigQuery Magics' graph visualization capabilities by integrating schema information directly into the graph rendering process. By programmatically fetching and converting graph metadata from BigQuery's INFORMATION_SCHEMA, the visualization widget can now present more structured and contextually rich graphs, improving the user's understanding of their data relationships. This change streamlines the workflow for users interacting with property graphs in BigQuery. Highlights
Changelog
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request adds functionality to retrieve and display graph schemas by parsing the graph name from a query, fetching the schema from INFORMATION_SCHEMA, and passing it to the visualization framework. The overall approach is sound, but I've identified a critical SQL injection vulnerability that must be addressed. Additionally, I've noted some fragile logic related to string escaping and testing that could be improved for better maintainability.
| # Verify generate_visualization_html was called with the converted schema | ||
| assert gen_html_mock.called | ||
| params_str = gen_html_mock.call_args[1]["params"] | ||
| params = json.loads(params_str.replace('\\"', '"').replace("\\\\", "\\")) |
There was a problem hiding this comment.
The logic to parse params_str by manually reversing escaping is brittle and is repeated in the new tests (lines 1163, 1207, 1252). This can easily break if the escaping logic in _add_graph_widget changes or for more complex inputs. Assuming the problematic escaping in _add_graph_widget is fixed as per my other comment, you can simplify this to just load the JSON string.
| params = json.loads(params_str.replace('\\"', '"').replace("\\\\", "\\")) | |
| params = json.loads(params_str) |
| # Verify generate_visualization_html was called without a schema | ||
| assert gen_html_mock.called | ||
| params_str = gen_html_mock.call_args[1]["params"] | ||
| params = json.loads(params_str.replace('\\"', '"').replace("\\\\", "\\")) |
There was a problem hiding this comment.
This test logic is brittle because it tries to manually reverse the escaping done in _add_graph_widget. This can easily break if the escaping logic changes or for more complex inputs. A better approach would be to simplify the test by just loading the JSON string, assuming the problematic escaping in _add_graph_widget is fixed.
| params = json.loads(params_str.replace('\\"', '"').replace("\\\\", "\\")) | |
| params = json.loads(params_str) |
| # Verify generate_visualization_html was called without a schema | ||
| assert gen_html_mock.called | ||
| params_str = gen_html_mock.call_args[1]["params"] | ||
| params = json.loads(params_str.replace('\\"', '"').replace("\\\\", "\\")) |
There was a problem hiding this comment.
This test logic is brittle because it tries to manually reverse the escaping done in _add_graph_widget. This can easily break if the escaping logic changes or for more complex inputs. A better approach would be to simplify the test by just loading the JSON string, assuming the problematic escaping in _add_graph_widget is fixed.
| params = json.loads(params_str.replace('\\"', '"').replace("\\\\", "\\")) | |
| params = json.loads(params_str) |
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
| info_schema_results = bq_client.query( | ||
| info_schema_query, job_config=job_config | ||
| ).to_dataframe() |
There was a problem hiding this comment.
No change needed, but FYI you'll get the best performance with query_and_wait() since that allows for the fast (jobless) query path to kick in.
PR created by the Librarian CLI to initialize a release. Merging this PR will auto trigger a release. Librarian Version: v0.8.0 Language Image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:1a2a85ab507aea26d787c06cc7979decb117164c81dd78a745982dfda80d4f68 <details><summary>bigquery-magics: 0.12.0</summary> ## [0.12.0](v0.11.0...v0.12.0) (2026-02-10) ### Features * support schema view (#211) ([8e1883e](8e1883ee)) * remove bqsql magic to make that name available for bigframes (#210) ([c46c94a](c46c94af)) ### Bug Fixes * reduce conflicts between Spanner and BigQuery graph visualization on Colab (#209) ([7dca7b1](7dca7b13)) </details>
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:
Fixes #<issue_number_goes_here> 🦕