Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

feat: add api_method parameter to Client.query to select INSERT or QUERY API - #967

Merged
tswast merged 25 commits into
googleapis:v3from
tswast:issue589-queries-endpoint
Dec 2, 2021
Merged

feat: add api_method parameter to Client.query to select INSERT or QUERY API#967
tswast merged 25 commits into
googleapis:v3from
tswast:issue589-queries-endpoint

Conversation

@tswast

@tswasttswast commented Sep 13, 2021

Copy link
Copy Markdown
Contributor

This PR is the first step in enabling the "fast query path". At the moment, selecting api_method="QUERY" is actually likely to be slower because it fetches the first page of results and discards them. A PR will follow-up to cache this first page for use by the row iterator.

This commit only refactors to allow jobs.insert to be selected.
Supporting jobs.query will require more transformations to QueryJobConfig,
QueryJob, and RowIterator.

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 #589 🦕

@google-clagoogle-claBot added the cla: yes This human has signed the Contributor License Agreement. label Sep 13, 2021
@product-auto-labelproduct-auto-labelBot added the api: bigquery Issues related to the googleapis/python-bigquery API. label Sep 13, 2021
Comment threadgoogle/cloud/bigquery/_job_helpers.py Outdated
@tswast

tswast commented Sep 17, 2021

Copy link
Copy Markdown
ContributorAuthor

Even though this isn't a breaking change, it refactors enough that maybe this should target v3 so as not to delay v3 any longer.

@tswast
tswast changed the base branch from main to v3October 5, 2021 15:41
@snippet-bot

snippet-botBot commented Oct 5, 2021

Copy link
Copy Markdown

No region tags are edited in this PR.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@google-clagoogle-claBot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Oct 5, 2021
@tswasttswast changed the title feat: add api_method parameter to Client.query to select insert or query APIfeat: add api_method parameter to Client.query to select INSERT or QUERY APIOct 6, 2021
@google-cla

This comment has been minimized.

… or `query` API
Work in Progress. This commit only refactors to allow jobs.insert to be selected.
Supporting jobs.query will require more transformations to QueryJobConfig,
QueryJob, and RowIterator.
@tswast
tswastforce-pushed the issue589-queries-endpoint branch from 7b9457c to 2e4af92CompareOctober 7, 2021 21:43
@googleapisgoogleapis deleted a comment from google-claBotOct 7, 2021
@google-clagoogle-claBot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Oct 7, 2021
@googleapisgoogleapis deleted a comment from google-claBotOct 7, 2021
@googleapisgoogleapis deleted a comment from google-claBotOct 7, 2021
@googleapisgoogleapis deleted a comment from google-claBotOct 7, 2021
@tswast
tswast requested review from a team and loferrisNovember 18, 2021 23:05
@tswast

Copy link
Copy Markdown
ContributorAuthor

I've just synced to the latest v3 branch. Unit tests and query system tests are passing. I think this is ready for review.

Note: This won't actually result in any performance improvements until the # TODO: https://github.com/googleapis/python-bigquery/issues/589 in _job_helpers.py is resolved. Since that requires more hacks to the QueryJob class, I figure that's worth postponing to a separate PR. As-is, this PR should be showing the same behavior for api_method="INSERT" and api_method="QUERY" options.

@tswast

This comment has been minimized.

@tswast

This comment has been minimized.

Comment threadtests/system/conftest.py Outdated
@tswast
tswast requested a review from plamutNovember 19, 2021 16:25
@tswast

This comment has been minimized.

@plamutplamut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks really promising and structured, mostly just minor remarks and questions.

Comment threadgoogle/cloud/bigquery/_job_helpers.py Outdated
Comment threadgoogle/cloud/bigquery/_job_helpers.py Outdated
Comment threadgoogle/cloud/bigquery/_job_helpers.py Outdated
Comment threadtests/system/test_query.py Outdated
Comment threadtests/system/test_query.py
Comment threadtests/unit/test__job_helpers.py Outdated
@tswast
tswast requested a review from plamutNovember 22, 2021 16:54

@plamutplamut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

There's one nit, but decide for yourself if it's worth updating the PR.

called on the job returned. The ``job_retry``
specified here becomes the default ``job_retry`` for
``result()``, where it can also be specified.
api_method (Union[str, enums.QueryApiMethod]):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(nit) Duplicate annotation info

@loferrisloferris left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@tswast
tswast merged commit 3b3ebff into googleapis:v3Dec 2, 2021
@tswast
tswast deleted the issue589-queries-endpoint branch December 2, 2021 20:15
tswast added a commit that referenced this pull request Mar 29, 2022
deps!: BigQuery Storage and pyarrow are required dependencies (#776)
fix!: use nullable `Int64` and `boolean` dtypes in `to_dataframe` (#786) feat!: destination tables are no-longer removed by `create_job` (#891)
feat!: In `to_dataframe`, use `dbdate` and `dbtime` dtypes from db-dtypes package for BigQuery DATE and TIME columns (#972)
fix!: automatically convert out-of-bounds dates in `to_dataframe`, remove `date_as_object` argument (#972)
feat!: mark the package as type-checked (#1058)
feat!: default to DATETIME type when loading timezone-naive datetimes from Pandas (#1061)
feat: add `api_method` parameter to `Client.query` to select `INSERT` or `QUERY` API (#967)
fix: improve type annotations for mypy validation (#1081)
feat: use `StandardSqlField` class for `Model.feature_columns` and `Model.label_columns` (#1117)
docs: Add migration guide from version 2.x to 3.x (#1027)
Release-As: 3.0.0
@release-pleaserelease-pleaseBot mentioned this pull request Mar 29, 2022
waltaskew pushed a commit to waltaskew/python-bigquery that referenced this pull request Jul 20, 2022
deps!: BigQuery Storage and pyarrow are required dependencies (googleapis#776)
fix!: use nullable `Int64` and `boolean` dtypes in `to_dataframe` (googleapis#786) feat!: destination tables are no-longer removed by `create_job` (googleapis#891)
feat!: In `to_dataframe`, use `dbdate` and `dbtime` dtypes from db-dtypes package for BigQuery DATE and TIME columns (googleapis#972)
fix!: automatically convert out-of-bounds dates in `to_dataframe`, remove `date_as_object` argument (googleapis#972)
feat!: mark the package as type-checked (googleapis#1058)
feat!: default to DATETIME type when loading timezone-naive datetimes from Pandas (googleapis#1061)
feat: add `api_method` parameter to `Client.query` to select `INSERT` or `QUERY` API (googleapis#967)
fix: improve type annotations for mypy validation (googleapis#1081)
feat: use `StandardSqlField` class for `Model.feature_columns` and `Model.label_columns` (googleapis#1117)
docs: Add migration guide from version 2.x to 3.x (googleapis#1027)
Release-As: 3.0.0
abdelmegahedgoogle pushed a commit to abdelmegahedgoogle/python-bigquery that referenced this pull request Apr 17, 2023
…1014)
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](https://github.com/googleapis/python-bigquery/issues/new/choose) 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)
Issue discovered while investigating what properties are needed in googleapis#967
abdelmegahedgoogle pushed a commit to abdelmegahedgoogle/python-bigquery that referenced this pull request Apr 17, 2023
deps!: BigQuery Storage and pyarrow are required dependencies (googleapis#776)
fix!: use nullable `Int64` and `boolean` dtypes in `to_dataframe` (googleapis#786) feat!: destination tables are no-longer removed by `create_job` (googleapis#891)
feat!: In `to_dataframe`, use `dbdate` and `dbtime` dtypes from db-dtypes package for BigQuery DATE and TIME columns (googleapis#972)
fix!: automatically convert out-of-bounds dates in `to_dataframe`, remove `date_as_object` argument (googleapis#972)
feat!: mark the package as type-checked (googleapis#1058)
feat!: default to DATETIME type when loading timezone-naive datetimes from Pandas (googleapis#1061)
feat: add `api_method` parameter to `Client.query` to select `INSERT` or `QUERY` API (googleapis#967)
fix: improve type annotations for mypy validation (googleapis#1081)
feat: use `StandardSqlField` class for `Model.feature_columns` and `Model.label_columns` (googleapis#1117)
docs: Add migration guide from version 2.x to 3.x (googleapis#1027)
Release-As: 3.0.0
@davidkelldavidkell mentioned this pull request Dec 19, 2023
25 tasks
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide support for synchronous queries through the v2/projects/{projectId}/queries endpoint

3 participants

@tswast@plamut@loferris