Skip to content

Commit 17a82db

Browse files
authored
Merge pull request #2347 from tseaver/2229-bigquery-standard-sql-data-types
Add support for Standard SQL dialect 'INT64' and 'FLOAT64' types.
2 parents 6fb2d73 + bdb3244 commit 17a82db

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

google/cloud/bigquery/_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ def _string_from_json(value, _):
7575

7676
_CELLDATA_FROM_JSON = {
7777
'INTEGER': _int_from_json,
78+
'INT64': _int_from_json,
7879
'FLOAT': _float_from_json,
80+
'FLOAT64': _float_from_json,
7981
'BOOLEAN': _bool_from_json,
8082
'TIMESTAMP': _datetime_from_json,
8183
'DATE': _date_from_json,

unit_tests/bigquery/test__helpers.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,37 @@ def test_w_record_subfield(self):
284284
coerced = self._callFUT(rows, schema)
285285
self.assertEqual(coerced, expected)
286286

287+
def test_w_int64_float64(self):
288+
# "Standard" SQL dialect uses 'INT64', 'FLOAT64'.
289+
candidate = _Field('REQUIRED', 'candidate', 'STRING')
290+
votes = _Field('REQUIRED', 'votes', 'INT64')
291+
percentage = _Field('REQUIRED', 'percentage', 'FLOAT64')
292+
schema = [candidate, votes, percentage]
293+
rows = [
294+
{'f': [
295+
{'v': 'Phred Phlyntstone'},
296+
{'v': 8},
297+
{'v': 0.25},
298+
]},
299+
{'f': [
300+
{'v': 'Bharney Rhubble'},
301+
{'v': 4},
302+
{'v': 0.125},
303+
]},
304+
{'f': [
305+
{'v': 'Wylma Phlyntstone'},
306+
{'v': 20},
307+
{'v': 0.625},
308+
]},
309+
]
310+
expected = [
311+
('Phred Phlyntstone', 8, 0.25),
312+
('Bharney Rhubble', 4, 0.125),
313+
('Wylma Phlyntstone', 20, 0.625),
314+
]
315+
coerced = self._callFUT(rows, schema)
316+
self.assertEqual(coerced, expected)
317+
287318

288319
class Test_ConfigurationProperty(unittest.TestCase):
289320

0 commit comments

Comments
 (0)