Skip to content

Commit

Permalink
Merge branch 'master' into data-type-case-option
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Dec 7, 2023
2 parents bcd084d + 59fe667 commit 98b3816
Show file tree
Hide file tree
Showing 26 changed files with 87 additions and 88 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Sebastian Lyng Johansen <[email protected]>
Sergei Egorov <[email protected]>
Stanislav Germanovskii <[email protected]>
Steven Yung <[email protected]>
Timon Jurschitsch <[email protected]>
Tito Griné <[email protected]>
Toliver <[email protected]>
Toni Müller <[email protected]>
Expand Down
3 changes: 2 additions & 1 deletion src/languages/bigquery/bigquery.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const reservedClauses = expandPhrases([
'UPDATE SET',
// Data definition, https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language
'CREATE [OR REPLACE] [MATERIALIZED] VIEW [IF NOT EXISTS]',
'CREATE [OR REPLACE] [TEMP|TEMPORARY|SNAPSHOT|EXTERNAL] TABLE [IF NOT EXISTS]',

'CLUSTER BY',
'FOR SYSTEM_TIME AS OF', // CREATE SNAPSHOT TABLE
Expand All @@ -42,6 +41,8 @@ const reservedClauses = expandPhrases([
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [OR REPLACE] [TEMP|TEMPORARY|SNAPSHOT|EXTERNAL] TABLE [IF NOT EXISTS]',
// - update:
'UPDATE',
// - delete:
Expand Down
3 changes: 2 additions & 1 deletion src/languages/db2/db2.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ const reservedClauses = expandPhrases([
'INSERT',
// Data definition
'CREATE [OR REPLACE] VIEW',
'CREATE [GLOBAL TEMPORARY | EXTERNAL] TABLE [IF NOT EXISTS]',
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [GLOBAL TEMPORARY | EXTERNAL] TABLE [IF NOT EXISTS]',
// - update:
'UPDATE',
'WHERE CURRENT OF',
Expand Down
3 changes: 2 additions & 1 deletion src/languages/db2i/db2i.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ const reservedClauses = expandPhrases([
'DELETE',
'INSERT',
// Data definition - table
'CREATE [OR REPLACE] TABLE',
'FOR SYSTEM NAME',
// Data definition - view
'CREATE [OR REPLACE] [RECURSIVE] VIEW',
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [OR REPLACE] TABLE',
// - update:
'UPDATE',
'WHERE CURRENT OF',
Expand Down
3 changes: 2 additions & 1 deletion src/languages/hive/hive.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ const reservedClauses = expandPhrases([
'[OVERWRITE] INTO TABLE',
// Data definition
'CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]',
'CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS]',
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [TEMPORARY] [EXTERNAL] TABLE [IF NOT EXISTS]',
// - update:
'UPDATE',
// - delete:
Expand Down
3 changes: 2 additions & 1 deletion src/languages/mariadb/mariadb.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ const reservedClauses = expandPhrases([
'SET',
// Data definition
'CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]',
'CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS]',
// other
'RETURNING',
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [OR REPLACE] [TEMPORARY] TABLE [IF NOT EXISTS]',
// - update:
'UPDATE [LOW_PRIORITY] [IGNORE]',
// - delete:
Expand Down
3 changes: 2 additions & 1 deletion src/languages/mysql/mysql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ const reservedClauses = expandPhrases([
'SET',
// Data definition
'CREATE [OR REPLACE] [SQL SECURITY DEFINER | SQL SECURITY INVOKER] VIEW [IF NOT EXISTS]',
'CREATE [TEMPORARY] TABLE [IF NOT EXISTS]',
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [TEMPORARY] TABLE [IF NOT EXISTS]',
// - update:
'UPDATE [LOW_PRIORITY] [IGNORE]',
// - delete:
Expand Down
3 changes: 2 additions & 1 deletion src/languages/plsql/plsql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ const reservedClauses = expandPhrases([
// Data definition
'CREATE [OR REPLACE] [NO FORCE | FORCE] [EDITIONING | EDITIONABLE | EDITIONABLE EDITIONING | NONEDITIONABLE] VIEW',
'CREATE MATERIALIZED VIEW',
'CREATE [GLOBAL TEMPORARY | PRIVATE TEMPORARY | SHARDED | DUPLICATED | IMMUTABLE BLOCKCHAIN | BLOCKCHAIN | IMMUTABLE] TABLE',
// other
'RETURNING',
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [GLOBAL TEMPORARY | PRIVATE TEMPORARY | SHARDED | DUPLICATED | IMMUTABLE BLOCKCHAIN | BLOCKCHAIN | IMMUTABLE] TABLE',
// - update:
'UPDATE [ONLY]',
// - delete:
Expand Down
3 changes: 2 additions & 1 deletion src/languages/postgresql/postgresql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ const reservedClauses = expandPhrases([
// Data definition
'CREATE [OR REPLACE] [TEMP | TEMPORARY] [RECURSIVE] VIEW',
'CREATE MATERIALIZED VIEW [IF NOT EXISTS]',
'CREATE [GLOBAL | LOCAL] [TEMPORARY | TEMP | UNLOGGED] TABLE [IF NOT EXISTS]',
// other
'RETURNING',
]);

const onelineClauses = expandPhrases([
// - create
'CREATE [GLOBAL | LOCAL] [TEMPORARY | TEMP | UNLOGGED] TABLE [IF NOT EXISTS]',
// - update:
'UPDATE [ONLY]',
'WHERE CURRENT OF',
Expand Down
3 changes: 2 additions & 1 deletion src/languages/redshift/redshift.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ const reservedClauses = expandPhrases([
'SET',
// Data definition
'CREATE [OR REPLACE | MATERIALIZED] VIEW',
'CREATE [TEMPORARY | TEMP | LOCAL TEMPORARY | LOCAL TEMP] TABLE [IF NOT EXISTS]',
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [TEMPORARY | TEMP | LOCAL TEMPORARY | LOCAL TEMP] TABLE [IF NOT EXISTS]',
// - update:
'UPDATE',
// - delete:
Expand Down
3 changes: 2 additions & 1 deletion src/languages/singlestoredb/singlestoredb.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ const reservedClauses = expandPhrases([
'SET',
// Data definition
'CREATE VIEW',
'CREATE [ROWSTORE] [REFERENCE | TEMPORARY | GLOBAL TEMPORARY] TABLE [IF NOT EXISTS]',
'CREATE [OR REPLACE] [TEMPORARY] PROCEDURE [IF NOT EXISTS]',
'CREATE [OR REPLACE] [EXTERNAL] FUNCTION',
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [ROWSTORE] [REFERENCE | TEMPORARY | GLOBAL TEMPORARY] TABLE [IF NOT EXISTS]',
// - update:
'UPDATE',
// - delete:
Expand Down
5 changes: 3 additions & 2 deletions src/languages/snowflake/snowflake.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const reservedClauses = expandPhrases([
// - view
'CREATE [OR REPLACE] [SECURE] [RECURSIVE] VIEW [IF NOT EXISTS]',
// - create/drop/merge table
'CREATE [OR REPLACE] [VOLATILE] TABLE [IF NOT EXISTS]',
'CREATE [OR REPLACE] [LOCAL | GLOBAL] {TEMP|TEMPORARY} TABLE [IF NOT EXISTS]',
'CLUSTER BY',
'[WITH] {MASKING POLICY | TAG | ROW ACCESS POLICY}',
'COPY GRANTS',
Expand All @@ -42,6 +40,9 @@ const reservedClauses = expandPhrases([
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [OR REPLACE] [VOLATILE] TABLE [IF NOT EXISTS]',
'CREATE [OR REPLACE] [LOCAL | GLOBAL] {TEMP|TEMPORARY} TABLE [IF NOT EXISTS]',
// - update:
'UPDATE',
// - delete:
Expand Down
3 changes: 2 additions & 1 deletion src/languages/spark/spark.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ const reservedClauses = expandPhrases([
'[OVERWRITE] INTO TABLE',
// Data definition
'CREATE [OR REPLACE] [GLOBAL TEMPORARY | TEMPORARY] VIEW [IF NOT EXISTS]',
'CREATE [EXTERNAL] TABLE [IF NOT EXISTS]',
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [EXTERNAL] TABLE [IF NOT EXISTS]',
// - drop table:
'DROP TABLE [IF EXISTS]',
// - alter table:
Expand Down
3 changes: 2 additions & 1 deletion src/languages/sql/sql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ const reservedClauses = expandPhrases([
'SET',
// Data definition
'CREATE [RECURSIVE] VIEW',
'CREATE [GLOBAL TEMPORARY | LOCAL TEMPORARY] TABLE',
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [GLOBAL TEMPORARY | LOCAL TEMPORARY] TABLE',
// - update:
'UPDATE',
'WHERE CURRENT OF',
Expand Down
3 changes: 2 additions & 1 deletion src/languages/sqlite/sqlite.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ const reservedClauses = expandPhrases([
'SET',
// Data definition
'CREATE [TEMPORARY | TEMP] VIEW [IF NOT EXISTS]',
'CREATE [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]',
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE [TEMPORARY | TEMP] TABLE [IF NOT EXISTS]',
// - update:
'UPDATE [OR ABORT | OR FAIL | OR IGNORE | OR REPLACE | OR ROLLBACK]',
// - insert:
Expand Down
3 changes: 2 additions & 1 deletion src/languages/transactsql/transactsql.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ const reservedClauses = expandPhrases([
'UPDATE SET',
// Data definition
'CREATE [OR ALTER] [MATERIALIZED] VIEW',
'CREATE TABLE',
'CREATE [OR ALTER] {PROC | PROCEDURE}',
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE TABLE',
// - update:
'UPDATE',
'WHERE CURRENT OF',
Expand Down
3 changes: 2 additions & 1 deletion src/languages/trino/trino.formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const reservedClauses = expandPhrases([
'SET',
// Data definition
'CREATE [OR REPLACE] [MATERIALIZED] VIEW',
'CREATE TABLE [IF NOT EXISTS]',
// MATCH_RECOGNIZE
'MATCH_RECOGNIZE',
'MEASURES',
Expand All @@ -40,6 +39,8 @@ const reservedClauses = expandPhrases([
]);

const onelineClauses = expandPhrases([
// - create:
'CREATE TABLE [IF NOT EXISTS]',
// - update:
'UPDATE',
// - delete:
Expand Down
3 changes: 1 addition & 2 deletions test/behavesLikeMariaDbFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ export default function behavesLikeMariaDbFormatter(format: FormatFn) {
}
)
).toBe(dedent`
CREATE TABLE
account (id INT comment 'the most important column');
CREATE TABLE account (id INT comment 'the most important column');
SELECT
*
Expand Down
3 changes: 1 addition & 2 deletions test/bigquery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ describe('BigQueryFormatter', () => {
uris = ['gs://bucket/path1.csv']
)`;
const expected = dedent`
CREATE EXTERNAL TABLE
dataset.CsvTable
CREATE EXTERNAL TABLE dataset.CsvTable
WITH PARTITION COLUMNS
(field_1 STRING, field_2 INT64) OPTIONS(format = 'CSV', uris = ['gs://bucket/path1.csv'])`;
expect(format(input)).toBe(expected);
Expand Down
9 changes: 4 additions & 5 deletions test/features/constraints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ export default function supportsConstraints(format: FormatFn, actions: string[])
);
`)
).toBe(dedent`
CREATE TABLE
foo (
update_time datetime ON UPDATE ${action},
delete_time datetime ON DELETE ${action},
);
CREATE TABLE foo (
update_time datetime ON UPDATE ${action},
delete_time datetime ON DELETE ${action},
);
`);
});
});
Expand Down
34 changes: 14 additions & 20 deletions test/features/createTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ interface CreateTableConfig {
export default function supportsCreateTable(format: FormatFn, cfg: CreateTableConfig = {}) {
it('formats short CREATE TABLE', () => {
expect(format('CREATE TABLE tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent`
CREATE TABLE
tbl (a INT PRIMARY KEY, b TEXT);
CREATE TABLE tbl (a INT PRIMARY KEY, b TEXT);
`);
});

Expand All @@ -23,30 +22,27 @@ export default function supportsCreateTable(format: FormatFn, cfg: CreateTableCo
expect(
format('CREATE TABLE tbl (a INT PRIMARY KEY, b TEXT, c INT NOT NULL, doggie INT NOT NULL);')
).toBe(dedent`
CREATE TABLE
tbl (
a INT PRIMARY KEY,
b TEXT,
c INT NOT NULL,
doggie INT NOT NULL
);
CREATE TABLE tbl (
a INT PRIMARY KEY,
b TEXT,
c INT NOT NULL,
doggie INT NOT NULL
);
`);
});

if (cfg.orReplace) {
it('formats short CREATE OR REPLACE TABLE', () => {
expect(format('CREATE OR REPLACE TABLE tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent`
CREATE OR REPLACE TABLE
tbl (a INT PRIMARY KEY, b TEXT);
CREATE OR REPLACE TABLE tbl (a INT PRIMARY KEY, b TEXT);
`);
});
}

if (cfg.ifNotExists) {
it('formats short CREATE TABLE IF NOT EXISTS', () => {
expect(format('CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent`
CREATE TABLE IF NOT EXISTS
tbl (a INT PRIMARY KEY, b TEXT);
CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);
`);
});
}
Expand All @@ -56,20 +52,18 @@ export default function supportsCreateTable(format: FormatFn, cfg: CreateTableCo
expect(
format(`CREATE TABLE tbl (a INT COMMENT 'Hello world!', b TEXT COMMENT 'Here we are!');`)
).toBe(dedent`
CREATE TABLE
tbl (
a INT COMMENT 'Hello world!',
b TEXT COMMENT 'Here we are!'
);
CREATE TABLE tbl (
a INT COMMENT 'Hello world!',
b TEXT COMMENT 'Here we are!'
);
`);
});
}

if (cfg.tableComment) {
it('formats short CREATE TABLE with comment', () => {
expect(format(`CREATE TABLE tbl (a INT, b TEXT) COMMENT = 'Hello, world!';`)).toBe(dedent`
CREATE TABLE
tbl (a INT, b TEXT) COMMENT = 'Hello, world!';
CREATE TABLE tbl (a INT, b TEXT) COMMENT = 'Hello, world!';
`);
});
}
Expand Down
3 changes: 1 addition & 2 deletions test/features/createView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ export default function supportsCreateView(
if (ifNotExists) {
it('formats short CREATE TABLE IF NOT EXISTS', () => {
expect(format('CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);')).toBe(dedent`
CREATE TABLE IF NOT EXISTS
tbl (a INT PRIMARY KEY, b TEXT);
CREATE TABLE IF NOT EXISTS tbl (a INT PRIMARY KEY, b TEXT);
`);
});
}
Expand Down
9 changes: 3 additions & 6 deletions test/options/dataTypeCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export default function supportsDataTypeCase(format: FormatFn) {
it('preserves data type keyword case by default', () => {
const result = format('CREATE TABLE users ( id iNt PRIMARY KEY )');
expect(result).toBe(dedent`
CREATE TABLE
users (id iNt PRIMARY KEY)
CREATE TABLE users (id iNt PRIMARY KEY)
`);
});

Expand All @@ -16,8 +15,7 @@ export default function supportsDataTypeCase(format: FormatFn) {
dataTypeCase: 'upper',
});
expect(result).toBe(dedent`
CREATE TABLE
users (id INT PRIMARY KEY)
CREATE TABLE users (id INT PRIMARY KEY)
`);
});

Expand All @@ -26,8 +24,7 @@ export default function supportsDataTypeCase(format: FormatFn) {
dataTypeCase: 'lower',
});
expect(result).toBe(dedent`
CREATE TABLE
users (id int PRIMARY KEY)
CREATE TABLE users (id int PRIMARY KEY)
`);
});

Expand Down
Loading

0 comments on commit 98b3816

Please sign in to comment.