This repository was archived by the owner on Mar 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 325
feat: support ScalarQueryParameterType for type_ argument in ScalarQueryParameter constructor
#850
Merged
gcf-merge-on-green
merged 7 commits into
googleapis:master
from
tswast:ScalarQueryParameterType
Aug 11, 2021
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e9475d4
feat: support `ScalarQueryParameterType` for `type_` argument in `Sca…
tswast 9f4f6e2
revert INTERVAL change
tswast 93e153b
Merge remote-tracking branch 'upstream/master' into ScalarQueryParame…
tswast 7599f25
use singular for scalar type
tswast 4bca752
Merge branch 'master' into ScalarQueryParameterType
tswast cdd18d8
Merge branch 'master' into ScalarQueryParameterType
tswast e447953
Merge branch 'master' into ScalarQueryParameterType
plamut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -259,23 +259,23 @@ class SqlTypeNames(str, enum.Enum): | |
| class SqlParameterScalarTypes: | ||
| """Supported scalar SQL query parameter types as type objects.""" | ||
|
|
||
| STRING = ScalarQueryParameterType("STRING") | ||
| BOOL = ScalarQueryParameterType("BOOL") | ||
| BOOLEAN = ScalarQueryParameterType("BOOL") | ||
| BIGDECIMAL = ScalarQueryParameterType("BIGNUMERIC") | ||
| BIGNUMERIC = ScalarQueryParameterType("BIGNUMERIC") | ||
| BYTES = ScalarQueryParameterType("BYTES") | ||
| INTEGER = ScalarQueryParameterType("INT64") | ||
| INT64 = ScalarQueryParameterType("INT64") | ||
| DATE = ScalarQueryParameterType("DATE") | ||
| DATETIME = ScalarQueryParameterType("DATETIME") | ||
| DECIMAL = ScalarQueryParameterType("NUMERIC") | ||
| FLOAT = ScalarQueryParameterType("FLOAT64") | ||
| FLOAT64 = ScalarQueryParameterType("FLOAT64") | ||
| NUMERIC = ScalarQueryParameterType("NUMERIC") | ||
| BIGNUMERIC = ScalarQueryParameterType("BIGNUMERIC") | ||
| DECIMAL = ScalarQueryParameterType("NUMERIC") | ||
| BIGDECIMAL = ScalarQueryParameterType("BIGNUMERIC") | ||
| BOOLEAN = ScalarQueryParameterType("BOOL") | ||
| BOOL = ScalarQueryParameterType("BOOL") | ||
| GEOGRAPHY = ScalarQueryParameterType("GEOGRAPHY") | ||
| TIMESTAMP = ScalarQueryParameterType("TIMESTAMP") | ||
| DATE = ScalarQueryParameterType("DATE") | ||
| INT64 = ScalarQueryParameterType("INT64") | ||
| INTEGER = ScalarQueryParameterType("INT64") | ||
| NUMERIC = ScalarQueryParameterType("NUMERIC") | ||
| STRING = ScalarQueryParameterType("STRING") | ||
| TIME = ScalarQueryParameterType("TIME") | ||
| DATETIME = ScalarQueryParameterType("DATETIME") | ||
| TIMESTAMP = ScalarQueryParameterType("TIMESTAMP") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't INTERVAL too a scalar? Or why don't we include it here in this class? (can also be done in the #840 if out of scope here)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can't actually at the moment. When I tried in a system test, I got a backend error. The team is aware and fixing it in internal issue 195050789 |
||
|
|
||
|
|
||
| class WriteDisposition(object): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,14 +16,21 @@ | |
|
|
||
| from collections import OrderedDict | ||
| import copy | ||
| from typing import Union | ||
| import datetime | ||
| import decimal | ||
| from typing import Optional, Union | ||
|
|
||
| from google.cloud.bigquery.table import _parse_schema_resource | ||
| from google.cloud.bigquery._helpers import _rows_from_json | ||
| from google.cloud.bigquery._helpers import _QUERY_PARAMS_FROM_JSON | ||
| from google.cloud.bigquery._helpers import _SCALAR_VALUE_TO_JSON_PARAM | ||
|
|
||
|
|
||
| _SCALAR_VALUE_TYPE = Optional[ | ||
| Union[str, int, float, decimal.Decimal, bool, datetime.datetime, datetime.date] | ||
| ] | ||
|
|
||
|
|
||
| class UDFResource(object): | ||
| """Describe a single user-defined function (UDF) resource. | ||
|
|
||
|
|
@@ -325,35 +332,46 @@ class ScalarQueryParameter(_AbstractQueryParameter): | |
| """Named / positional query parameters for scalar values. | ||
|
|
||
| Args: | ||
| name (Optional[str]): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| name: | ||
| Parameter name, used via ``@foo`` syntax. If None, the | ||
| parameter can only be addressed via position (``?``). | ||
|
|
||
| type_ (str): | ||
| Name of parameter type. One of 'STRING', 'INT64', | ||
| 'FLOAT64', 'NUMERIC', 'BIGNUMERIC', 'BOOL', 'TIMESTAMP', 'DATETIME', or | ||
| 'DATE'. | ||
| type_: | ||
| Name of parameter type. See | ||
| :class:`google.cloud.bigquery.enums.SqlTypeNames` and | ||
| :class:`google.cloud.bigquery.enums.SqlParameterScalarTypes` for | ||
| supported types. | ||
|
|
||
| value (Union[str, int, float, decimal.Decimal, bool, datetime.datetime, datetime.date]): | ||
| value: | ||
| The scalar parameter value. | ||
| """ | ||
|
|
||
| def __init__(self, name, type_, value): | ||
| def __init__( | ||
| self, | ||
| name: Optional[str], | ||
| type_: Optional[Union[str, ScalarQueryParameterType]], | ||
| value: _SCALAR_VALUE_TYPE, | ||
| ): | ||
| self.name = name | ||
| self.type_ = type_ | ||
| if isinstance(type_, ScalarQueryParameterType): | ||
| self.type_ = type_._type | ||
| else: | ||
| self.type_ = type_ | ||
| self.value = value | ||
|
|
||
| @classmethod | ||
| def positional(cls, type_: str, value) -> "ScalarQueryParameter": | ||
| def positional( | ||
| cls, type_: Union[str, ScalarQueryParameterType], value: _SCALAR_VALUE_TYPE | ||
| ) -> "ScalarQueryParameter": | ||
| """Factory for positional paramater. | ||
|
|
||
| Args: | ||
| type_ (str): | ||
| type_: | ||
| Name of parameter type. One of 'STRING', 'INT64', | ||
| 'FLOAT64', 'NUMERIC', 'BIGNUMERIC', 'BOOL', 'TIMESTAMP', 'DATETIME', or | ||
| 'DATE'. | ||
|
|
||
| value (Union[str, int, float, decimal.Decimal, bool, datetime.datetime, datetime.date]): | ||
| value: | ||
| The scalar parameter value. | ||
|
|
||
| Returns: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Uh oh!
There was an error while loading. Please reload this page.