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

feat: implement query options versioning support#30

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

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

Conversation

@larkee
Copy link
Copy Markdown
Contributor

@larkee larkee commented Mar 9, 2020

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

Copy link
Copy Markdown
Contributor Author

@larkee larkee Mar 10, 2020

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.

"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

Copy link
Copy Markdown

@hengfengli hengfengli left a comment

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, 👍

Copy link
Copy Markdown
Contributor

@skuruppu skuruppu left a comment

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
Copy link
Copy Markdown
Contributor Author

larkee commented Mar 12, 2020

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

@hengfengli
Copy link
Copy Markdown

hengfengli commented Mar 12, 2020

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

Copy link
Copy Markdown

@hengfengli hengfengli left a comment

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