-
Notifications
You must be signed in to change notification settings - Fork 60
feat: add bigframes.options.compute.maximum_bytes_billed option that sets maximum bytes billed on query jobs #133
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
15 commits
Select commit
Hold shift + click to select a range
b09c746
feat: add `bigframes.options.compute.maximum_bytes_billed` option tha…
orrbradford 4ba47f5
feat: add `bigframes.options.compute.maximum_bytes_billed` option tha…
orrbradford 704a2d7
add liscence header
orrbradford b46670a
Merge branch 'main' into orrbradford-job-dev
orrbradford f5dc41a
update test to pass coverage check
orrbradford 7105777
Merge branch 'orrbradford-job-dev' of github.com:googleapis/python-bi…
orrbradford 3baac36
Merge branch 'main' into orrbradford-job-dev
orrbradford 43654c0
Merge branch 'main' into orrbradford-job-dev
tswast ef291ff
docs: add artithmetic df sample code (#153)
ashleyxuu 73c77ba
feat: Implement operator `@` for `DataFrame.dot` (#139)
shobsi a2f730d
test: add code snippets for loading data from BigQuery Job (#154)
ashleyxuu b797a99
add options_context to __all__
orrbradford c44879c
Merge branch 'main' of github.com:googleapis/python-bigquery-datafram…
orrbradford ad2fd81
add autoclass for compute options
orrbradford d0a85b5
update bad autoclass config
orrbradford 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Options for displaying objects.""" | ||
|
||
import dataclasses | ||
from typing import Optional | ||
|
||
|
||
@dataclasses.dataclass | ||
class ComputeOptions: | ||
""" | ||
Encapsulates configuration for compute options. | ||
Attributes: | ||
maximum_bytes_billed (int, Options): | ||
Limits the bytes billed for query jobs. Queries that will have | ||
bytes billed beyond this limit will fail (without incurring a | ||
charge). If unspecified, this will be set to your project default. | ||
See `maximum_bytes_billed <https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.job.QueryJobConfig#google_cloud_bigquery_job_QueryJobConfig_maximum_bytes_billed>`_. | ||
""" | ||
|
||
maximum_bytes_billed: Optional[int] = None |
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
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
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import bigframes as bf | ||
|
||
from . import resources | ||
|
||
|
||
def test_maximum_bytes_option(): | ||
session = resources.create_bigquery_session() | ||
num_query_calls = 0 | ||
with bf.option_context("compute.maximum_bytes_billed", 10000): | ||
# clear initial method calls | ||
session.bqclient.method_calls = [] | ||
session._start_query("query") | ||
for call in session.bqclient.method_calls: | ||
_, _, kwargs = call | ||
num_query_calls += 1 | ||
assert kwargs["job_config"].maximum_bytes_billed == 10000 | ||
assert num_query_calls > 0 |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Contains code from https://github.com/pandas-dev/pandas/blob/main/pandas/_config/config.py | ||
import contextlib | ||
orrbradford marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import operator | ||
|
||
import bigframes | ||
|
||
|
||
class option_context(contextlib.ContextDecorator): | ||
""" | ||
Context manager to temporarily set options in the `with` statement context. | ||
|
||
You need to invoke as ``option_context(pat, val, [(pat, val), ...])``. | ||
|
||
Examples | ||
-------- | ||
>>> import bigframes | ||
>>> with bigframes.option_context('display.max_rows', 10, 'display.max_columns', 5): | ||
... pass | ||
""" | ||
|
||
def __init__(self, *args) -> None: | ||
if len(args) % 2 != 0 or len(args) < 2: | ||
raise ValueError( | ||
"Need to invoke as option_context(pat, val, [(pat, val), ...])." | ||
) | ||
|
||
self.ops = list(zip(args[::2], args[1::2])) | ||
|
||
def __enter__(self) -> None: | ||
self.undo = [ | ||
(pat, operator.attrgetter(pat)(bigframes.options)) for pat, val in self.ops | ||
] | ||
|
||
for pat, val in self.ops: | ||
self._set_option(pat, val) | ||
|
||
def __exit__(self, *args) -> None: | ||
if self.undo: | ||
for pat, val in self.undo: | ||
self._set_option(pat, val) | ||
|
||
def _set_option(self, pat, val): | ||
root, attr = pat.rsplit(".", 1) | ||
parent = operator.attrgetter(root)(bigframes.options) | ||
setattr(parent, attr, val) |
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.
Uh oh!
There was an error while loading. Please reload this page.