question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bigquery insert data error] table.insert_data() issue

See original GitHub issue

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

sql_schema = [('viewer_id', 'INTEGER'),
              ('ip','STRING'),
              ('author_id', 'INTEGER'),
              ('post_id', 'STRING'),
              ('time', 'TIMESTAMP')]

And this is a test data:

[['25512',
  '126.107.92.215',
  '6524',
  '9f4047d3-7bf8-406c-823c-9803b4730fb9',
  '2015-12-14 18:29:01.245142'],
 ['24534',
  '87.13.200.79',
  '29096',
  'e09baadc-9647-4cde-9019-7c6846dfd662',
  '2015-12-14 18:29:01.245237']]

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?

Thanks

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
dhermescommented, Jan 12, 2016

Sorry the doc is vague:

:type rows: list of tuples
:param rows: row data to be inserted

As an example, our system test uses the schema

full_name = bigquery.SchemaField('full_name', 'STRING',
                                 mode='REQUIRED')
age = bigquery.SchemaField('age', 'INTEGER', mode='REQUIRED')
now = bigquery.SchemaField('now', 'TIMESTAMP')

to create the table

table = dataset.table(TABLE_NAME, schema=[full_name, age, now])

and then uses rows as a list of triples

ROWS = [
    ('Phred Phlyntstone', 32, NOW),
    ('Bharney Rhubble', 33, NOW + datetime.timedelta(seconds=10)),
    ('Wylma Phlyntstone', 29, NOW + datetime.timedelta(seconds=20)),
    ('Bhettye Rhubble', 27, None),
]

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:

ROW_IDS = [1, 2, 3, 4]
errors = table.insert_data(ROWS, ROW_IDS)

(For the record, I wouldn’t have expected you to have looked here, just wanted to provide an example.)


  1. As of right now, we expect a datetime.datetime object for a TIMESTAMP schema field.
  2. What situation are you in that you have lots of datetime’s as strings rather than native? (So I can understand the use-case)
  3. Could you provide the code snippets you used to generate the error? It’s unclear how sql_schema and your “test data” were used.
0reactions
dhermescommented, May 8, 2017

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

error while inserting data to a bigquery table in google cloud?
this error message shows while i'm running a query in my big query table. I create a table called nutrient and i want...
Read more >
Error messages | BigQuery - Google Cloud
This document describes error messages you might encounter when working with BigQuery, including HTTP error codes, job errors, and Google Cloud console ...
Read more >
Error while inserting data to big query table - Talend Community
Hello Everyone,. Getting below error in the last insert in bigquery output. Starting job live_exercise_v1 at 01:45 30/03/2020.
Read more >
POST Web service data action Problem (BigQuery)
Hi, everyone. I am trying to integrate a Web Service (Post) of BigQuery and Purecloud with data actions based on HTTPS.
Read more >
OAuth 2.0 Scopes for Google APIs | Authorization
https://www.googleapis.com/auth/bigquery.insertdata, Insert data into Google BigQuery ... Administer your Cloud Bigtable tables and clusters.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found