You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bigquery insert data error] table.insert_data() issue #1381
I got this error while using table.insert_data(rows)
--> 246 if not value.tzinfo:
247 value = value.replace(tzinfo=UTC)
248 # Regardless of what timezone is on the value, convert it to UTC.
AttributeError: 'str' object has no attribute 'tzinfo'
The doc of table.insert_data() said rows is list of tuple, so this is my schema
I know '2015-12-14 18:29:01.245237' is a string which doesn't have tzinfo field.
Do I have to convert it to Datetime object every time I try to load time data into bigquery?
Do I have better options?
that correspond to the schema (i.e. a required string, a required integer and an optional timestamp). After does this, they are inserted with a set of row IDS:
Perfect!! Thanks for quick response.
I'm on 0.8.0 doc.
☁ pageview_to_bigquery [master] ⚡ pip show gcloud
---
Metadata-Version: 2.0
Name: gcloud
Version: 0.8.0
Summary: API Client library for Google Cloud
Home-page: https://github.com/GoogleCloudPlatform/gcloud-python
Author: Google Cloud Platform
Author-email: jjg+gcloud-python@google.com
License: Apache 2.0
Location: /Users/lucas/anaconda/lib/python2.7/site-packages
Requires: six, httplib2, pycrypto, protobuf, google-apitools, oauth2client
Thanks you so much by pointing out a good source to learn how to use gcloud API. The system_tests is wonderful.
The use case is as follow:
I got csv files periodically uploaded to s3, and I want to load files into bigquery table.
So I'm going to have many time string (UTC) like this 2015-12-14 18:29:01.245237 in the raw csv waiting to be loaded into bigquery.
About my code, it's very simple:
load data as a pandas dataframe -> transform it to json -> send it to bigquery table
@icrtiou You can upload your CSV files directly to Google Cloud Storage and then tell BigQuery to grab them (ref).
With our library you can use bigquery.Client.load_table_from_storage to accomplish this. See storage docs for info on how to upload the CSV to Google Cloud Storage (there is also an example in the BigQuery system test file).
Activity
dhermes commentedon Jan 12, 2016
@icrtiou Are you on
http://googlecloudplatform.github.io/gcloud-python/latest/
or
http://googlecloudplatform.github.io/gcloud-python/0.8.0/
Also which version do you have installed?
dhermes commentedon Jan 12, 2016
@icrtiou Also thanks a lot for kicking the tires here AND for taking the time to report the bugs.
dhermes commentedon Jan 12, 2016
Sorry the doc is vague:
As an example, our system test uses the schema
to create the table
and then uses rows as a list of triples
that correspond to the schema (i.e. a required string, a required integer and an optional timestamp). After does this, they are inserted with a set of row IDS:
(For the record, I wouldn't have expected you to have looked here, just wanted to provide an example.)
datetime.datetimeobject for aTIMESTAMPschema field.sql_schemaand your "test data" were used.lukaemon commentedon Jan 12, 2016
Perfect!! Thanks for quick response.
I'm on 0.8.0 doc.
Thanks you so much by pointing out a good source to learn how to use gcloud API. The
system_testsis wonderful.The use case is as follow:
I got csv files periodically uploaded to s3, and I want to load files into bigquery table.
So I'm going to have many time string (UTC) like this
2015-12-14 18:29:01.245237in the raw csv waiting to be loaded into bigquery.About my code, it's very simple:
load data as a pandas dataframe -> transform it to json -> send it to bigquery table
df = pd.read_csv(StringIO(data), names=['viewer_id', 'ip', 'author_id', 'post_id', 'time'])rows = json.loads(df.to_json(orient='records'))table.insert_data(rows)I use the
sql_schemato create the bigquery table:So I guess I have to transform those raw time string into datetime object before loading into bigquery.
Thank you.
dhermes commentedon Jan 12, 2016
@icrtiou You can upload your CSV files directly to Google Cloud Storage and then tell BigQuery to grab them (ref).
With our library you can use
bigquery.Client.load_table_from_storageto accomplish this. See storage docs for info on how to upload the CSV to Google Cloud Storage (there is also an example in the BigQuery system test file).lukaemon commentedon Jan 12, 2016
Got it. That's next I wanna try after I could handle this streaming case without leaving side effects.
Thanks for your time.
dhermes commentedon Jan 12, 2016
Thanks for your time! I am filing a new issue for consideration of how to handle existing string timestamps.
lukaemon commentedon Jan 12, 2016
That would be awesome feature to have. For lazy library user XD
dhermes commentedon Jan 12, 2016
Not just for lazy people but for people who don't want to waste compute cycles.
lukaemon commentedon Jan 12, 2016
Indeed.
Add more detail to BigQuery Table.insert_data().
jasonmellone commentedon May 8, 2017
Is there any reason table.insert() does not accept dictionaries of {'column_name':value_to_be_inserted,...,}?
This would be clean and allow arbitrary sorting.
dhermes commentedon May 8, 2017
@jasonmellone Care to file a new feature request?
I just don't want the discussion to get lost among this old, closed issue.
jasonmellone commentedon May 8, 2017
dhermes commentedon May 8, 2017
Thanks
chore(deps): update dependency setuptools to v63.3.0 (#1381)
chore: update sys test cred (#1381)
chore(main): release 2.29.1 (#1381)
chore: remove debugger comment (#1381)
feat: Add support for multiplexed sessions (#1381)