Skip to content

Commit 2c41ffa

Browse files
committed
support undrop statement. fix #331
1 parent 26ef362 commit 2c41ffa

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

expected_output/ddl.sql

+5
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,8 @@ DROP ROW ACCESS POLICY ident ON t;
376376
DROP ROW ACCESS POLICY IF EXISTS ident ON t;
377377

378378
DROP ALL ROW ACCESS POLICIES ON t;
379+
380+
----- UNDROP statement -----
381+
UNDROP SCHEMA datasetname;
382+
383+
UNDROP SCHEMA IF NOT EXISTS projectname.datasetname;

input/ddl.sql

+5
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,8 @@ drop row access policy ident on t;
377377
drop row access policy if exists ident on t;
378378

379379
drop all row access policies on t;
380+
381+
----- UNDROP statement -----
382+
undrop schema datasetname;
383+
384+
undrop schema if not exists projectname.datasetname;

src/printer.ts

+35
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,8 @@ export const printSQL = (
767767
return printTypeDeclaration(path, options, print, node);
768768
case "UnaryOperator":
769769
return printUnaryOperator(path, options, print, node);
770+
case "UndropStatement":
771+
return printUndropStatement(path, options, print, node);
770772
case "UnpivotConfig":
771773
return printUnpivotConfig(path, options, print, node);
772774
case "UnpivotOperator":
@@ -4913,6 +4915,39 @@ const printUnaryOperator: PrintFunc<bq2cst.UnaryOperator> = (
49134915
];
49144916
};
49154917

4918+
const printUndropStatement: PrintFunc<bq2cst.UndropStatement> = (
4919+
path,
4920+
options,
4921+
print,
4922+
node,
4923+
) => {
4924+
const p = new Printer(path, options, print, node);
4925+
const docs: { [Key in Docs<bq2cst.UndropStatement>]: Doc } = {
4926+
leading_comments: printLeadingComments(path, options, print, node),
4927+
self: p.self("upper"),
4928+
trailing_comments: printTrailingComments(path, options, print, node),
4929+
what: p.child("what", undefined, "all"),
4930+
if_not_exists: p.child("if_not_exists", (x) => group([line, x])),
4931+
ident: p.child("ident", undefined, "all"),
4932+
semicolon: p.child("semicolon"),
4933+
};
4934+
return [
4935+
docs.leading_comments,
4936+
group([
4937+
docs.self,
4938+
docs.trailing_comments,
4939+
" ",
4940+
docs.what,
4941+
docs.if_not_exists,
4942+
" ",
4943+
docs.ident,
4944+
softline,
4945+
docs.semicolon,
4946+
]),
4947+
p.newLine(),
4948+
];
4949+
};
4950+
49164951
const printUnpivotConfig: PrintFunc<bq2cst.UnpivotConfig> = (
49174952
path,
49184953
options,

0 commit comments

Comments
 (0)