goccy / bigquery-emulator

BigQuery emulator server implemented in Go
MIT License
831 stars 109 forks source link

BigQueryException: Failed to create view with recursive CTE #216

Open SButterfly opened 1 year ago

SButterfly commented 1 year ago

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
);
totem3 commented 11 months ago

Recursive CTEs are currently not supported.

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