Skip to content

Commit

Permalink
BREAKING! Replace *Kw fields in CreateViewStmt with ViewKind
Browse files Browse the repository at this point in the history
Similar to TableKind in CreateTableStmt.
  • Loading branch information
nene committed Jan 30, 2024
1 parent 454a068 commit c8beba7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
11 changes: 7 additions & 4 deletions src/cst/View.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ClusterByClause } from "./OtherClauses";
import { AsClause } from "./ProcClause";
import { PartitionByClause, SubSelect } from "./Select";

export type AllViewNodes = AllViewStatements | WithCheckOptionClause;
export type AllViewNodes = AllViewStatements | ViewKind | WithCheckOptionClause;

export type AllViewStatements = CreateViewStmt | DropViewStmt | AlterViewStmt;

Expand All @@ -16,16 +16,19 @@ export interface CreateViewStmt extends BaseNode {
type: "create_view_stmt";
createKw: Keyword<"CREATE">;
orReplaceKw?: [Keyword<"OR">, Keyword<"REPLACE">];
temporaryKw?: Keyword<"TEMP" | "TEMPORARY">;
recursiveKw?: Keyword<"RECURSIVE">;
materializedKw?: Keyword<"MATERIALIZED">;
kinds: ViewKind[];
viewKw: Keyword<"VIEW">;
ifNotExistsKw?: [Keyword<"IF">, Keyword<"NOT">, Keyword<"EXISTS">];
name: EntityName;
columns?: ParenExpr<ListExpr<Identifier>>;
clauses: CreateViewClause[];
}

export interface ViewKind extends BaseNode {
type: "view_kind";
kindKw: Keyword<"TEMP" | "TEMPORARY" | "MATERIALIZED" | "RECURSIVE">;
}

type CreateViewClause =
| BigqueryOptions
| PostgresqlWithOptions
Expand Down
19 changes: 13 additions & 6 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1776,9 +1776,7 @@ merge_action_insert_row_clause
create_view_stmt
= createKw:CREATE
repKw:(__ OR __ REPLACE)?
tmpKw:(__ (TEMP / TEMPORARY))?
recursiveKw:(__ RECURSIVE)?
materKw:(__ MATERIALIZED)?
kinds:(__ view_kind)*
viewKw:(__ VIEW)
ifKw:(__ if_not_exists)?
name:(__ entity_name)
Expand All @@ -1788,9 +1786,7 @@ create_view_stmt
type: "create_view_stmt",
createKw,
orReplaceKw: read(repKw),
temporaryKw: read(tmpKw),
recursiveKw: read(recursiveKw),
materializedKw: read(materKw),
kinds: kinds.map(read),
viewKw: read(viewKw),
ifNotExistsKw: read(ifKw),
name: read(name),
Expand All @@ -1799,6 +1795,17 @@ create_view_stmt
});
}

view_kind
= kw:(TEMP / TEMPORARY) (&sqlite / &postgres) {
return loc({ type: "table_kind", kindKw: kw });
}
/ kw:RECURSIVE &postgres {
return loc({ type: "table_kind", kindKw: read(kw) });
}
/ kw:MATERIALIZED (&bigquery / &postgres) {
return loc({ type: "table_kind", kindKw: kw });
}

create_view_clause
= as_clause$compound_select_stmt
/ &bigquery op:bigquery_create_view_clause { return op; }
Expand Down
5 changes: 2 additions & 3 deletions src/showNode/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ export const viewMap: FullTransformMap<string, AllViewNodes> = {
show([
node.createKw,
node.orReplaceKw,
node.temporaryKw,
node.recursiveKw,
node.materializedKw,
node.kinds,
node.viewKw,
node.ifNotExistsKw,
node.name,
node.columns,
node.clauses,
]),
view_kind: (node) => show([node.kindKw]),
with_check_option_clause: (node) =>
show([node.withKw, node.levelKw, node.checkOptionKw]),
// DROP VIEW statement
Expand Down

0 comments on commit c8beba7

Please sign in to comment.