python-3.x - 将 python 日期时间加载到 Google BigQuery

标签 python-3.x google-bigquery

我正在将 Pandas 的日期时间字段加载到 Google BigQuery DATETIME 中并收到以下错误:

google.api_core.exceptions.BadRequest: 400 Error while reading data, error message: Invalid datetime value 1594835746000000 for field 'my field name' of type 'INT64' (logical type 'TIMESTAMP_MICROS'): generic::out_of_range: Cannot return an invalid datetime value of 1594835746000000 microseconds relative to the Unix epoch. The range of valid datetime values is [0001-01-1 00:00:00, 9999-12-31 23:59:59.999999]

在 Pandas 中,该对象绝对是一个 datetime.datetime 对象并且具有有效日期,当我从 1594835746000000 到 https://www.epochconverter.com/ 时它返回一个有效日期。

我正在通过调用将数据加载到 BigQuery 中:

job_config = bigquery.LoadJobConfig(schema = schema_fieldlist)
job = bigquery_client.load_table_from_dataframe(df, f'{dataset}.{tablename}', job_config)
job.result()

在哪里 schema_fieldlist 是一个数组,对于相关字段,定义为:

bigquery.SchemaField('my field name', 'DATETIME')

我没有做任何聪明的事情 - 任何人都可以建议他们是否让这个工作以及如何工作?我看到了其他与返回时间戳有关的问题以及标准和遗留 SQL 方言之间有效范围的变化

最佳答案

我也遇到了 DATETIME 和 TIME 的问题(已报告 https://issuetracker.google.com/issues/169230812)。

以下是我使用的相关包版本:

   pyarrow==1.0.1
   pandas==1.1.1
   google-cloud-bigquery==1.28.0
   numpy==1.19.1

TIMESTAMP 可以作为 DATETIME 的替代品,尽管带有隐含的时区。然而,它并不是 TIME 的良好替代品。

关于python-3.x - 将 python 日期时间加载到 Google BigQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64076076/

相关文章:

google-bigquery - 未设置应用程序名称。调用Builder#setApplicationName。错误

python - 创建唯一列表 : comparing dict objects

python - 如何在ThreadPool中等待任何线程?

python-3.x - 如何在 Visual Studio Code 中使用 activate.bat 而不是 ps1 运行选定文本?

google-bigquery - 从 BigQuery 中的查询返回一个数组(重复字段)

google-bigquery - 大查询中出现错误

python - Python 3 中的排序函数

python - 在 numpy 数组上应用统计方法 : unexpected results

google-bigquery - 加载位置 Southamerica-west1 : BigQuery Data Transfer Service does not yet support location: southamerica-west1 时出错

google-bigquery - 如何使用基于多列的bigquery关联?