Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add column description to BiqQuery table?

need to add descriptions to each column of a BigQuery table, seems I can do it manually, how to do it programmatically?

like image 516
Echo Avatar asked May 02 '15 21:05

Echo


1 Answers

As Adam mentioned, you can use the table PATCH method on the API to update the schema columns. The other method is to use bq.

You can first get the schema by doing the following:

1: Get the JSON schema:

TABLE=publicdata:samples.shakespeare

bq show --format=prettyjson ${TABLE} > table.txt

Then copy the schema from table.txt to schema.txt ... it will look something like:

[
  {
    "description": "A single unique word (where whitespace is the delimiter) extracted from a corpus.",
    "mode": "REQUIRED",
    "name": "word",
    "type": "STRING"
  },
  {
    "description": "The number of times this word appears in this corpus.",
    "mode": "REQUIRED",
    "name": "word_count",
    "type": "INTEGER"
  },
  ....
]

2: Set the description field to whatever you want (if it is not there, add it).

3: Tell BigQuery to update the schema with the added columns. Note that schema.txt must contain the complete schema.

 bq update --schema schema.txt -t ${TABLE}
like image 149
Jordan Tigani Avatar answered Oct 14 '22 05:10

Jordan Tigani