Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support RANGE query parameters #1827

Merged
merged 14 commits into from Mar 4, 2024

Conversation

Linchin
Copy link
Contributor

@Linchin Linchin commented Feb 23, 2024

Part of #1724.

In this PR, we add support for using a query parameter of RANGE type, either named or positional. Here is an example below:

from google.cloud import bigquery
from datetime import datetime, date

# Construct a BigQuery client object.
client = bigquery.Client()

query = """SELECT ? AS foo"""


# Set the name to None to use positional parameters.
# Note that you cannot mix named and positional parameters.
job_config = bigquery.QueryJobConfig(
    query_parameters=[
        bigquery.RangeQueryParameter("DATETIME", start=datetime(year=2020, month=10, day=30), end=None),
    ]
)

results = client.query_and_wait(query, job_config=job_config) 

for row in results:
    print(row)

More specifically:

  • Added classes RangeQueryParameter, RangeQueryParameterType and their corresponding methods
  • Added unit tests
  • Added system tests

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)

Towards #1724 馃

@Linchin Linchin requested review from a team as code owners February 23, 2024 22:50
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: bigquery Issues related to the googleapis/python-bigquery API. labels Feb 23, 2024
@Linchin Linchin added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Feb 23, 2024
@Linchin Linchin removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Feb 24, 2024
@Linchin Linchin added kokoro:force-run Add this label to force Kokoro to re-run the tests. do not merge Indicates a pull request not ready for merge, due to either quality or timing. kokoro:run Add this label to force Kokoro to re-run the tests. and removed kokoro:force-run Add this label to force Kokoro to re-run the tests. do not merge Indicates a pull request not ready for merge, due to either quality or timing. kokoro:run Add this label to force Kokoro to re-run the tests. labels Feb 24, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Feb 26, 2024
@chalmerlowe
Copy link
Contributor

@Linchin please fill out the description of this PR so that reviewers and "future us" can quickly identify the purpose and scope of this change. Thanks.

@Linchin
Copy link
Contributor Author

Linchin commented Feb 27, 2024

Thanks @chalmerlowe! Definitely got lost in the work and forgot to add the description. I just edited it to add more details :)

google/cloud/bigquery/query.py Outdated Show resolved Hide resolved
google/cloud/bigquery/query.py Outdated Show resolved Hide resolved
tests/unit/test_query.py Outdated Show resolved Hide resolved
@@ -422,6 +423,38 @@ def test_query_statistics(bigquery_client, query_api_method):
)
],
),
(
"SELECT @range_date",
"[2016-12-05, UNBOUNDED)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is 'UNBOUNDED' some kind of type alias, or does the service return that as the literal string? If so, should we convert UNBOUNDED -> None when build query parameter values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The service returns 'UNBOUNDED' as part of the literal string. 'UNBOUNDED' isn't an alias of any type, so it's safe to convert it into None.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! Its fine to punt on this aspect, I just wanted to clarify.

@@ -422,6 +423,38 @@ def test_query_statistics(bigquery_client, query_api_method):
)
],
),
(
"SELECT @range_date",
"[2016-12-05, UNBOUNDED)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! Its fine to punt on this aspect, I just wanted to clarify.

@Linchin Linchin enabled auto-merge (squash) March 4, 2024 18:31
@Linchin Linchin merged commit b359a9a into googleapis:main Mar 4, 2024
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants