|
16 | 16 |
|
17 | 17 | from collections import OrderedDict
|
18 | 18 | import copy
|
19 |
| -from typing import Union |
| 19 | +import datetime |
| 20 | +import decimal |
| 21 | +from typing import Optional, Union |
20 | 22 |
|
21 | 23 | from google.cloud.bigquery.table import _parse_schema_resource
|
22 | 24 | from google.cloud.bigquery._helpers import _rows_from_json
|
23 | 25 | from google.cloud.bigquery._helpers import _QUERY_PARAMS_FROM_JSON
|
24 | 26 | from google.cloud.bigquery._helpers import _SCALAR_VALUE_TO_JSON_PARAM
|
25 | 27 |
|
26 | 28 |
|
| 29 | +_SCALAR_VALUE_TYPE = Optional[ |
| 30 | + Union[str, int, float, decimal.Decimal, bool, datetime.datetime, datetime.date] |
| 31 | +] |
| 32 | + |
| 33 | + |
27 | 34 | class UDFResource(object):
|
28 | 35 | """Describe a single user-defined function (UDF) resource.
|
29 | 36 |
|
@@ -325,35 +332,46 @@ class ScalarQueryParameter(_AbstractQueryParameter):
|
325 | 332 | """Named / positional query parameters for scalar values.
|
326 | 333 |
|
327 | 334 | Args:
|
328 |
| - name (Optional[str]): |
| 335 | + name: |
329 | 336 | Parameter name, used via ``@foo`` syntax. If None, the
|
330 | 337 | parameter can only be addressed via position (``?``).
|
331 | 338 |
|
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. |
336 | 344 |
|
337 |
| - value (Union[str, int, float, decimal.Decimal, bool, datetime.datetime, datetime.date]): |
| 345 | + value: |
338 | 346 | The scalar parameter value.
|
339 | 347 | """
|
340 | 348 |
|
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 | + ): |
342 | 355 | self.name = name
|
343 |
| - self.type_ = type_ |
| 356 | + if isinstance(type_, ScalarQueryParameterType): |
| 357 | + self.type_ = type_._type |
| 358 | + else: |
| 359 | + self.type_ = type_ |
344 | 360 | self.value = value
|
345 | 361 |
|
346 | 362 | @classmethod
|
347 |
| - def positional(cls, type_: str, value) -> "ScalarQueryParameter": |
| 363 | + def positional( |
| 364 | + cls, type_: Union[str, ScalarQueryParameterType], value: _SCALAR_VALUE_TYPE |
| 365 | + ) -> "ScalarQueryParameter": |
348 | 366 | """Factory for positional paramater.
|
349 | 367 |
|
350 | 368 | Args:
|
351 |
| - type_ (str): |
| 369 | + type_: |
352 | 370 | Name of parameter type. One of 'STRING', 'INT64',
|
353 | 371 | 'FLOAT64', 'NUMERIC', 'BIGNUMERIC', 'BOOL', 'TIMESTAMP', 'DATETIME', or
|
354 | 372 | 'DATE'.
|
355 | 373 |
|
356 |
| - value (Union[str, int, float, decimal.Decimal, bool, datetime.datetime, datetime.date]): |
| 374 | + value: |
357 | 375 | The scalar parameter value.
|
358 | 376 |
|
359 | 377 | Returns:
|
|
0 commit comments