3

Is there a way to programmatically (Java API) get Bigquery's table and dataset metadata?

I was trying to create a report on the size, creator, creation time of each tables/datasets and want to avoid doing it manually. We have a lot of tables.

Febian Shah
  • 967
  • 5
  • 12
  • 23
  • 2
    check this out: http://stackoverflow.com/questions/22734777/how-do-i-use-the-table-query-function-in-bigquery/22735031#22735031 – N.N. May 28 '14 at 05:27

2 Answers2

3

Thanks N.N. This worked:

SELECT dataset_id, table_id, size_bytes FROM <<>>.TABLES WHERE size_bytes > 0 order by size_bytes desc

Anyway to get created_by?

Febian Shah
  • 967
  • 5
  • 12
  • 23
  • you're welcome. I am not aware of anyway to retrieve creator... this is a question for Jordan, Felipe, & co. – N.N. May 28 '14 at 11:55
  • Thanks N.N.! That would be a great feature requests for https://code.google.com/p/google-bigquery-tools/issues/list. This is an interesting use case btw, how many people do you have creating tables? – Felipe Hoffa May 28 '14 at 13:02
  • 1
    Right now we just have three users. But we see this increasing to around 10 users soon. I've posted this feature along with a few other features I would love seeing in Bigquery. https://code.google.com/p/google-bigquery-tools/issues/detail?id=23 https://code.google.com/p/google-bigquery-tools/issues/detail?id=24 – Febian Shah May 28 '14 at 17:47
1

regarding getting the table metadata, with java you can do it like this

Tables tableRequest = bigquery.tables();
Table table =     tableRequest.get(projectName,datasetName,tableName).execute();
List<TableFieldSchema> fields = table.getSchema().getFields();

contact me if you have any more questions. i worked alot with big query table schema

Yonihu
  • 171
  • 1
  • 1
  • 6
  • I can't find method getSchema at Table class. I'm not sure if it is the same class you are referring to here or not. I'm looking at com.google.cloud.bigquery.Table – Mahmoud Hanafy Sep 14 '18 at 09:34