bigquery-emulator icon indicating copy to clipboard operation
bigquery-emulator copied to clipboard

BigQueryException: Failed to create view with recursive CTE

Open SButterfly opened this issue 1 year ago • 1 comments

Steps to reproduce

        bigQuery.create(DatasetInfo.of("temp"));
        bigQuery.create(TableInfo.of(TableId.of("temp", "countries"), StandardTableDefinition.of(
            Schema.of(Field.newBuilder("name", StandardSQLTypeName.STRING).build())
        )));
        bigQuery.create(TableInfo.of(TableId.of("temp", "my_view"), ViewDefinition.of(
            "with recursive all_countries as (select * from temp.countries)\n" +
                "select * from all_countries"
        )));

Will lead to an exception

com.google.cloud.bigquery.BigQueryException: failed to create view CREATE VIEW `test-project.temp.my_view` AS (with recursive all_countries as (select * from temp.countries)
select * from all_countries): failed to analyze: INVALID_ARGUMENT: RECURSIVE is not supported in the WITH clause [at 1:45]
	at com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc.translate(HttpBigQueryRpc.java:115)
	at com.google.cloud.bigquery.spi.v2.HttpBigQueryRpc.create(HttpBigQueryRpc.java:187)
	at com.google.cloud.bigquery.BigQueryImpl$2.call(BigQueryImpl.java:300)
	at com.google.cloud.bigquery.BigQueryImpl$2.call(BigQueryImpl.java:297)
	at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:103)
	at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
	at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
	at com.google.cloud.bigquery.BigQueryImpl.create(BigQueryImpl.java:296)

But if you execute the same SQL in BigQuery, everything will be successful

CREATE VIEW `temp.my_view` AS (
with recursive all_countries as (select * from temp.countries)
select * from all_countries
);

SButterfly avatar Jul 26 '23 12:07 SButterfly

Recursive CTEs are currently not supported.

https://github.com/goccy/go-zetasqlite#query

totem3 avatar Dec 11 '23 01:12 totem3