-
Notifications
You must be signed in to change notification settings - Fork 48
perf: if primary keys are defined, read_gbq
avoids copying table data
#112
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b36b555
perf: if primary keys are defined, `read_gbq` avoids copying table data
tswast e04d3a6
only load primary key table once per project
tswast 6fb7e1d
Merge remote-tracking branch 'origin/main' into b294870053-primary-key
tswast 2563567
Merge branch 'main' into b294870053-primary-key
tswast d0e5012
remove `release_dry_run` from presubmits as its no longer used
tswast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,6 @@ | |
"system", | ||
"doctest", | ||
"cover", | ||
"release_dry_run", | ||
] | ||
|
||
# Error if a python version is missing | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
from typing import List | ||
|
||
import google.api_core.exceptions | ||
import google.cloud.bigquery as bigquery | ||
import numpy as np | ||
import pandas as pd | ||
import pytest | ||
|
@@ -231,6 +232,30 @@ def test_read_gbq_w_anonymous_query_results_table(session: bigframes.Session): | |
pd.testing.assert_frame_equal(result, expected, check_dtype=False) | ||
|
||
|
||
def test_read_gbq_w_primary_keys_table( | ||
session: bigframes.Session, usa_names_grouped_table: bigquery.Table | ||
): | ||
table = usa_names_grouped_table | ||
# TODO(b/305264153): Use public properties to fetch primary keys once | ||
# added to google-cloud-bigquery. | ||
primary_keys = ( | ||
table._properties.get("tableConstraints", {}) | ||
.get("primaryKey", {}) | ||
.get("columns") | ||
) | ||
assert len(primary_keys) != 0 | ||
|
||
df = session.read_gbq(f"{table.project}.{table.dataset_id}.{table.table_id}") | ||
result = df.head(100).to_pandas() | ||
|
||
# Verify that the DataFrame is already sorted by primary keys. | ||
sorted_result = result.sort_values(primary_keys) | ||
pd.testing.assert_frame_equal(result, sorted_result) | ||
|
||
# Verify that we're working from a snapshot rather than a copy of the table. | ||
assert "FOR SYSTEM_TIME AS OF TIMESTAMP" in df.sql | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM |
||
|
||
|
||
@pytest.mark.parametrize( | ||
("query_or_table", "max_results"), | ||
[ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM