python - 如何将 "array of strings"添加为 BigQuery 的架构值

标签 python google-bigquery google-cloud-platform

我想在 BigQuery 的单个列中存储一个字符串值数组。为此,我需要先创建一个具有正确模式的表。该数组的模式标识符是 ARRAY<T>其中 T是数据类型。

例如:T替换为 INT64作为ARRAY<INT64>在该列中启用 64 位整数数组的存储。除了存储字符串值,我应该如何获得相同的效果?我已经试过了 STRING , VARCHARCHAR .

只需提及:我使用的是最新的 google-cloud python 包

Documentation Reference for BigQuery Schema

最佳答案

为了添加一个包含数组数据的列,您需要将该列的模式定义为REPEATED。因此,示例架构最终为:

{
  'name': 'array_of_strings',
  'type': 'STRING',
  'mode': 'REPEATED'
},{
  'name': 'array_of_floats',
  'type': 'FLOAT',
  'mode': 'REPEATED'
}

这使得该字段保存数组值。

注意:您应该知道,如果这是表的架构,那么您不能使用大查询的 CSV 导入功能,因为这是 CSV 文件格式的限制。您将需要使用 jsonavro 格式。

Reference to the GitHub issue

关于python - 如何将 "array of strings"添加为 BigQuery 的架构值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45315063/

相关文章:

python - TensorFlow 库未编译为在 Google Cloud Platform Console 上使用 SSE3、SSE4.1、SSE4.2、AVX

python - Tkinter 调整框架内框架的大小

random - BigQuery 中固定行数的高效采样

python - 确定我的 App Engine 代码在哪个项目 ID 上运行

google-bigquery - BigQuery 表数据导出

google-cloud-platform - GCP 发布订阅 : "The request was aborted because there was no available instance." - Doesn't Retry on Failure

google-cloud-platform - 无法在 GCP Cloud Scheduler 上创建作业

python - 如何从以下向量中获取具有最高值的 5 个元组?

python - 设置子图中 x 和 y 刻度的字体类型 matplotlib

python - 混淆矩阵-Sklearn 0.22 数字格式错误