google / zetasql

ZetaSQL - Analyzer Framework for SQL
Apache License 2.0
2.28k stars 214 forks source link

BigQuery Dialect - CREATE TABLE CLONE and COPY #141

Open jrbangit opened 1 year ago

jrbangit commented 1 year ago

Hi, All

just wondering if there is a support coming for these bigquery statements?

CREATE TABLE `tbl`
CLONE `src_tbl`;
CREATE TABLE `tbl`
COPY `src_tbl`

reference: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#create_table_copy

currently, I'm encountering this limitation below.

com.google.zetasql.SqlException: CREATE TABLE CLONE is not supported [at 4:7]

edit: it seems COPY is supported, only CLONE is not supported.

Thank you!

matthewcbrown commented 1 year ago

Support in the evaluator is not likely, but it is supported in the various other api calls (Analyzer.java).

You may need to modify the LanguageOptions to enable the statements you need enabled: You can see an example here: https://github.com/google/zetasql/blob/206e78c86a85053f2c0d75db6fa7b1998181263b/javatests/com/google/zetasql/AnalyzerTest.java#L284

AnalyzerOptions analyzerOptions = new AnalyzerOptions();
analyzerOptions
    .getLanguageOptions()
    .setSupportedStatementKinds(ImmutableSet.of(ResolvedNodeKind.RESOLVED_CREATE_TABLE_STMT));
Analyzer.analyzeStatement(sql, analyzerOptions, new SimpleCatalog(""))
pratnaparkhi2000 commented 7 months ago

Hi, CLONE query works for me.

CREATE TABLE .. CLONE .. FOR SYSTEM_TIME AS OF CURRENT_TIMESTAMP();