Skip to content

Commit 9fb4375

Browse files
Support create table/view optional arguments
1 parent 44071e3 commit 9fb4375

2 files changed

Lines changed: 134 additions & 0 deletions

File tree

src/languages/bigquery.formatter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,21 @@ const reservedCommands = [
718718
'SET SCHEMA', // added
719719
'CREATE SCHEMA',
720720
'CREATE TABLE',
721+
'CREATE TABLE IF NOT EXISTS',
722+
'CREATE TEMP TABLE',
723+
'CREATE TEMP TABLE IF NOT EXISTS',
724+
'CREATE TEMPORARY TABLE',
725+
'CREATE TEMPORARY TABLE IF NOT EXISTS',
726+
'CREATE OR REPLACE TABLE',
727+
'CREATE OR REPLACE TEMP TABLE',
728+
'CREATE OR REPLACE TEMPORARY TABLE',
721729
'CREATE TABLE LIKE',
722730
'CREATE TABLE COPY',
723731
'CREATE SNAPSHOT TABLE',
724732
'CREATE TABLE CLONE',
725733
'CREATE VIEW',
734+
'CREATE VIEW IF NOT EXISTS',
735+
'CREATE OR REPLACE VIEW',
726736
'CREATE MATERIALIZED VIEW',
727737
'CREATE EXTERNAL TABLE',
728738
'CREATE FUNCTION',

test/bigquery.test.ts

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,128 @@ describe('BigQueryFormatter', () => {
166166
Items;
167167
`);
168168
});
169+
170+
it('supports create view optional arguments', () => {
171+
expect(
172+
format(`
173+
CREATE OR REPLACE VIEW my_dataset.my_view AS (
174+
SELECT t1.col1, t1.col2 FROM my_dataset.my_table)`)
175+
).toBe(dedent`
176+
CREATE OR REPLACE VIEW
177+
my_dataset.my_view AS (
178+
SELECT
179+
t1.col1,
180+
t1.col2
181+
FROM
182+
my_dataset.my_table
183+
)
184+
`);
185+
186+
expect(
187+
format(`
188+
CREATE VIEW IF NOT EXISTS my_dataset.my_view AS (
189+
SELECT t1.col1, t1.col2 FROM my_dataset.my_table)`)
190+
).toBe(dedent`
191+
CREATE VIEW IF NOT EXISTS
192+
my_dataset.my_view AS (
193+
SELECT
194+
t1.col1,
195+
t1.col2
196+
FROM
197+
my_dataset.my_table
198+
)
199+
`);
200+
});
201+
202+
it('supports create table optional arguments', () => {
203+
expect(
204+
format(`
205+
CREATE TABLE mydataset.newtable (
206+
a INT64 NOT NULL
207+
)`)
208+
).toBe(dedent`
209+
CREATE TABLE
210+
mydataset.newtable (a INT64 NOT NULL)
211+
`);
212+
213+
expect(
214+
format(`
215+
CREATE TABLE IF NOT EXISTS mydataset.newtable (
216+
a INT64 NOT NULL
217+
)`)
218+
).toBe(dedent`
219+
CREATE TABLE IF NOT EXISTS
220+
mydataset.newtable (a INT64 NOT NULL)
221+
`);
222+
223+
expect(
224+
format(`
225+
CREATE TEMP TABLE mydataset.newtable (
226+
a INT64 NOT NULL
227+
)`)
228+
).toBe(dedent`
229+
CREATE TEMP TABLE
230+
mydataset.newtable (a INT64 NOT NULL)
231+
`);
232+
233+
expect(
234+
format(`
235+
CREATE TEMP TABLE IF NOT EXISTS mydataset.newtable (
236+
a INT64 NOT NULL
237+
)`)
238+
).toBe(dedent`
239+
CREATE TEMP TABLE IF NOT EXISTS
240+
mydataset.newtable (a INT64 NOT NULL)
241+
`);
242+
243+
expect(
244+
format(`
245+
CREATE TEMPORARY TABLE mydataset.newtable (
246+
a INT64 NOT NULL
247+
)`)
248+
).toBe(dedent`
249+
CREATE TEMPORARY TABLE
250+
mydataset.newtable (a INT64 NOT NULL)
251+
`);
252+
253+
expect(
254+
format(`
255+
CREATE TEMPORARY TABLE IF NOT EXISTS mydataset.newtable (
256+
a INT64 NOT NULL
257+
)`)
258+
).toBe(dedent`
259+
CREATE TEMPORARY TABLE IF NOT EXISTS
260+
mydataset.newtable (a INT64 NOT NULL)
261+
`);
262+
263+
expect(
264+
format(`
265+
CREATE OR REPLACE TABLE mydataset.newtable (
266+
a INT64 NOT NULL
267+
)`)
268+
).toBe(dedent`
269+
CREATE OR REPLACE TABLE
270+
mydataset.newtable (a INT64 NOT NULL)
271+
`);
272+
273+
expect(
274+
format(`
275+
CREATE OR REPLACE TEMP TABLE mydataset.newtable (
276+
a INT64 NOT NULL
277+
)`)
278+
).toBe(dedent`
279+
CREATE OR REPLACE TEMP TABLE
280+
mydataset.newtable (a INT64 NOT NULL)
281+
`);
282+
283+
expect(
284+
format(`
285+
CREATE OR REPLACE TEMPORARY TABLE mydataset.newtable (
286+
a INT64 NOT NULL
287+
)`)
288+
).toBe(dedent`
289+
CREATE OR REPLACE TEMPORARY TABLE
290+
mydataset.newtable (a INT64 NOT NULL)
291+
`);
292+
});
169293
});

0 commit comments

Comments
 (0)