Specify SQL dialect for ViewDefinition in BigQuery API

独自空忆成欢 提交于 2020-01-14 05:05:22

问题


There are two APIs for manipulating BigQuery entities (Datasets, Tables, Views, etc.)...

  1. The old (deprecated) API: com.google.api.services.bigquery
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!