Reputation: 6999
Using the Java client library for Google BigQuery, how does one create a view?
Upvotes: 1
Views: 619
Reputation: 33705
The relevant API call is tables.insert. With the Java API, this is represented by the create
method on the BigQuery service object. You first have to create a TableInfo
, which encapsulates a ViewDefinition
object. The documentation for setDefinition
on TableInfo.Builder
says:
Sets the table definition. Use StandardTableDefinition to create simple BigQuery table. Use ViewDefinition to create a BigQuery view. Use ExternalTableDefinition to create a BigQuery a table backed by external data.
Sample code:
bigQuery.create(TableInfo.of(TableId.of("DatasetName", "ViewName"),
ViewDefinition.of("SELECT this, is, the, view FROM query")))
Upvotes: 2