如何将嵌套数组加载到Google BigQuery中? [英] How can I load nested array into Google BigQuery?

查看:215
本文介绍了如何将嵌套数组加载到Google BigQuery中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将嵌套数组加载到Google BigQuery中。例如



任何帮助将不胜感激。
Subhayu

解决方案

我很快试图想出一些代码。不知道它是否会完全解决您的使用案例。但你必须做类似的事情。



以下是以编程方式创建表的Scala代码



<$ p $ ()。setSchema(new TableSchema()。setFields(); setSchema(new TableSchema()。setFields(); setSchema(new TableSchema()。setFields (
List(
)TableFieldSchema()。setName(geo).setType(RECORD)。setFields(
List(
new TableFieldSchema()。setName(类型)。setType(STRING),
new TableFieldSchema()。setName(coordinates).setType(RECORD).setMode(REPEATED)。setFields(
List b $ b new TableFieldSchema()。setName(index).setType(RECORD).setMode(REPEATED)。setFields(
List(
new TableFieldSchema()。setName(sub_index ).setType(RECORD).setMode(REPEATED)。
setFields(List(new TableFieldSchema()。setName(_ 0).setType(STRING),
新的TableFieldSchema()。setName(_ 1).setType(STRING)))





) )

).setTableReference(tableReference)

可以从csv文件加载数据,也可以以编程方式插入数据。



这会创建一个像这样的表模式


How can I load nested array into Google BigQuery. For example

Any help will be highly appreciated. Subhayu

解决方案

I have quickly tried to come up with some code. Don't know whether it would exactly solve your use case. But you will have to do something similar.

Below is the Scala code to create the table programmatically

  val tableId = "_geometry_" 
  val tableReference = new TableReference().setTableId(tableId)
  val table = new Table().setSchema(new TableSchema().setFields(
    List(
      new TableFieldSchema().setName("geo").setType("RECORD").setFields(
        List(
          new TableFieldSchema().setName("type").setType("STRING"),
          new TableFieldSchema().setName("coordinates").setType("RECORD").setMode("REPEATED").setFields(
            List(
              new TableFieldSchema().setName("index").setType("RECORD").setMode("REPEATED").setFields(
                List(
                   new TableFieldSchema().setName("sub_index").setType("RECORD").setMode("REPEATED").
                     setFields(List( new TableFieldSchema().setName("_0").setType("STRING"),
                   new TableFieldSchema().setName("_1").setType("STRING")))
                )
              )
            )
          )
        )
      ))
    )
  ).setTableReference(tableReference)

After creating the table you can load the data from csv file or you can also programmatically insert the data.

This would create a table schema like this

这篇关于如何将嵌套数组加载到Google BigQuery中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆