Subhayu
Subhayu

Reputation: 47

How can I load nested array into Google BigQuery?

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

Any help will be highly appreciated. Subhayu

Upvotes: 3

Views: 1662

Answers (1)

Vishal John
Vishal John

Reputation: 4382

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

enter image description here

Upvotes: 3

Related Questions