File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919import six
2020
2121from gcloud ._helpers import _datetime_from_microseconds
22+ from gcloud ._helpers import _microseconds_from_datetime
2223from gcloud ._helpers import _millis_from_datetime
2324from gcloud .exceptions import NotFound
2425from gcloud .bigquery ._helpers import _rows_from_json
@@ -654,8 +655,11 @@ def insert_data(self,
654655 row_info = {}
655656
656657 for field , value in zip (self ._schema , row ):
657- if field .field_type == 'TIMESTAMP' :
658- value = _millis_from_datetime (value )
658+ if field .field_type == 'TIMESTAMP' and value is not None :
659+ # BigQuery stores TIMESTAMP data internally as a
660+ # UNIX timestamp with microsecond precision.
661+ # Specifies the number of seconds since the epoch.
662+ value = _microseconds_from_datetime (value ) * 1e-6
659663 row_info [field .name ] = value
660664
661665 info = {'json' : row_info }
Original file line number Diff line number Diff line change @@ -1060,7 +1060,7 @@ def test_fetch_data_w_record_schema(self):
10601060 def test_insert_data_w_bound_client (self ):
10611061 import datetime
10621062 from gcloud ._helpers import UTC
1063- from gcloud ._helpers import _millis_from_datetime
1063+ from gcloud ._helpers import _microseconds_from_datetime
10641064 from gcloud .bigquery .table import SchemaField
10651065
10661066 WHEN_TS = 1437767599.006
@@ -1084,9 +1084,12 @@ def test_insert_data_w_bound_client(self):
10841084 ]
10851085
10861086 def _row_data (row ):
1087+ joined = None
1088+ if row [2 ] is not None :
1089+ joined = _microseconds_from_datetime (row [2 ]) * 1e-6
10871090 return {'full_name' : row [0 ],
10881091 'age' : row [1 ],
1089- 'joined' : _millis_from_datetime ( row [ 2 ]) }
1092+ 'joined' : joined }
10901093
10911094 SENT = {
10921095 'rows' : [{'json' : _row_data (row )} for row in ROWS ],
You can’t perform that action at this time.
0 commit comments