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

feat: implement query options versioning support - #30

Merged
larkee merged 4 commits into
googleapis:masterfrom
larkee:query_versioning
Mar 12, 2020
Merged

feat: implement query options versioning support#30
larkee merged 4 commits into
googleapis:masterfrom
larkee:query_versioning

Conversation

@larkee

@larkee larkee commented Mar 9, 2020

Copy link
Copy Markdown
Contributor

Adds support for QueryOptions.

The QueryOptions are set in one of three ways (in ascending order of precedence):

  • As an argument to the Client constructor.
  • Setting the SPANNER_OPTIMIZER_VERSION env variable.
  • On a per-query basis.

If the backend implements query hints, for example, to instruct the backend which query optimizer version to use, these query hints will also automatically be supported.

@larkee larkee added the api: spanner Issues related to the googleapis/python-spanner API. label Mar 9, 2020
@larkee
larkee requested review from hengfengli and skuruppu March 9, 2020 06:02
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 9, 2020
@larkee larkee added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Mar 9, 2020
Comment thread tests/unit/test_client.py
self.assertEqual(client._query_options, expected_query_options)

@mock.patch("google.cloud.spanner_v1.client.os.getenv")
@mock.patch("google.cloud.spanner_v1.client._get_spanner_emulator_host")

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.

Not sure why there's a diff for _get_spanner_emulator_host in this PR.

@larkee larkee Mar 10, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both emulator support and query options support rely on calling os.getenv which means it's more difficult to set up the mock. The os.getenv call for emulator is made in _get_spanner_emulator_host which means mocking that function instead is much more clear and avoids setting up theos.getenv mock.

Comment thread google/cloud/spanner_v1/client.py Outdated
"without a scheme: ex %s=localhost:8080."
) % ((EMULATOR_ENV_VAR,) * 3)
SPANNER_ADMIN_SCOPE = "https://www.googleapis.com/auth/spanner.admin"
OPTIMIZER_VERSION_VAR = "SPANNER_OPTIMIZER_VERSION"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

probably use OPTIMIZER_VERSION_ENV_VAR

Comment thread google/cloud/spanner_v1/_helpers.py
Comment thread google/cloud/spanner_v1/session.py

@hengfengli hengfengli left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Major concerns:

  1. Does query_options support both ExecuteSqlRequest.QueryOptions and dict everywhere? It needs to be clear in the doc comment.
  2. Does partition_query support query_options as well?
  3. Nits: the merge function can be more generic for future extension. This can be done in the future when we add new fields in query_options.

For the rest, LGTM, 👍

@skuruppu skuruppu 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.

Just to confirm that we're going with SPANNER_OPTIMIZER_VERSION to be consistent with the query hint name. I think your implementation already uses this name but just wanted to make sure.

@larkee
larkee requested a review from crwilcox March 12, 2020 05:13
@larkee

larkee commented Mar 12, 2020

Copy link
Copy Markdown
Contributor Author

@hengfengli partition_query does not support query_options as it does not call executeSql or executeStreamingSql

@hengfengli

hengfengli commented Mar 12, 2020

Copy link
Copy Markdown

@hengfengli partition_query does not support query_options as it does not call executeSql or executeStreamingSql

Actually, I mean this method generate_query_batches. You have done it already.

@hengfengli hengfengli left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM 👍

@larkee
larkee changed the base branch from autosynth to master March 12, 2020 07:36
@larkee
larkee force-pushed the query_versioning branch from 49a422f to 4e16212 Compare March 12, 2020 07:38
@larkee larkee removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Mar 12, 2020
@larkee
larkee merged commit 5147921 into googleapis:master Mar 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: spanner Issues related to the googleapis/python-spanner API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants