问题
There are two APIs for manipulating BigQuery entities (Datasets, Tables, Views, etc.)...
- The old (deprecated) API: com.google.api.services.bigquery
- The new API: com.google.cloud.bigquery
In the old API, the View class has a boolean flag that specifies whether the associated query is using legacy or standard SQL. That flag is accessed via the methods:
- getUseLegacySql
- setUseLegacySql
The new API introduces the ViewDefinition class, but it does not have the boolean flag.
How do you specify the SQL dialect for a ViewDefinition?
回答1:
It seems that it is indeed broken. I've just open a case in Google about it (please, star it!): https://issuetracker.google.com/issues/70662064
Meanwhile, it is working with the "bq" command line, or with REST (which is the approach I took, until the Java API is fixed).
Update on 15/12/21017:
Google just advised me to use the "#standardSQL" notation at the beginning of the query. It works fine and I prefer it than using REST.
Here is an example:
ViewDefinition tableDefinition = ViewDefinition.newBuilder("#standardSQL\n WITH A AS (select 1 as foo) SELECT * from A").build();
来源:https://stackoverflow.com/questions/46813165/specify-sql-dialect-for-viewdefinition-in-bigquery-api