Is it possible to add a new field to an existing field of RECORD type in bigquery from UI?

与世无争的帅哥 提交于 2020-08-01 06:30:58

问题


Is it possible to add a new field to an existing field of RECORD type in bigquery? So for example if my current schema is :

{u'fields': [{u'mode': u'NULLABLE', u'name': u'test1', u'type': u'STRING'},
             {u'fields': [{u'mode': u'NULLABLE',
                           u'name': u'field1',
                           u'type': u'STRING'}],
              u'mode': u'NULLABLE',
              u'name': u'recordtest',
              u'type': u'RECORD'}]}

Can I change it to add field "field2" to recordtest? So the new schema will look like:

{u'fields': [{u'mode': u'NULLABLE', u'name': u'test1', u'type': u'STRING'},
             {u'fields': [{u'mode': u'NULLABLE',
                           u'name': u'field1',
                           u'type': u'STRING'},
                          {u'mode': u'NULLABLE',
                           u'name': u'field2',
                           u'type': u'STRING'}],
              u'mode': u'NULLABLE',
              u'name': u'recordtest',
              u'type': u'RECORD'}]}

I couldn't find a way to do this from the UI. But I was able to do this using the API.


回答1:


This can be done totally from within UI using respective API Explorers

First, you need to get schema of your table. You can do this using Tables.get API Explorer. Make sure you select/check schema in fields box (better to leave the rest unchecked). Click Authorize and Execute. When done - Copy response text - it will look somehow like below

{
 "schema": {
  "fields": [
   {
    "name": "id",
    "type": "STRING",
    "mode": "NULLABLE"
   },

... 

   {
    "name": "comment",
    "type": "STRING",
    "mode": "NULLABLE"
   }
  ]
 }
}

Then, use Tables.patch API Explorer
Add needed fields(s) into previously retrieved schema and paste it as is into Patch Body box (chose freeform editor in the right-top corner of this box and just replace whatever inside with your schema's text). Again click Authorize and Execute

You done now.
Note that no matter where you put your new field within record - it will be added to the end of this record fields

Btw, alternatively, you can use standalone Explorers
Services > BigQuery API v2

The ones that we used here are bigquery.jobs.get and bigquery.tables.patch



来源:https://stackoverflow.com/questions/40033346/is-it-possible-to-add-a-new-field-to-an-existing-field-of-record-type-in-bigquer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!