Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
Marshal 'BYTES' and 'TIME' column / paramter types#2806
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
Merged
tseaver
merged 8 commits into
googleapis:master
from
tseaver:2229-bigquery-marshal-bytes-time-typesDec 5, 2016
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
44cda35
Reorder to match docs.
tseaver 9f62375
Fix field mode for test.
tseaver a8b534c
Add support for 'BYTES' columns / parameters.
tseaver 20cdfc7
Add helper for parsing zoneless time strings.
tseaver 175e027
Add support for 'TIME' columns / parameters.
tseaver 240d44a
Add system tests for standard SQL scalar column types.
tseaver 2c1ccd2
Fix base64 encodeing of test value on Py3k.
tseaver 2518708
pylint
tseaver File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -14,6 +14,7 @@ | ||
| """Shared helper functions for BigQuery API classes.""" | ||
| import base64 | ||
| from collections import OrderedDict | ||
| import datetime | ||
| @@ -22,6 +23,7 @@ | ||
| from google.cloud._helpers import _datetime_to_rfc3339 | ||
| from google.cloud._helpers import _microseconds_from_datetime | ||
| from google.cloud._helpers import _RFC3339_NO_FRACTION | ||
| from google.cloud._helpers import _time_from_iso8601_time_naive | ||
| def _not_null(value, field): | ||
| @@ -47,6 +49,17 @@ def _bool_from_json(value, field): | ||
| return value.lower() in ['t', 'true', '1'] | ||
| def _string_from_json(value, _): | ||
| """NOOP string -> string coercion""" | ||
| return value | ||
| def _bytes_from_json(value, field): | ||
| """Base64-decode value""" | ||
| if _not_null(value, field): | ||
| return base64.decodestring(value) | ||
| def _timestamp_from_json(value, field): | ||
| """Coerce 'value' to a datetime, if set or not nullable.""" | ||
| if _not_null(value, field): | ||
| @@ -64,9 +77,17 @@ def _datetime_from_json(value, field): | ||
| def _date_from_json(value, field): | ||
| """Coerce 'value' to a datetime date, if set or not nullable""" | ||
| if _not_null(value, field): | ||
| # value will be a string, in YYYY-MM-DD form. | ||
| return _date_from_iso8601_date(value) | ||
| def _time_from_json(value, field): | ||
| """Coerce 'value' to a datetime date, if set or not nullable""" | ||
| if _not_null(value, field): | ||
| # value will be a string, in HH:MM:SS form. | ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| return _time_from_iso8601_time_naive(value) | ||
| def _record_from_json(value, field): | ||
| """Coerce 'value' to a mapping, if set or not nullable.""" | ||
| if _not_null(value, field): | ||
| @@ -82,23 +103,20 @@ def _record_from_json(value, field): | ||
| return record | ||
| def _string_from_json(value, _): | ||
| """NOOP string -> string coercion""" | ||
| return value | ||
| _CELLDATA_FROM_JSON = { | ||
| 'INTEGER': _int_from_json, | ||
| 'INT64': _int_from_json, | ||
| 'FLOAT': _float_from_json, | ||
| 'FLOAT64': _float_from_json, | ||
| 'BOOLEAN': _bool_from_json, | ||
| 'BOOL': _bool_from_json, | ||
| 'STRING': _string_from_json, | ||
| 'BYTES': _bytes_from_json, | ||
| 'TIMESTAMP': _timestamp_from_json, | ||
| 'DATETIME': _datetime_from_json, | ||
| 'DATE': _date_from_json, | ||
| 'TIME': _time_from_json, | ||
| 'RECORD': _record_from_json, | ||
| 'STRING': _string_from_json, | ||
| } | ||
| @@ -121,6 +139,13 @@ def _bool_to_json(value): | ||
| return value | ||
| def _bytes_to_json(value): | ||
| """Coerce 'value' to an JSON-compatible representation.""" | ||
| if isinstance(value, bytes): | ||
| value = base64.encodestring(value) | ||
| return value | ||
| def _timestamp_to_json(value): | ||
| """Coerce 'value' to an JSON-compatible representation.""" | ||
| if isinstance(value, datetime.datetime): | ||
| @@ -142,16 +167,25 @@ def _date_to_json(value): | ||
| return value | ||
| def _time_to_json(value): | ||
| """Coerce 'value' to an JSON-compatible representation.""" | ||
| if isinstance(value, datetime.time): | ||
| value = value.isoformat() | ||
| return value | ||
| _SCALAR_VALUE_TO_JSON = { | ||
| 'INTEGER': _int_to_json, | ||
| 'INT64': _int_to_json, | ||
| 'FLOAT': _float_to_json, | ||
| 'FLOAT64': _float_to_json, | ||
| 'BOOLEAN': _bool_to_json, | ||
| 'BOOL': _bool_to_json, | ||
| 'BYTES': _bytes_to_json, | ||
| 'TIMESTAMP': _timestamp_to_json, | ||
| 'DATETIME': _datetime_to_json, | ||
| 'DATE': _date_to_json, | ||
| 'TIME': _time_to_json, | ||
| } | ||
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
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.