Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit93d15e2

Browse files
authored
feat: supportScalarQueryParameterType fortype_ argument inScalarQueryParameter constructor (#850)
Follow-up tohttps://github.com/googleapis/python-bigquery/pull/840/files#r679880582Thank 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)
1 parentc1a3d44 commit93d15e2

File tree

5 files changed

+57
-24
lines changed

5 files changed

+57
-24
lines changed

‎docs/conf.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
# directories to ignore when looking for source files.
111111
exclude_patterns= [
112112
"_build",
113+
"**/.nox/**/*",
113114
"samples/AUTHORING_GUIDE.md",
114115
"samples/CONTRIBUTING.md",
115116
"samples/snippets/README.rst",

‎docs/reference.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Query
138138

139139
query.ArrayQueryParameter
140140
query.ScalarQueryParameter
141+
query.ScalarQueryParameterType
141142
query.StructQueryParameter
142143
query.UDFResource
143144

‎google/cloud/bigquery/enums.py‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,23 +259,23 @@ class SqlTypeNames(str, enum.Enum):
259259
classSqlParameterScalarTypes:
260260
"""Supported scalar SQL query parameter types as type objects."""
261261

262-
STRING=ScalarQueryParameterType("STRING")
262+
BOOL=ScalarQueryParameterType("BOOL")
263+
BOOLEAN=ScalarQueryParameterType("BOOL")
264+
BIGDECIMAL=ScalarQueryParameterType("BIGNUMERIC")
265+
BIGNUMERIC=ScalarQueryParameterType("BIGNUMERIC")
263266
BYTES=ScalarQueryParameterType("BYTES")
264-
INTEGER=ScalarQueryParameterType("INT64")
265-
INT64=ScalarQueryParameterType("INT64")
267+
DATE=ScalarQueryParameterType("DATE")
268+
DATETIME=ScalarQueryParameterType("DATETIME")
269+
DECIMAL=ScalarQueryParameterType("NUMERIC")
266270
FLOAT=ScalarQueryParameterType("FLOAT64")
267271
FLOAT64=ScalarQueryParameterType("FLOAT64")
268-
NUMERIC=ScalarQueryParameterType("NUMERIC")
269-
BIGNUMERIC=ScalarQueryParameterType("BIGNUMERIC")
270-
DECIMAL=ScalarQueryParameterType("NUMERIC")
271-
BIGDECIMAL=ScalarQueryParameterType("BIGNUMERIC")
272-
BOOLEAN=ScalarQueryParameterType("BOOL")
273-
BOOL=ScalarQueryParameterType("BOOL")
274272
GEOGRAPHY=ScalarQueryParameterType("GEOGRAPHY")
275-
TIMESTAMP=ScalarQueryParameterType("TIMESTAMP")
276-
DATE=ScalarQueryParameterType("DATE")
273+
INT64=ScalarQueryParameterType("INT64")
274+
INTEGER=ScalarQueryParameterType("INT64")
275+
NUMERIC=ScalarQueryParameterType("NUMERIC")
276+
STRING=ScalarQueryParameterType("STRING")
277277
TIME=ScalarQueryParameterType("TIME")
278-
DATETIME=ScalarQueryParameterType("DATETIME")
278+
TIMESTAMP=ScalarQueryParameterType("TIMESTAMP")
279279

280280

281281
classWriteDisposition(object):

‎google/cloud/bigquery/query.py‎

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@
1616

1717
fromcollectionsimportOrderedDict
1818
importcopy
19-
fromtypingimportUnion
19+
importdatetime
20+
importdecimal
21+
fromtypingimportOptional,Union
2022

2123
fromgoogle.cloud.bigquery.tableimport_parse_schema_resource
2224
fromgoogle.cloud.bigquery._helpersimport_rows_from_json
2325
fromgoogle.cloud.bigquery._helpersimport_QUERY_PARAMS_FROM_JSON
2426
fromgoogle.cloud.bigquery._helpersimport_SCALAR_VALUE_TO_JSON_PARAM
2527

2628

29+
_SCALAR_VALUE_TYPE=Optional[
30+
Union[str,int,float,decimal.Decimal,bool,datetime.datetime,datetime.date]
31+
]
32+
33+
2734
classUDFResource(object):
2835
"""Describe a single user-defined function (UDF) resource.
2936
@@ -325,35 +332,46 @@ class ScalarQueryParameter(_AbstractQueryParameter):
325332
"""Named / positional query parameters for scalar values.
326333
327334
Args:
328-
name (Optional[str]):
335+
name:
329336
Parameter name, used via ``@foo`` syntax. If None, the
330337
parameter can only be addressed via position (``?``).
331338
332-
type_ (str):
333-
Name of parameter type. One of 'STRING', 'INT64',
334-
'FLOAT64', 'NUMERIC', 'BIGNUMERIC', 'BOOL', 'TIMESTAMP', 'DATETIME', or
335-
'DATE'.
339+
type_:
340+
Name of parameter type. See
341+
:class:`google.cloud.bigquery.enums.SqlTypeNames` and
342+
:class:`google.cloud.bigquery.enums.SqlParameterScalarTypes` for
343+
supported types.
336344
337-
value (Union[str, int, float, decimal.Decimal, bool, datetime.datetime, datetime.date]):
345+
value:
338346
The scalar parameter value.
339347
"""
340348

341-
def__init__(self,name,type_,value):
349+
def__init__(
350+
self,
351+
name:Optional[str],
352+
type_:Optional[Union[str,ScalarQueryParameterType]],
353+
value:_SCALAR_VALUE_TYPE,
354+
):
342355
self.name=name
343-
self.type_=type_
356+
ifisinstance(type_,ScalarQueryParameterType):
357+
self.type_=type_._type
358+
else:
359+
self.type_=type_
344360
self.value=value
345361

346362
@classmethod
347-
defpositional(cls,type_:str,value)->"ScalarQueryParameter":
363+
defpositional(
364+
cls,type_:Union[str,ScalarQueryParameterType],value:_SCALAR_VALUE_TYPE
365+
)->"ScalarQueryParameter":
348366
"""Factory for positional paramater.
349367
350368
Args:
351-
type_ (str):
369+
type_:
352370
Name of parameter type. One of 'STRING', 'INT64',
353371
'FLOAT64', 'NUMERIC', 'BIGNUMERIC', 'BOOL', 'TIMESTAMP', 'DATETIME', or
354372
'DATE'.
355373
356-
value (Union[str, int, float, decimal.Decimal, bool, datetime.datetime, datetime.date]):
374+
value:
357375
The scalar parameter value.
358376
359377
Returns:

‎tests/unit/test_query.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
importdatetime
16+
importdecimal
1617
importunittest
1718

1819
importmock
@@ -430,6 +431,18 @@ def test_positional(self):
430431
self.assertEqual(param.type_,"INT64")
431432
self.assertEqual(param.value,123)
432433

434+
deftest_ctor_w_scalar_query_parameter_type(self):
435+
fromgoogle.cloud.bigqueryimportenums
436+
437+
param=self._make_one(
438+
name="foo",
439+
type_=enums.SqlParameterScalarTypes.BIGNUMERIC,
440+
value=decimal.Decimal("123.456"),
441+
)
442+
self.assertEqual(param.name,"foo")
443+
self.assertEqual(param.type_,"BIGNUMERIC")
444+
self.assertEqual(param.value,decimal.Decimal("123.456"))
445+
433446
deftest_from_api_repr_w_name(self):
434447
RESOURCE= {
435448
"name":"foo",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp