Skip to content

Commit

Permalink
Breaking! Support OPTIONS() in biquery CREATE VIEW columns list
Browse files Browse the repository at this point in the history
The CreateViewStmt.columns field now contains list of ColumnDefinition
nodes instead of just list of Identifier nodes.
  • Loading branch information
nene committed Feb 7, 2024
1 parent 590b00f commit 1ba2459
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/cst/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
WithDataClause,
UsingAccessMethodClause,
RelationKind,
ColumnDefinition,
} from "./CreateTable";
import { BigqueryOptions } from "./dialects/Bigquery";
import { PostgresqlWithOptions } from "./dialects/Postgresql";
Expand Down Expand Up @@ -33,7 +34,7 @@ export interface CreateViewStmt extends BaseNode {
viewKw: Keyword<"VIEW">;
ifNotExistsKw?: [Keyword<"IF">, Keyword<"NOT">, Keyword<"EXISTS">];
name: EntityName;
columns?: ParenExpr<ListExpr<Identifier>>;
columns?: ParenExpr<ListExpr<ColumnDefinition>>;
clauses: CreateViewClause[];
}

Expand Down
16 changes: 14 additions & 2 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ create_view_stmt
viewKw:(__ VIEW)
ifKw:(__ if_not_exists)?
name:(__ entity_name)
cols:(__ paren$list$column)?
cols:(__ paren$list$view_column_definition)?
clauses:(__ create_view_clause)+ {
return loc({
type: "create_view_stmt",
Expand All @@ -1873,6 +1873,16 @@ view_kind
return loc({ type: "relation_kind", kindKw: kw });
}

// Just like column_definition, but with the only possible constraint being bigquery OPTIONS()
view_column_definition
= name:ident constraints:(__ bigquery_options)|0..1| {
return loc({
type: "column_definition",
name,
constraints: constraints.map(read),
});
}

create_view_clause
= as_clause$compound_select_stmt
/ &bigquery op:bigquery_create_view_clause { return op; }
Expand Down Expand Up @@ -2533,7 +2543,7 @@ create_table_server_clause
}

bigquery_options
= kw:(OPTIONS __) options:paren$list$equals_expr {
= &bigquery kw:(OPTIONS __) options:paren$list$equals_expr {
return loc({
type: "bigquery_options",
optionsKw: read(kw),
Expand Down Expand Up @@ -6647,6 +6657,7 @@ paren$list$string_literal = .
paren$list$table_func_call = .
paren$list$table_option_postgresql = .
paren$list$tablesample_arg = .
paren$list$view_column_definition = .
paren$pivot_for_in = .
paren$postgresql_op = .
paren$pragma_value = .
Expand Down Expand Up @@ -6723,6 +6734,7 @@ list$transform_type = .
list$type_param = .
list$values_row = .
list$variable = .
list$view_column_definition = .
/*! list:end */

empty_list
Expand Down
10 changes: 10 additions & 0 deletions test/ddl/view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ describe("view", () => {
it("supports columns list", () => {
testWc("CREATE VIEW my_view (col1, col2) AS SELECT 1, 2");
});
dialect("bigquery", () => {
it("supports OPTIONS() in columns list", () => {
testWc(`
CREATE VIEW person (
id OPTIONS(description='identity'),
name OPTIONS(description='full person name')
) AS SELECT 1, 'John'
`);
});
});

dialect(["mysql", "mariadb", "bigquery", "postgresql"], () => {
it("supports OR REPLACE", () => {
Expand Down

0 comments on commit 1ba2459

Please sign in to comment.