Skip to content

Commit dac87a2

Browse files
authored
Merge PR #269: Support create table/view optional arguments
2 parents 75caa72 + 4fe43b1 commit dac87a2

2 files changed

Lines changed: 61 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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,55 @@ describe('BigQueryFormatter', () => {
166166
Items;
167167
`);
168168
});
169+
170+
it('supports create view optional arguments', () => {
171+
const createViewVariations = [
172+
'CREATE VIEW',
173+
'CREATE OR REPLACE VIEW',
174+
'CREATE VIEW IF NOT EXISTS',
175+
];
176+
177+
createViewVariations.forEach((createViewVariation: string) => {
178+
expect(
179+
format(`
180+
${createViewVariation} my_dataset.my_view AS (
181+
SELECT t1.col1, t1.col2 FROM my_dataset.my_table)`)
182+
).toBe(dedent`
183+
${createViewVariation}
184+
my_dataset.my_view AS (
185+
SELECT
186+
t1.col1,
187+
t1.col2
188+
FROM
189+
my_dataset.my_table
190+
)
191+
`);
192+
});
193+
});
194+
195+
it('supports create table optional arguments', () => {
196+
const createTableVariations = [
197+
'CREATE TABLE',
198+
'CREATE TABLE IF NOT EXISTS',
199+
'CREATE TEMP TABLE',
200+
'CREATE TEMP TABLE IF NOT EXISTS',
201+
'CREATE TEMPORARY TABLE',
202+
'CREATE TEMPORARY TABLE IF NOT EXISTS',
203+
'CREATE OR REPLACE TABLE',
204+
'CREATE OR REPLACE TEMP TABLE',
205+
'CREATE OR REPLACE TEMPORARY TABLE',
206+
];
207+
208+
createTableVariations.forEach((createTableVariation: string) => {
209+
expect(
210+
format(`
211+
${createTableVariation} mydataset.newtable (
212+
a INT64 NOT NULL
213+
)`)
214+
).toBe(dedent`
215+
${createTableVariation}
216+
mydataset.newtable (a INT64 NOT NULL)
217+
`);
218+
});
219+
});
169220
});

0 commit comments

Comments
 (0)