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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement query options versioning support #30

Merged
merged 4 commits into from
Mar 12, 2020

Conversation

larkee
Copy link
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
@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

@mock.patch("google.cloud.spanner_v1.client.os.getenv")
@mock.patch("google.cloud.spanner_v1.client._get_spanner_emulator_host")
Copy link
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
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.

@@ -62,6 +63,7 @@
"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"

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

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

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

@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 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 join this conversation on GitHub. Already have an account? Sign in to comment
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.

None yet

4 participants