1
votes

Is there a way to get the table creation time using the Bigquery Java Api? Currently I see that you can only fetch datasetid, projectid and tableid.

My usecase: I have a program that creates a table on a daily basis. Sometimes this program is run more than once a day. I wanted to add a check to see if the table was already created for this date and if so - ignore recreating it. For various other reasons, I cannot append the creation time to the tableid.

1

1 Answers

2
votes
  1. You can use the creationTime field returned by the API. The Java library already holds function for getCreationTime();

  2. You can use meta queries for that:

Run SELECT * FROM <dataset>.__TABLES_SUMMARY__ to get all meta information about table.

The __TABLES__ portion of that query may look unfamiliar. __TABLES_SUMMARY__ is a meta-table containing information about tables in a dataset. You can use this meta-table yourself. For example, the query SELECT * FROM publicdata:samples.__TABLES_SUMMARY__ will return metadata about the tables in the publicdata:samples dataset.

Available Fields:

The fields of the __TABLES_SUMMARY__ meta-table (that are all available in the TABLE_QUERY query) include:

  • table_id: name of the table.
  • creation_time: time, in milliseconds since 1/1/1970 UTC, that the table was created. This is the same as the creation_time field on the table.
  • type: whether it is a view (2) or regular table (1).

The following fields are not available in TABLE_QUERY() since they are members of __TABLES__ but not __TABLES_SUMMARY__. They're kept here for historical interest and to partially document the __TABLES__ metatable:

  • last_modified_time: time, in milliseconds since 1/1/1970 UTC, that the table was updated (either metadata or table contents). Note that if you use the tabledata.insertAll() to stream records to your table, this might be a few minutes out of date.
  • row_count: number of rows in the table.
  • size_bytes: total size in bytes of the table.