From 84552f1db780fee60176aeb8d96ad3375491052a Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Tue, 30 Apr 2024 15:04:05 +1000 Subject: [PATCH 01/24] Setup DuckDB dialect --- src/languages/duckdb/duckdb.formatter.ts | 377 +++++++++++++ src/languages/duckdb/duckdb.functions.ts | 654 +++++++++++++++++++++++ src/languages/duckdb/duckdb.keywords.ts | 516 ++++++++++++++++++ 3 files changed, 1547 insertions(+) create mode 100644 src/languages/duckdb/duckdb.formatter.ts create mode 100644 src/languages/duckdb/duckdb.functions.ts create mode 100644 src/languages/duckdb/duckdb.keywords.ts diff --git a/src/languages/duckdb/duckdb.formatter.ts b/src/languages/duckdb/duckdb.formatter.ts new file mode 100644 index 0000000000..d2b0d9c8d0 --- /dev/null +++ b/src/languages/duckdb/duckdb.formatter.ts @@ -0,0 +1,377 @@ +import { DialectOptions } from '../../dialect.js'; +import { expandPhrases } from '../../expandPhrases.js'; +import { functions } from './duckdb.functions.js'; +import { dataTypes, keywords } from './duckdb.keywords.js'; + +const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT]']); + +const reservedClauses = expandPhrases([ + // queries + 'WITH [RECURSIVE]', + 'FROM', + 'WHERE', + 'GROUP BY [ALL | DISTINCT]', + 'HAVING', + 'WINDOW', + 'PARTITION BY', + 'ORDER BY', + 'LIMIT', + 'OFFSET', + 'FETCH {FIRST | NEXT}', + 'FOR {UPDATE | NO KEY UPDATE | SHARE | KEY SHARE} [OF]', + // Data manipulation + // - insert: + 'INSERT INTO', + 'VALUES', + 'DEFAULT VALUES', + // - update: + 'SET', + // other + 'RETURNING', +]); + +const standardOnelineClauses = expandPhrases([ + 'CREATE [GLOBAL | LOCAL] [TEMPORARY | TEMP | UNLOGGED] TABLE [IF NOT EXISTS]', +]); + +const tabularOnelineClauses = expandPhrases([ + // - create + 'CREATE [OR REPLACE] [TEMP | TEMPORARY] [RECURSIVE] VIEW', + 'CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]', + // - update: + 'UPDATE [ONLY]', + 'WHERE CURRENT OF', + // - insert: + 'ON CONFLICT', + // - delete: + 'DELETE FROM [ONLY]', + // - drop table: + 'DROP TABLE [IF EXISTS]', + // - alter table: + 'ALTER TABLE [IF EXISTS] [ONLY]', + 'ALTER TABLE ALL IN TABLESPACE', + 'RENAME [COLUMN]', + 'RENAME TO', + 'ADD [COLUMN] [IF NOT EXISTS]', + 'DROP [COLUMN] [IF EXISTS]', + 'ALTER [COLUMN]', + 'SET DATA TYPE', // for alter column + '{SET | DROP} DEFAULT', // for alter column + '{SET | DROP} NOT NULL', // for alter column + // - truncate: + 'TRUNCATE [TABLE] [ONLY]', + // other + 'SET SCHEMA', + 'AFTER', + // https://www.postgresql.org/docs/14/sql-commands.html + 'ABORT', + 'ALTER AGGREGATE', + 'ALTER COLLATION', + 'ALTER CONVERSION', + 'ALTER DATABASE', + 'ALTER DEFAULT PRIVILEGES', + 'ALTER DOMAIN', + 'ALTER EVENT TRIGGER', + 'ALTER EXTENSION', + 'ALTER FOREIGN DATA WRAPPER', + 'ALTER FOREIGN TABLE', + 'ALTER FUNCTION', + 'ALTER GROUP', + 'ALTER INDEX', + 'ALTER LANGUAGE', + 'ALTER LARGE OBJECT', + 'ALTER MATERIALIZED VIEW', + 'ALTER OPERATOR', + 'ALTER OPERATOR CLASS', + 'ALTER OPERATOR FAMILY', + 'ALTER POLICY', + 'ALTER PROCEDURE', + 'ALTER PUBLICATION', + 'ALTER ROLE', + 'ALTER ROUTINE', + 'ALTER RULE', + 'ALTER SCHEMA', + 'ALTER SEQUENCE', + 'ALTER SERVER', + 'ALTER STATISTICS', + 'ALTER SUBSCRIPTION', + 'ALTER SYSTEM', + 'ALTER TABLESPACE', + 'ALTER TEXT SEARCH CONFIGURATION', + 'ALTER TEXT SEARCH DICTIONARY', + 'ALTER TEXT SEARCH PARSER', + 'ALTER TEXT SEARCH TEMPLATE', + 'ALTER TRIGGER', + 'ALTER TYPE', + 'ALTER USER', + 'ALTER USER MAPPING', + 'ALTER VIEW', + 'ANALYZE', + 'BEGIN', + 'CALL', + 'CHECKPOINT', + 'CLOSE', + 'CLUSTER', + 'COMMIT', + 'COMMIT PREPARED', + 'COPY', + 'CREATE ACCESS METHOD', + 'CREATE AGGREGATE', + 'CREATE CAST', + 'CREATE COLLATION', + 'CREATE CONVERSION', + 'CREATE DATABASE', + 'CREATE DOMAIN', + 'CREATE EVENT TRIGGER', + 'CREATE EXTENSION', + 'CREATE FOREIGN DATA WRAPPER', + 'CREATE FOREIGN TABLE', + 'CREATE FUNCTION', + 'CREATE GROUP', + 'CREATE INDEX', + 'CREATE LANGUAGE', + 'CREATE OPERATOR', + 'CREATE OPERATOR CLASS', + 'CREATE OPERATOR FAMILY', + 'CREATE POLICY', + 'CREATE PROCEDURE', + 'CREATE PUBLICATION', + 'CREATE ROLE', + 'CREATE RULE', + 'CREATE SCHEMA', + 'CREATE SEQUENCE', + 'CREATE SERVER', + 'CREATE STATISTICS', + 'CREATE SUBSCRIPTION', + 'CREATE TABLESPACE', + 'CREATE TEXT SEARCH CONFIGURATION', + 'CREATE TEXT SEARCH DICTIONARY', + 'CREATE TEXT SEARCH PARSER', + 'CREATE TEXT SEARCH TEMPLATE', + 'CREATE TRANSFORM', + 'CREATE TRIGGER', + 'CREATE TYPE', + 'CREATE USER', + 'CREATE USER MAPPING', + 'DEALLOCATE', + 'DECLARE', + 'DISCARD', + 'DROP ACCESS METHOD', + 'DROP AGGREGATE', + 'DROP CAST', + 'DROP COLLATION', + 'DROP CONVERSION', + 'DROP DATABASE', + 'DROP DOMAIN', + 'DROP EVENT TRIGGER', + 'DROP EXTENSION', + 'DROP FOREIGN DATA WRAPPER', + 'DROP FOREIGN TABLE', + 'DROP FUNCTION', + 'DROP GROUP', + 'DROP INDEX', + 'DROP LANGUAGE', + 'DROP MATERIALIZED VIEW', + 'DROP OPERATOR', + 'DROP OPERATOR CLASS', + 'DROP OPERATOR FAMILY', + 'DROP OWNED', + 'DROP POLICY', + 'DROP PROCEDURE', + 'DROP PUBLICATION', + 'DROP ROLE', + 'DROP ROUTINE', + 'DROP RULE', + 'DROP SCHEMA', + 'DROP SEQUENCE', + 'DROP SERVER', + 'DROP STATISTICS', + 'DROP SUBSCRIPTION', + 'DROP TABLESPACE', + 'DROP TEXT SEARCH CONFIGURATION', + 'DROP TEXT SEARCH DICTIONARY', + 'DROP TEXT SEARCH PARSER', + 'DROP TEXT SEARCH TEMPLATE', + 'DROP TRANSFORM', + 'DROP TRIGGER', + 'DROP TYPE', + 'DROP USER', + 'DROP USER MAPPING', + 'DROP VIEW', + 'EXECUTE', + 'EXPLAIN', + 'FETCH', + 'GRANT', + 'IMPORT FOREIGN SCHEMA', + 'LISTEN', + 'LOAD', + 'LOCK', + 'MOVE', + 'NOTIFY', + 'PREPARE', + 'PREPARE TRANSACTION', + 'REASSIGN OWNED', + 'REFRESH MATERIALIZED VIEW', + 'REINDEX', + 'RELEASE SAVEPOINT', + 'RESET', + 'REVOKE', + 'ROLLBACK', + 'ROLLBACK PREPARED', + 'ROLLBACK TO SAVEPOINT', + 'SAVEPOINT', + 'SECURITY LABEL', + 'SELECT INTO', + 'SET CONSTRAINTS', + 'SET ROLE', + 'SET SESSION AUTHORIZATION', + 'SET TRANSACTION', + 'SHOW', + 'START TRANSACTION', + 'UNLISTEN', + 'VACUUM', +]); + +const reservedSetOperations = expandPhrases([ + 'UNION [ALL | DISTINCT]', + 'EXCEPT [ALL | DISTINCT]', + 'INTERSECT [ALL | DISTINCT]', +]); + +const reservedJoins = expandPhrases([ + 'JOIN', + '{LEFT | RIGHT | FULL} [OUTER] JOIN', + '{INNER | CROSS} JOIN', + 'NATURAL [INNER] JOIN', + 'NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN', +]); + +const reservedPhrases = expandPhrases([ + 'PRIMARY KEY', + 'GENERATED {ALWAYS | BY DEFAULT} AS IDENTITY', + 'ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]', + '{ROWS | RANGE | GROUPS} BETWEEN', + // https://www.postgresql.org/docs/current/datatype-datetime.html + '[TIMESTAMP | TIME] {WITH | WITHOUT} TIME ZONE', + // comparison operator + 'IS [NOT] DISTINCT FROM', +]); + +// https://www.postgresql.org/docs/14/index.html +export const postgresql: DialectOptions = { + name: 'postgresql', + tokenizerOptions: { + reservedSelect, + reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], + reservedSetOperations, + reservedJoins, + reservedPhrases, + reservedKeywords: keywords, + reservedDataTypes: dataTypes, + reservedFunctionNames: functions, + nestedBlockComments: true, + extraParens: ['[]'], + stringTypes: [ + '$$', + { quote: "''-qq", prefixes: ['U&'] }, + { quote: "''-qq-bs", prefixes: ['E'], requirePrefix: true }, + { quote: "''-raw", prefixes: ['B', 'X'], requirePrefix: true }, + ], + identTypes: [{ quote: '""-qq', prefixes: ['U&'] }], + identChars: { rest: '$' }, + paramTypes: { numbered: ['$'] }, + operators: [ + // Arithmetic + '%', + '^', + '|/', + '||/', + '@', + // Assignment + ':=', + // Bitwise + '&', + '|', + '#', + '~', + '<<', + '>>', + // Byte comparison + '~>~', + '~<~', + '~>=~', + '~<=~', + // Geometric + '@-@', + '@@', + '##', + '<->', + '&&', + '&<', + '&>', + '<<|', + '&<|', + '|>>', + '|&>', + '<^', + '^>', + '?#', + '?-', + '?|', + '?-|', + '?||', + '@>', + '<@', + '~=', + // JSON + '?', + '@?', + '?&', + '->', + '->>', + '#>', + '#>>', + '#-', + // Named function params + '=>', + // Network address + '>>=', + '<<=', + // Pattern matching + '~~', + '~~*', + '!~~', + '!~~*', + // POSIX RegExp + '~', + '~*', + '!~', + '!~*', + // Range/multirange + '-|-', + // String concatenation + '||', + // Text search + '@@@', + '!!', + '^@', + // Trigram/trigraph + '<%', + '%>', + '<<%', + '%>>', + '<<->', + '<->>', + '<<<->', + '<->>>', + // Type cast + '::', + ':', + ], + }, + formatOptions: { + alwaysDenseOperators: ['::', ':'], + onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses], + tabularOnelineClauses, + }, +}; diff --git a/src/languages/duckdb/duckdb.functions.ts b/src/languages/duckdb/duckdb.functions.ts new file mode 100644 index 0000000000..7a3bbe5756 --- /dev/null +++ b/src/languages/duckdb/duckdb.functions.ts @@ -0,0 +1,654 @@ +export const functions: string[] = [ + 'ABS', + 'ACOS', + 'ADD', + 'ADD_PARQUET_KEY', + 'AGE', + 'AGGREGATE', + 'ALIAS', + 'ALL_PROFILING_OUTPUT', + 'ANY_VALUE', + 'APPLY', + 'APPROX_COUNT_DISTINCT', + 'APPROX_QUANTILE', + 'ARBITRARY', + 'ARGMAX', + 'ARGMIN', + 'ARG_MAX', + 'ARG_MAX_NULL', + 'ARG_MIN', + 'ARG_MIN_NULL', + 'ARRAY_AGG', + 'ARRAY_AGGR', + 'ARRAY_AGGREGATE', + 'ARRAY_APPEND', + 'ARRAY_APPLY', + 'ARRAY_CAT', + 'ARRAY_CONCAT', + 'ARRAY_CONTAINS', + 'ARRAY_COSINE_SIMILARITY', + 'ARRAY_CROSS_PRODUCT', + 'ARRAY_DISTANCE', + 'ARRAY_DISTINCT', + 'ARRAY_DOT_PRODUCT', + 'ARRAY_EXTRACT', + 'ARRAY_FILTER', + 'ARRAY_GRADE_UP', + 'ARRAY_HAS', + 'ARRAY_HAS_ALL', + 'ARRAY_HAS_ANY', + 'ARRAY_INDEXOF', + 'ARRAY_INNER_PRODUCT', + 'ARRAY_INTERSECT', + 'ARRAY_LENGTH', + 'ARRAY_POP_BACK', + 'ARRAY_POP_FRONT', + 'ARRAY_POSITION', + 'ARRAY_PREPEND', + 'ARRAY_PUSH_BACK', + 'ARRAY_PUSH_FRONT', + 'ARRAY_REDUCE', + 'ARRAY_RESIZE', + 'ARRAY_REVERSE', + 'ARRAY_REVERSE_SORT', + 'ARRAY_SELECT', + 'ARRAY_SLICE', + 'ARRAY_SORT', + 'ARRAY_TO_JSON', + 'ARRAY_TO_STRING', + 'ARRAY_TRANSFORM', + 'ARRAY_UNIQUE', + 'ARRAY_VALUE', + 'ARRAY_WHERE', + 'ARRAY_ZIP', + 'ARROW_SCAN', + 'ARROW_SCAN_DUMB', + 'ASCII', + 'ASIN', + 'ATAN', + 'ATAN2', + 'AVG', + 'BAR', + 'BASE64', + 'BIN', + 'BITSTRING', + 'BITSTRING_AGG', + 'BIT_AND', + 'BIT_COUNT', + 'BIT_LENGTH', + 'BIT_OR', + 'BIT_POSITION', + 'BIT_XOR', + 'BOOL_AND', + 'BOOL_OR', + 'CARDINALITY', + 'CBRT', + 'CEIL', + 'CEILING', + 'CENTURY', + 'CHECKPOINT', + 'CHR', + 'COLLATIONS', + 'COL_DESCRIPTION', + 'COMBINE', + 'CONCAT', + 'CONCAT_WS', + 'CONSTANT_OR_NULL', + 'CONTAINS', + 'COPY_DATABASE', + 'CORR', + 'COS', + 'COT', + 'COUNT', + 'COUNT_IF', + 'COUNT_STAR', + 'COVAR_POP', + 'COVAR_SAMP', + 'CREATE_SORT_KEY', + 'CURRENT_CATALOG', + 'CURRENT_DATABASE', + 'CURRENT_DATE', + 'CURRENT_LOCALTIME', + 'CURRENT_LOCALTIMESTAMP', + 'CURRENT_QUERY', + 'CURRENT_ROLE', + 'CURRENT_SCHEMA', + 'CURRENT_SCHEMAS', + 'CURRENT_SETTING', + 'CURRENT_USER', + 'CURRVAL', + 'DAMERAU_LEVENSHTEIN', + 'DATABASE_LIST', + 'DATABASE_SIZE', + 'DATEDIFF', + 'DATEPART', + 'DATESUB', + 'DATETRUNC', + 'DATE_ADD', + 'DATE_DIFF', + 'DATE_PART', + 'DATE_SUB', + 'DATE_TRUNC', + 'DAY', + 'DAYNAME', + 'DAYOFMONTH', + 'DAYOFWEEK', + 'DAYOFYEAR', + 'DECADE', + 'DECODE', + 'DEGREES', + 'DISABLE_CHECKPOINT_ON_SHUTDOWN', + 'DISABLE_OBJECT_CACHE', + 'DISABLE_OPTIMIZER', + 'DISABLE_PRINT_PROGRESS_BAR', + 'DISABLE_PROFILE', + 'DISABLE_PROFILING', + 'DISABLE_PROGRESS_BAR', + 'DISABLE_VERIFICATION', + 'DISABLE_VERIFY_EXTERNAL', + 'DISABLE_VERIFY_FETCH_ROW', + 'DISABLE_VERIFY_PARALLELISM', + 'DISABLE_VERIFY_SERIALIZER', + 'DIVIDE', + 'DUCKDB_COLUMNS', + 'DUCKDB_CONSTRAINTS', + 'DUCKDB_DATABASES', + 'DUCKDB_DEPENDENCIES', + 'DUCKDB_EXTENSIONS', + 'DUCKDB_FUNCTIONS', + 'DUCKDB_INDEXES', + 'DUCKDB_KEYWORDS', + 'DUCKDB_MEMORY', + 'DUCKDB_OPTIMIZERS', + 'DUCKDB_SCHEMAS', + 'DUCKDB_SECRETS', + 'DUCKDB_SEQUENCES', + 'DUCKDB_SETTINGS', + 'DUCKDB_TABLES', + 'DUCKDB_TEMPORARY_FILES', + 'DUCKDB_TYPES', + 'DUCKDB_VIEWS', + 'EDIT', + 'EDITDIST3', + 'ELEMENT_AT', + 'ENABLE_CHECKPOINT_ON_SHUTDOWN', + 'ENABLE_OBJECT_CACHE', + 'ENABLE_OPTIMIZER', + 'ENABLE_PRINT_PROGRESS_BAR', + 'ENABLE_PROFILE', + 'ENABLE_PROFILING', + 'ENABLE_PROGRESS_BAR', + 'ENABLE_VERIFICATION', + 'ENCODE', + 'ENDS_WITH', + 'ENTROPY', + 'ENUM_CODE', + 'ENUM_FIRST', + 'ENUM_LAST', + 'ENUM_RANGE', + 'ENUM_RANGE_BOUNDARY', + 'EPOCH', + 'EPOCH_MS', + 'EPOCH_NS', + 'EPOCH_US', + 'ERA', + 'ERROR', + 'EVEN', + 'EXP', + 'FACTORIAL', + 'FAVG', + 'FDIV', + 'FILTER', + 'FINALIZE', + 'FIRST', + 'FLATTEN', + 'FLOOR', + 'FMOD', + 'FORCE_CHECKPOINT', + 'FORMAT', + 'FORMATREADABLEDECIMALSIZE', + 'FORMATREADABLESIZE', + 'FORMAT_BYTES', + 'FORMAT_PG_TYPE', + 'FORMAT_TYPE', + 'FROM_BASE64', + 'FROM_BINARY', + 'FROM_HEX', + 'FROM_JSON', + 'FROM_JSON_STRICT', + 'FSUM', + 'FUNCTIONS', + 'GAMMA', + 'GCD', + 'GENERATE_SERIES', + 'GENERATE_SUBSCRIPTS', + 'GEN_RANDOM_UUID', + 'GEOMEAN', + 'GEOMETRIC_MEAN', + 'GETENV', + 'GET_BIT', + 'GET_BLOCK_SIZE', + 'GET_CURRENT_TIME', + 'GET_CURRENT_TIMESTAMP', + 'GLOB', + 'GRADE_UP', + 'GREATEST', + 'GREATEST_COMMON_DIVISOR', + 'GROUP_CONCAT', + 'HAMMING', + 'HASH', + 'HAS_ANY_COLUMN_PRIVILEGE', + 'HAS_COLUMN_PRIVILEGE', + 'HAS_DATABASE_PRIVILEGE', + 'HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE', + 'HAS_FUNCTION_PRIVILEGE', + 'HAS_LANGUAGE_PRIVILEGE', + 'HAS_SCHEMA_PRIVILEGE', + 'HAS_SEQUENCE_PRIVILEGE', + 'HAS_SERVER_PRIVILEGE', + 'HAS_TABLESPACE_PRIVILEGE', + 'HAS_TABLE_PRIVILEGE', + 'HEX', + 'HISTOGRAM', + 'HOUR', + 'ICU_CALENDAR_NAMES', + 'ICU_SORT_KEY', + 'ILIKE_ESCAPE', + 'IMPORT_DATABASE', + 'INDEX_SCAN', + 'INET_CLIENT_ADDR', + 'INET_CLIENT_PORT', + 'INET_SERVER_ADDR', + 'INET_SERVER_PORT', + 'INSTR', + 'IN_SEARCH_PATH', + 'ISFINITE', + 'ISINF', + 'ISNAN', + 'ISODOW', + 'ISOYEAR', + 'JACCARD', + 'JARO_SIMILARITY', + 'JARO_WINKLER_SIMILARITY', + 'JSON', + 'JSON_ARRAY', + 'JSON_ARRAY_LENGTH', + 'JSON_CONTAINS', + 'JSON_DESERIALIZE_SQL', + 'JSON_EXECUTE_SERIALIZED_SQL', + 'JSON_EXTRACT', + 'JSON_EXTRACT_PATH', + 'JSON_EXTRACT_PATH_TEXT', + 'JSON_EXTRACT_STRING', + 'JSON_GROUP_ARRAY', + 'JSON_GROUP_OBJECT', + 'JSON_GROUP_STRUCTURE', + 'JSON_KEYS', + 'JSON_MERGE_PATCH', + 'JSON_OBJECT', + 'JSON_QUOTE', + 'JSON_SERIALIZE_PLAN', + 'JSON_SERIALIZE_SQL', + 'JSON_STRUCTURE', + 'JSON_TRANSFORM', + 'JSON_TRANSFORM_STRICT', + 'JSON_TYPE', + 'JSON_VALID', + 'JULIAN', + 'KAHAN_SUM', + 'KURTOSIS', + 'KURTOSIS_POP', + 'LAST', + 'LAST_DAY', + 'LCASE', + 'LCM', + 'LEAST', + 'LEAST_COMMON_MULTIPLE', + 'LEFT', + 'LEFT_GRAPHEME', + 'LEN', + 'LENGTH', + 'LENGTH_GRAPHEME', + 'LEVENSHTEIN', + 'LGAMMA', + 'LIKE_ESCAPE', + 'LIST', + 'LISTAGG', + 'LIST_AGGR', + 'LIST_AGGREGATE', + 'LIST_ANY_VALUE', + 'LIST_APPEND', + 'LIST_APPLY', + 'LIST_APPROX_COUNT_DISTINCT', + 'LIST_AVG', + 'LIST_BIT_AND', + 'LIST_BIT_OR', + 'LIST_BIT_XOR', + 'LIST_BOOL_AND', + 'LIST_BOOL_OR', + 'LIST_CAT', + 'LIST_CONCAT', + 'LIST_CONTAINS', + 'LIST_COSINE_SIMILARITY', + 'LIST_COUNT', + 'LIST_DISTANCE', + 'LIST_DISTINCT', + 'LIST_DOT_PRODUCT', + 'LIST_ELEMENT', + 'LIST_ENTROPY', + 'LIST_EXTRACT', + 'LIST_FILTER', + 'LIST_FIRST', + 'LIST_GRADE_UP', + 'LIST_HAS', + 'LIST_HAS_ALL', + 'LIST_HAS_ANY', + 'LIST_HISTOGRAM', + 'LIST_INDEXOF', + 'LIST_INNER_PRODUCT', + 'LIST_INTERSECT', + 'LIST_KURTOSIS', + 'LIST_KURTOSIS_POP', + 'LIST_LAST', + 'LIST_MAD', + 'LIST_MAX', + 'LIST_MEDIAN', + 'LIST_MIN', + 'LIST_MODE', + 'LIST_PACK', + 'LIST_POSITION', + 'LIST_PREPEND', + 'LIST_PRODUCT', + 'LIST_REDUCE', + 'LIST_RESIZE', + 'LIST_REVERSE', + 'LIST_REVERSE_SORT', + 'LIST_SELECT', + 'LIST_SEM', + 'LIST_SKEWNESS', + 'LIST_SLICE', + 'LIST_SORT', + 'LIST_STDDEV_POP', + 'LIST_STDDEV_SAMP', + 'LIST_STRING_AGG', + 'LIST_SUM', + 'LIST_TRANSFORM', + 'LIST_UNIQUE', + 'LIST_VALUE', + 'LIST_VAR_POP', + 'LIST_VAR_SAMP', + 'LIST_WHERE', + 'LIST_ZIP', + 'LN', + 'LOG', + 'LOG10', + 'LOG2', + 'LOWER', + 'LPAD', + 'LSMODE', + 'LTRIM', + 'MAD', + 'MAKE_DATE', + 'MAKE_TIME', + 'MAKE_TIMESTAMP', + 'MAKE_TIMESTAMPTZ', + 'MAP', + 'MAP_CONCAT', + 'MAP_ENTRIES', + 'MAP_EXTRACT', + 'MAP_FROM_ENTRIES', + 'MAP_KEYS', + 'MAP_VALUES', + 'MAX', + 'MAX_BY', + 'MD5', + 'MD5_NUMBER', + 'MD5_NUMBER_LOWER', + 'MD5_NUMBER_UPPER', + 'MEAN', + 'MEDIAN', + 'METADATA_INFO', + 'MICROSECOND', + 'MILLENNIUM', + 'MILLISECOND', + 'MIN', + 'MINUTE', + 'MIN_BY', + 'MISMATCHES', + 'MOD', + 'MODE', + 'MONTH', + 'MONTHNAME', + 'MULTIPLY', + 'NEXTAFTER', + 'NEXTVAL', + 'NFC_NORMALIZE', + 'NOT_ILIKE_ESCAPE', + 'NOT_LIKE_ESCAPE', + 'NOW', + 'NULLIF', + 'OBJ_DESCRIPTION', + 'OCTET_LENGTH', + 'ORD', + 'PARQUET_FILE_METADATA', + 'PARQUET_KV_METADATA', + 'PARQUET_METADATA', + 'PARQUET_SCAN', + 'PARQUET_SCHEMA', + 'PARSE_DIRNAME', + 'PARSE_DIRPATH', + 'PARSE_FILENAME', + 'PARSE_PATH', + 'PG_COLLATION_IS_VISIBLE', + 'PG_CONF_LOAD_TIME', + 'PG_CONVERSION_IS_VISIBLE', + 'PG_FUNCTION_IS_VISIBLE', + 'PG_GET_CONSTRAINTDEF', + 'PG_GET_EXPR', + 'PG_GET_VIEWDEF', + 'PG_HAS_ROLE', + 'PG_IS_OTHER_TEMP_SCHEMA', + 'PG_MY_TEMP_SCHEMA', + 'PG_OPCLASS_IS_VISIBLE', + 'PG_OPERATOR_IS_VISIBLE', + 'PG_OPFAMILY_IS_VISIBLE', + 'PG_POSTMASTER_START_TIME', + 'PG_SIZE_PRETTY', + 'PG_TABLE_IS_VISIBLE', + 'PG_TIMEZONE_NAMES', + 'PG_TS_CONFIG_IS_VISIBLE', + 'PG_TS_DICT_IS_VISIBLE', + 'PG_TS_PARSER_IS_VISIBLE', + 'PG_TS_TEMPLATE_IS_VISIBLE', + 'PG_TYPEOF', + 'PG_TYPE_IS_VISIBLE', + 'PI', + 'PLATFORM', + 'POSITION', + 'POW', + 'POWER', + 'PRAGMA_COLLATIONS', + 'PRAGMA_DATABASE_SIZE', + 'PRAGMA_METADATA_INFO', + 'PRAGMA_PLATFORM', + 'PRAGMA_SHOW', + 'PRAGMA_STORAGE_INFO', + 'PRAGMA_TABLE_INFO', + 'PRAGMA_USER_AGENT', + 'PRAGMA_VERSION', + 'PREFIX', + 'PRINTF', + 'PRODUCT', + 'QUANTILE', + 'QUANTILE_CONT', + 'QUANTILE_DISC', + 'QUARTER', + 'RADIANS', + 'RANDOM', + 'RANGE', + 'READFILE', + 'READ_BLOB', + 'READ_CSV', + 'READ_CSV_AUTO', + 'READ_JSON', + 'READ_JSON_AUTO', + 'READ_JSON_OBJECTS', + 'READ_JSON_OBJECTS_AUTO', + 'READ_NDJSON', + 'READ_NDJSON_AUTO', + 'READ_NDJSON_OBJECTS', + 'READ_PARQUET', + 'READ_TEXT', + 'REDUCE', + 'REGEXP_ESCAPE', + 'REGEXP_EXTRACT', + 'REGEXP_EXTRACT_ALL', + 'REGEXP_FULL_MATCH', + 'REGEXP_MATCHES', + 'REGEXP_REPLACE', + 'REGEXP_SPLIT_TO_ARRAY', + 'REGEXP_SPLIT_TO_TABLE', + 'REGR_AVGX', + 'REGR_AVGY', + 'REGR_COUNT', + 'REGR_INTERCEPT', + 'REGR_R2', + 'REGR_SLOPE', + 'REGR_SXX', + 'REGR_SXY', + 'REGR_SYY', + 'REPEAT', + 'REPEAT_ROW', + 'REPLACE', + 'RESERVOIR_QUANTILE', + 'REVERSE', + 'RIGHT', + 'RIGHT_GRAPHEME', + 'ROUND', + 'ROUNDBANKERS', + 'ROUND_EVEN', + 'ROW', + 'ROW_TO_JSON', + 'RPAD', + 'RTRIM', + 'SECOND', + 'SEM', + 'SEQ_SCAN', + 'SESSION_USER', + 'SETSEED', + 'SET_BIT', + 'SHA256', + 'SHA3', + 'SHELL_ADD_SCHEMA', + 'SHELL_ESCAPE_CRNL', + 'SHELL_IDQUOTE', + 'SHELL_MODULE_SCHEMA', + 'SHELL_PUTSNL', + 'SHOBJ_DESCRIPTION', + 'SHOW', + 'SHOW_DATABASES', + 'SHOW_TABLES', + 'SHOW_TABLES_EXPANDED', + 'SIGN', + 'SIGNBIT', + 'SIN', + 'SKEWNESS', + 'SNIFF_CSV', + 'SPLIT', + 'SPLIT_PART', + 'SQL_AUTO_COMPLETE', + 'SQRT', + 'STARTS_WITH', + 'STATS', + 'STDDEV', + 'STDDEV_POP', + 'STDDEV_SAMP', + 'STORAGE_INFO', + 'STRFTIME', + 'STRING_AGG', + 'STRING_SPLIT', + 'STRING_SPLIT_REGEX', + 'STRING_TO_ARRAY', + 'STRIP_ACCENTS', + 'STRLEN', + 'STRPOS', + 'STRPTIME', + 'STRUCT_EXTRACT', + 'STRUCT_INSERT', + 'STRUCT_PACK', + 'STR_SPLIT', + 'STR_SPLIT_REGEX', + 'SUBSTR', + 'SUBSTRING', + 'SUBSTRING_GRAPHEME', + 'SUBTRACT', + 'SUFFIX', + 'SUM', + 'SUMKAHAN', + 'SUMMARY', + 'SUM_NO_OVERFLOW', + 'TABLE_INFO', + 'TAN', + 'TEST_ALL_TYPES', + 'TEST_VECTOR_TYPES', + 'TIMEZONE', + 'TIMEZONE_HOUR', + 'TIMEZONE_MINUTE', + 'TIME_BUCKET', + 'TODAY', + 'TO_BASE', + 'TO_BASE64', + 'TO_BINARY', + 'TO_CENTURIES', + 'TO_DAYS', + 'TO_DECADES', + 'TO_HEX', + 'TO_HOURS', + 'TO_JSON', + 'TO_MICROSECONDS', + 'TO_MILLENNIA', + 'TO_MILLISECONDS', + 'TO_MINUTES', + 'TO_MONTHS', + 'TO_SECONDS', + 'TO_TIMESTAMP', + 'TO_WEEKS', + 'TO_YEARS', + 'TRANSACTION_TIMESTAMP', + 'TRANSLATE', + 'TRIM', + 'TRUNC', + 'TRY_STRPTIME', + 'TXID_CURRENT', + 'TYPEOF', + 'UCASE', + 'UNBIN', + 'UNHEX', + 'UNICODE', + 'UNION_EXTRACT', + 'UNION_TAG', + 'UNION_VALUE', + 'UNNEST', + 'UNPIVOT_LIST', + 'UPPER', + 'USER', + 'USER_AGENT', + 'UUID', + 'VARIANCE', + 'VAR_POP', + 'VAR_SAMP', + 'VECTOR_TYPE', + 'VERIFY_EXTERNAL', + 'VERIFY_FETCH_ROW', + 'VERIFY_PARALLELISM', + 'VERIFY_SERIALIZER', + 'VERSION', + 'WEEK', + 'WEEKDAY', + 'WEEKOFYEAR', + 'WHICH_SECRET', + 'WRITEFILE', + 'XOR', + 'YEAR', + 'YEARWEEK', +]; diff --git a/src/languages/duckdb/duckdb.keywords.ts b/src/languages/duckdb/duckdb.keywords.ts new file mode 100644 index 0000000000..1e113eead2 --- /dev/null +++ b/src/languages/duckdb/duckdb.keywords.ts @@ -0,0 +1,516 @@ +export const keywords: string[] = [ + 'ABORT', + 'ABSOLUTE', + 'ACCESS', + 'ACTION', + 'ADD', + 'ADMIN', + 'AFTER', + 'AGGREGATE', + 'ALL', + 'ALSO', + 'ALTER', + 'ALWAYS', + 'ANALYSE', + 'ANALYZE', + 'AND', + 'ANTI', + 'ANY', + 'ARRAY', + 'AS', + 'ASC', + 'ASOF', + 'ASSERTION', + 'ASSIGNMENT', + 'ASYMMETRIC', + 'AT', + 'ATTACH', + 'ATTRIBUTE', + 'AUTHORIZATION', + 'BACKWARD', + 'BEFORE', + 'BEGIN', + 'BETWEEN', + 'BIGINT', + 'BINARY', + 'BIT', + 'BOOLEAN', + 'BOTH', + 'BY', + 'CACHE', + 'CALL', + 'CALLED', + 'CASCADE', + 'CASCADED', + 'CASE', + 'CAST', + 'CATALOG', + 'CENTURIES', + 'CENTURY', + 'CHAIN', + 'CHAR', + 'CHARACTER', + 'CHARACTERISTICS', + 'CHECK', + 'CHECKPOINT', + 'CLASS', + 'CLOSE', + 'CLUSTER', + 'COALESCE', + 'COLLATE', + 'COLLATION', + 'COLUMN', + 'COLUMNS', + 'COMMENT', + 'COMMENTS', + 'COMMIT', + 'COMMITTED', + 'COMPRESSION', + 'CONCURRENTLY', + 'CONFIGURATION', + 'CONFLICT', + 'CONNECTION', + 'CONSTRAINT', + 'CONSTRAINTS', + 'CONTENT', + 'CONTINUE', + 'CONVERSION', + 'COPY', + 'COST', + 'CREATE', + 'CROSS', + 'CSV', + 'CUBE', + 'CURRENT', + 'CURSOR', + 'CYCLE', + 'DATA', + 'DATABASE', + 'DAY', + 'DAYS', + 'DEALLOCATE', + 'DEC', + 'DECADE', + 'DECADES', + 'DECIMAL', + 'DECLARE', + 'DEFAULT', + 'DEFAULTS', + 'DEFERRABLE', + 'DEFERRED', + 'DEFINER', + 'DELETE', + 'DELIMITER', + 'DELIMITERS', + 'DEPENDS', + 'DESC', + 'DESCRIBE', + 'DETACH', + 'DICTIONARY', + 'DISABLE', + 'DISCARD', + 'DISTINCT', + 'DO', + 'DOCUMENT', + 'DOMAIN', + 'DOUBLE', + 'DROP', + 'EACH', + 'ELSE', + 'ENABLE', + 'ENCODING', + 'ENCRYPTED', + 'END', + 'ENUM', + 'ESCAPE', + 'EVENT', + 'EXCEPT', + 'EXCLUDE', + 'EXCLUDING', + 'EXCLUSIVE', + 'EXECUTE', + 'EXISTS', + 'EXPLAIN', + 'EXPORT', + 'EXPORT_STATE', + 'EXTENSION', + 'EXTERNAL', + 'EXTRACT', + 'FALSE', + 'FAMILY', + 'FETCH', + 'FILTER', + 'FIRST', + 'FLOAT', + 'FOLLOWING', + 'FOR', + 'FORCE', + 'FOREIGN', + 'FORWARD', + 'FREEZE', + 'FROM', + 'FULL', + 'FUNCTION', + 'FUNCTIONS', + 'GENERATED', + 'GLOB', + 'GLOBAL', + 'GRANT', + 'GRANTED', + 'GROUP', + 'GROUPING', + 'GROUPING_ID', + 'GROUPS', + 'HANDLER', + 'HAVING', + 'HEADER', + 'HOLD', + 'HOUR', + 'HOURS', + 'IDENTITY', + 'IF', + 'IGNORE', + 'ILIKE', + 'IMMEDIATE', + 'IMMUTABLE', + 'IMPLICIT', + 'IMPORT', + 'IN', + 'INCLUDE', + 'INCLUDING', + 'INCREMENT', + 'INDEX', + 'INDEXES', + 'INHERIT', + 'INHERITS', + 'INITIALLY', + 'INLINE', + 'INNER', + 'INOUT', + 'INPUT', + 'INSENSITIVE', + 'INSERT', + 'INSTALL', + 'INSTEAD', + 'INT', + 'INTEGER', + 'INTERSECT', + 'INTERVAL', + 'INTO', + 'INVOKER', + 'IS', + 'ISNULL', + 'ISOLATION', + 'JOIN', + 'JSON', + 'KEY', + 'LABEL', + 'LANGUAGE', + 'LARGE', + 'LAST', + 'LATERAL', + 'LEADING', + 'LEAKPROOF', + 'LEFT', + 'LEVEL', + 'LIKE', + 'LIMIT', + 'LISTEN', + 'LOAD', + 'LOCAL', + 'LOCATION', + 'LOCK', + 'LOCKED', + 'LOGGED', + 'MACRO', + 'MAP', + 'MAPPING', + 'MATCH', + 'MATERIALIZED', + 'MAXVALUE', + 'METHOD', + 'MICROSECOND', + 'MICROSECONDS', + 'MILLENNIA', + 'MILLENNIUM', + 'MILLISECOND', + 'MILLISECONDS', + 'MINUTE', + 'MINUTES', + 'MINVALUE', + 'MODE', + 'MONTH', + 'MONTHS', + 'MOVE', + 'NAME', + 'NAMES', + 'NATIONAL', + 'NATURAL', + 'NCHAR', + 'NEW', + 'NEXT', + 'NO', + 'NONE', + 'NOT', + 'NOTHING', + 'NOTIFY', + 'NOTNULL', + 'NOWAIT', + 'NULL', + 'NULLIF', + 'NULLS', + 'NUMERIC', + 'OBJECT', + 'OF', + 'OFF', + 'OFFSET', + 'OIDS', + 'OLD', + 'ON', + 'ONLY', + 'OPERATOR', + 'OPTION', + 'OPTIONS', + 'OR', + 'ORDER', + 'ORDINALITY', + 'OTHERS', + 'OUT', + 'OUTER', + 'OVER', + 'OVERLAPS', + 'OVERLAY', + 'OVERRIDING', + 'OWNED', + 'OWNER', + 'PARALLEL', + 'PARSER', + 'PARTIAL', + 'PARTITION', + 'PASSING', + 'PASSWORD', + 'PERCENT', + 'PERSISTENT', + 'PIVOT', + 'PIVOT_LONGER', + 'PIVOT_WIDER', + 'PLACING', + 'PLANS', + 'POLICY', + 'POSITION', + 'POSITIONAL', + 'PRAGMA', + 'PRECEDING', + 'PRECISION', + 'PREPARE', + 'PREPARED', + 'PRESERVE', + 'PRIMARY', + 'PRIOR', + 'PRIVILEGES', + 'PROCEDURAL', + 'PROCEDURE', + 'PROGRAM', + 'PUBLICATION', + 'QUALIFY', + 'QUOTE', + 'RANGE', + 'READ', + 'REAL', + 'REASSIGN', + 'RECHECK', + 'RECURSIVE', + 'REF', + 'REFERENCES', + 'REFERENCING', + 'REFRESH', + 'REINDEX', + 'RELATIVE', + 'RELEASE', + 'RENAME', + 'REPEATABLE', + 'REPLACE', + 'REPLICA', + 'RESET', + 'RESPECT', + 'RESTART', + 'RESTRICT', + 'RETURNING', + 'RETURNS', + 'REVOKE', + 'RIGHT', + 'ROLE', + 'ROLLBACK', + 'ROLLUP', + 'ROW', + 'ROWS', + 'RULE', + 'SAMPLE', + 'SAVEPOINT', + 'SCHEMA', + 'SCHEMAS', + 'SCOPE', + 'SCROLL', + 'SEARCH', + 'SECOND', + 'SECONDS', + 'SECRET', + 'SECURITY', + 'SELECT', + 'SEMI', + 'SEQUENCE', + 'SEQUENCES', + 'SERIALIZABLE', + 'SERVER', + 'SESSION', + 'SET', + 'SETOF', + 'SETS', + 'SHARE', + 'SHOW', + 'SIMILAR', + 'SIMPLE', + 'SKIP', + 'SMALLINT', + 'SNAPSHOT', + 'SOME', + 'SQL', + 'STABLE', + 'STANDALONE', + 'START', + 'STATEMENT', + 'STATISTICS', + 'STDIN', + 'STDOUT', + 'STORAGE', + 'STORED', + 'STRICT', + 'STRIP', + 'STRUCT', + 'SUBSCRIPTION', + 'SUBSTRING', + 'SUMMARIZE', + 'SYMMETRIC', + 'SYSID', + 'SYSTEM', + 'TABLE', + 'TABLES', + 'TABLESAMPLE', + 'TABLESPACE', + 'TEMP', + 'TEMPLATE', + 'TEMPORARY', + 'TEXT', + 'THEN', + 'TIES', + 'TIME', + 'TIMESTAMP', + 'TO', + 'TRAILING', + 'TRANSACTION', + 'TRANSFORM', + 'TREAT', + 'TRIGGER', + 'TRIM', + 'TRUE', + 'TRUNCATE', + 'TRUSTED', + 'TRY_CAST', + 'TYPE', + 'TYPES', + 'UNBOUNDED', + 'UNCOMMITTED', + 'UNENCRYPTED', + 'UNION', + 'UNIQUE', + 'UNKNOWN', + 'UNLISTEN', + 'UNLOGGED', + 'UNPIVOT', + 'UNTIL', + 'UPDATE', + 'USE', + 'USER', + 'USING', + 'VACUUM', + 'VALID', + 'VALIDATE', + 'VALIDATOR', + 'VALUE', + 'VALUES', + 'VARCHAR', + 'VARIADIC', + 'VARYING', + 'VERBOSE', + 'VERSION', + 'VIEW', + 'VIEWS', + 'VIRTUAL', + 'VOLATILE', + 'WEEK', + 'WEEKS', + 'WHEN', + 'WHERE', + 'WHITESPACE', + 'WINDOW', + 'WITH', + 'WITHIN', + 'WITHOUT', + 'WORK', + 'WRAPPER', + 'WRITE', + 'XML', + 'XMLATTRIBUTES', + 'XMLCONCAT', + 'XMLELEMENT', + 'XMLEXISTS', + 'XMLFOREST', + 'XMLNAMESPACES', + 'XMLPARSE', + 'XMLPI', + 'XMLROOT', + 'XMLSERIALIZE', + 'XMLTABLE', + 'YEAR', + 'YEARS', + 'YES', + 'ZONE', + +]; + +export const dataTypes: string[] = [ + 'BIGINT', + 'BIT', + 'BLOB', + 'BOOLEAN', + 'DATE', + 'DECIMAL', + 'DOUBLE', + 'ENUM', + 'FLOAT', + 'HUGEINT', + 'INTEGER', + 'INTERVAL', + 'LIST', + 'MAP', + 'NULL', + 'SMALLINT', + 'STRUCT', + 'TIME', + 'TIME WITH TIME ZONE', + 'TIMESTAMP', + 'TIMESTAMP WITH TIME ZONE', + 'TIMESTAMP_MS', + 'TIMESTAMP_NS', + 'TIMESTAMP_S', + 'TINYINT', + 'UBIGINT', + 'UHUGEINT', + 'UINTEGER', + 'UNION', + 'USMALLINT', + 'UTINYINT', + 'UUID', + 'VARCHAR', + +]; From 9001e8cb7ae2e50c75da85f890431f3a7db777bc Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Tue, 30 Apr 2024 15:05:02 +1000 Subject: [PATCH 02/24] Generate DuckDB words --- duckdb_functions.txt | 652 +++++++++++++++++++++++++++++++++++++++++++ duckdb_keywords.txt | 476 +++++++++++++++++++++++++++++++ duckdb_types.txt | 33 +++ duckdb_words.sql | 20 ++ 4 files changed, 1181 insertions(+) create mode 100644 duckdb_functions.txt create mode 100644 duckdb_keywords.txt create mode 100644 duckdb_types.txt create mode 100644 duckdb_words.sql diff --git a/duckdb_functions.txt b/duckdb_functions.txt new file mode 100644 index 0000000000..d3e82941ca --- /dev/null +++ b/duckdb_functions.txt @@ -0,0 +1,652 @@ +ABS +ACOS +ADD +ADD_PARQUET_KEY +AGE +AGGREGATE +ALIAS +ALL_PROFILING_OUTPUT +ANY_VALUE +APPLY +APPROX_COUNT_DISTINCT +APPROX_QUANTILE +ARBITRARY +ARGMAX +ARGMIN +ARG_MAX +ARG_MAX_NULL +ARG_MIN +ARG_MIN_NULL +ARRAY_AGG +ARRAY_AGGR +ARRAY_AGGREGATE +ARRAY_APPEND +ARRAY_APPLY +ARRAY_CAT +ARRAY_CONCAT +ARRAY_CONTAINS +ARRAY_COSINE_SIMILARITY +ARRAY_CROSS_PRODUCT +ARRAY_DISTANCE +ARRAY_DISTINCT +ARRAY_DOT_PRODUCT +ARRAY_EXTRACT +ARRAY_FILTER +ARRAY_GRADE_UP +ARRAY_HAS +ARRAY_HAS_ALL +ARRAY_HAS_ANY +ARRAY_INDEXOF +ARRAY_INNER_PRODUCT +ARRAY_INTERSECT +ARRAY_LENGTH +ARRAY_POP_BACK +ARRAY_POP_FRONT +ARRAY_POSITION +ARRAY_PREPEND +ARRAY_PUSH_BACK +ARRAY_PUSH_FRONT +ARRAY_REDUCE +ARRAY_RESIZE +ARRAY_REVERSE +ARRAY_REVERSE_SORT +ARRAY_SELECT +ARRAY_SLICE +ARRAY_SORT +ARRAY_TO_JSON +ARRAY_TO_STRING +ARRAY_TRANSFORM +ARRAY_UNIQUE +ARRAY_VALUE +ARRAY_WHERE +ARRAY_ZIP +ARROW_SCAN +ARROW_SCAN_DUMB +ASCII +ASIN +ATAN +ATAN2 +AVG +BAR +BASE64 +BIN +BITSTRING +BITSTRING_AGG +BIT_AND +BIT_COUNT +BIT_LENGTH +BIT_OR +BIT_POSITION +BIT_XOR +BOOL_AND +BOOL_OR +CARDINALITY +CBRT +CEIL +CEILING +CENTURY +CHECKPOINT +CHR +COLLATIONS +COL_DESCRIPTION +COMBINE +CONCAT +CONCAT_WS +CONSTANT_OR_NULL +CONTAINS +COPY_DATABASE +CORR +COS +COT +COUNT +COUNT_IF +COUNT_STAR +COVAR_POP +COVAR_SAMP +CREATE_SORT_KEY +CURRENT_CATALOG +CURRENT_DATABASE +CURRENT_DATE +CURRENT_LOCALTIME +CURRENT_LOCALTIMESTAMP +CURRENT_QUERY +CURRENT_ROLE +CURRENT_SCHEMA +CURRENT_SCHEMAS +CURRENT_SETTING +CURRENT_USER +CURRVAL +DAMERAU_LEVENSHTEIN +DATABASE_LIST +DATABASE_SIZE +DATEDIFF +DATEPART +DATESUB +DATETRUNC +DATE_ADD +DATE_DIFF +DATE_PART +DATE_SUB +DATE_TRUNC +DAY +DAYNAME +DAYOFMONTH +DAYOFWEEK +DAYOFYEAR +DECADE +DECODE +DEGREES +DISABLE_CHECKPOINT_ON_SHUTDOWN +DISABLE_OBJECT_CACHE +DISABLE_OPTIMIZER +DISABLE_PRINT_PROGRESS_BAR +DISABLE_PROFILE +DISABLE_PROFILING +DISABLE_PROGRESS_BAR +DISABLE_VERIFICATION +DISABLE_VERIFY_EXTERNAL +DISABLE_VERIFY_FETCH_ROW +DISABLE_VERIFY_PARALLELISM +DISABLE_VERIFY_SERIALIZER +DIVIDE +DUCKDB_COLUMNS +DUCKDB_CONSTRAINTS +DUCKDB_DATABASES +DUCKDB_DEPENDENCIES +DUCKDB_EXTENSIONS +DUCKDB_FUNCTIONS +DUCKDB_INDEXES +DUCKDB_KEYWORDS +DUCKDB_MEMORY +DUCKDB_OPTIMIZERS +DUCKDB_SCHEMAS +DUCKDB_SECRETS +DUCKDB_SEQUENCES +DUCKDB_SETTINGS +DUCKDB_TABLES +DUCKDB_TEMPORARY_FILES +DUCKDB_TYPES +DUCKDB_VIEWS +EDIT +EDITDIST3 +ELEMENT_AT +ENABLE_CHECKPOINT_ON_SHUTDOWN +ENABLE_OBJECT_CACHE +ENABLE_OPTIMIZER +ENABLE_PRINT_PROGRESS_BAR +ENABLE_PROFILE +ENABLE_PROFILING +ENABLE_PROGRESS_BAR +ENABLE_VERIFICATION +ENCODE +ENDS_WITH +ENTROPY +ENUM_CODE +ENUM_FIRST +ENUM_LAST +ENUM_RANGE +ENUM_RANGE_BOUNDARY +EPOCH +EPOCH_MS +EPOCH_NS +EPOCH_US +ERA +ERROR +EVEN +EXP +FACTORIAL +FAVG +FDIV +FILTER +FINALIZE +FIRST +FLATTEN +FLOOR +FMOD +FORCE_CHECKPOINT +FORMAT +FORMATREADABLEDECIMALSIZE +FORMATREADABLESIZE +FORMAT_BYTES +FORMAT_PG_TYPE +FORMAT_TYPE +FROM_BASE64 +FROM_BINARY +FROM_HEX +FROM_JSON +FROM_JSON_STRICT +FSUM +FUNCTIONS +GAMMA +GCD +GENERATE_SERIES +GENERATE_SUBSCRIPTS +GEN_RANDOM_UUID +GEOMEAN +GEOMETRIC_MEAN +GETENV +GET_BIT +GET_BLOCK_SIZE +GET_CURRENT_TIME +GET_CURRENT_TIMESTAMP +GLOB +GRADE_UP +GREATEST +GREATEST_COMMON_DIVISOR +GROUP_CONCAT +HAMMING +HASH +HAS_ANY_COLUMN_PRIVILEGE +HAS_COLUMN_PRIVILEGE +HAS_DATABASE_PRIVILEGE +HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE +HAS_FUNCTION_PRIVILEGE +HAS_LANGUAGE_PRIVILEGE +HAS_SCHEMA_PRIVILEGE +HAS_SEQUENCE_PRIVILEGE +HAS_SERVER_PRIVILEGE +HAS_TABLESPACE_PRIVILEGE +HAS_TABLE_PRIVILEGE +HEX +HISTOGRAM +HOUR +ICU_CALENDAR_NAMES +ICU_SORT_KEY +ILIKE_ESCAPE +IMPORT_DATABASE +INDEX_SCAN +INET_CLIENT_ADDR +INET_CLIENT_PORT +INET_SERVER_ADDR +INET_SERVER_PORT +INSTR +IN_SEARCH_PATH +ISFINITE +ISINF +ISNAN +ISODOW +ISOYEAR +JACCARD +JARO_SIMILARITY +JARO_WINKLER_SIMILARITY +JSON +JSON_ARRAY +JSON_ARRAY_LENGTH +JSON_CONTAINS +JSON_DESERIALIZE_SQL +JSON_EXECUTE_SERIALIZED_SQL +JSON_EXTRACT +JSON_EXTRACT_PATH +JSON_EXTRACT_PATH_TEXT +JSON_EXTRACT_STRING +JSON_GROUP_ARRAY +JSON_GROUP_OBJECT +JSON_GROUP_STRUCTURE +JSON_KEYS +JSON_MERGE_PATCH +JSON_OBJECT +JSON_QUOTE +JSON_SERIALIZE_PLAN +JSON_SERIALIZE_SQL +JSON_STRUCTURE +JSON_TRANSFORM +JSON_TRANSFORM_STRICT +JSON_TYPE +JSON_VALID +JULIAN +KAHAN_SUM +KURTOSIS +KURTOSIS_POP +LAST +LAST_DAY +LCASE +LCM +LEAST +LEAST_COMMON_MULTIPLE +LEFT +LEFT_GRAPHEME +LEN +LENGTH +LENGTH_GRAPHEME +LEVENSHTEIN +LGAMMA +LIKE_ESCAPE +LIST +LISTAGG +LIST_AGGR +LIST_AGGREGATE +LIST_ANY_VALUE +LIST_APPEND +LIST_APPLY +LIST_APPROX_COUNT_DISTINCT +LIST_AVG +LIST_BIT_AND +LIST_BIT_OR +LIST_BIT_XOR +LIST_BOOL_AND +LIST_BOOL_OR +LIST_CAT +LIST_CONCAT +LIST_CONTAINS +LIST_COSINE_SIMILARITY +LIST_COUNT +LIST_DISTANCE +LIST_DISTINCT +LIST_DOT_PRODUCT +LIST_ELEMENT +LIST_ENTROPY +LIST_EXTRACT +LIST_FILTER +LIST_FIRST +LIST_GRADE_UP +LIST_HAS +LIST_HAS_ALL +LIST_HAS_ANY +LIST_HISTOGRAM +LIST_INDEXOF +LIST_INNER_PRODUCT +LIST_INTERSECT +LIST_KURTOSIS +LIST_KURTOSIS_POP +LIST_LAST +LIST_MAD +LIST_MAX +LIST_MEDIAN +LIST_MIN +LIST_MODE +LIST_PACK +LIST_POSITION +LIST_PREPEND +LIST_PRODUCT +LIST_REDUCE +LIST_RESIZE +LIST_REVERSE +LIST_REVERSE_SORT +LIST_SELECT +LIST_SEM +LIST_SKEWNESS +LIST_SLICE +LIST_SORT +LIST_STDDEV_POP +LIST_STDDEV_SAMP +LIST_STRING_AGG +LIST_SUM +LIST_TRANSFORM +LIST_UNIQUE +LIST_VALUE +LIST_VAR_POP +LIST_VAR_SAMP +LIST_WHERE +LIST_ZIP +LN +LOG +LOG10 +LOG2 +LOWER +LPAD +LSMODE +LTRIM +MAD +MAKE_DATE +MAKE_TIME +MAKE_TIMESTAMP +MAKE_TIMESTAMPTZ +MAP +MAP_CONCAT +MAP_ENTRIES +MAP_EXTRACT +MAP_FROM_ENTRIES +MAP_KEYS +MAP_VALUES +MAX +MAX_BY +MD5 +MD5_NUMBER +MD5_NUMBER_LOWER +MD5_NUMBER_UPPER +MEAN +MEDIAN +METADATA_INFO +MICROSECOND +MILLENNIUM +MILLISECOND +MIN +MINUTE +MIN_BY +MISMATCHES +MOD +MODE +MONTH +MONTHNAME +MULTIPLY +NEXTAFTER +NEXTVAL +NFC_NORMALIZE +NOT_ILIKE_ESCAPE +NOT_LIKE_ESCAPE +NOW +NULLIF +OBJ_DESCRIPTION +OCTET_LENGTH +ORD +PARQUET_FILE_METADATA +PARQUET_KV_METADATA +PARQUET_METADATA +PARQUET_SCAN +PARQUET_SCHEMA +PARSE_DIRNAME +PARSE_DIRPATH +PARSE_FILENAME +PARSE_PATH +PG_COLLATION_IS_VISIBLE +PG_CONF_LOAD_TIME +PG_CONVERSION_IS_VISIBLE +PG_FUNCTION_IS_VISIBLE +PG_GET_CONSTRAINTDEF +PG_GET_EXPR +PG_GET_VIEWDEF +PG_HAS_ROLE +PG_IS_OTHER_TEMP_SCHEMA +PG_MY_TEMP_SCHEMA +PG_OPCLASS_IS_VISIBLE +PG_OPERATOR_IS_VISIBLE +PG_OPFAMILY_IS_VISIBLE +PG_POSTMASTER_START_TIME +PG_SIZE_PRETTY +PG_TABLE_IS_VISIBLE +PG_TIMEZONE_NAMES +PG_TS_CONFIG_IS_VISIBLE +PG_TS_DICT_IS_VISIBLE +PG_TS_PARSER_IS_VISIBLE +PG_TS_TEMPLATE_IS_VISIBLE +PG_TYPEOF +PG_TYPE_IS_VISIBLE +PI +PLATFORM +POSITION +POW +POWER +PRAGMA_COLLATIONS +PRAGMA_DATABASE_SIZE +PRAGMA_METADATA_INFO +PRAGMA_PLATFORM +PRAGMA_SHOW +PRAGMA_STORAGE_INFO +PRAGMA_TABLE_INFO +PRAGMA_USER_AGENT +PRAGMA_VERSION +PREFIX +PRINTF +PRODUCT +QUANTILE +QUANTILE_CONT +QUANTILE_DISC +QUARTER +RADIANS +RANDOM +RANGE +READFILE +READ_BLOB +READ_CSV +READ_CSV_AUTO +READ_JSON +READ_JSON_AUTO +READ_JSON_OBJECTS +READ_JSON_OBJECTS_AUTO +READ_NDJSON +READ_NDJSON_AUTO +READ_NDJSON_OBJECTS +READ_PARQUET +READ_TEXT +REDUCE +REGEXP_ESCAPE +REGEXP_EXTRACT +REGEXP_EXTRACT_ALL +REGEXP_FULL_MATCH +REGEXP_MATCHES +REGEXP_REPLACE +REGEXP_SPLIT_TO_ARRAY +REGEXP_SPLIT_TO_TABLE +REGR_AVGX +REGR_AVGY +REGR_COUNT +REGR_INTERCEPT +REGR_R2 +REGR_SLOPE +REGR_SXX +REGR_SXY +REGR_SYY +REPEAT +REPEAT_ROW +REPLACE +RESERVOIR_QUANTILE +REVERSE +RIGHT +RIGHT_GRAPHEME +ROUND +ROUNDBANKERS +ROUND_EVEN +ROW +ROW_TO_JSON +RPAD +RTRIM +SECOND +SEM +SEQ_SCAN +SESSION_USER +SETSEED +SET_BIT +SHA256 +SHA3 +SHELL_ADD_SCHEMA +SHELL_ESCAPE_CRNL +SHELL_IDQUOTE +SHELL_MODULE_SCHEMA +SHELL_PUTSNL +SHOBJ_DESCRIPTION +SHOW +SHOW_DATABASES +SHOW_TABLES +SHOW_TABLES_EXPANDED +SIGN +SIGNBIT +SIN +SKEWNESS +SNIFF_CSV +SPLIT +SPLIT_PART +SQL_AUTO_COMPLETE +SQRT +STARTS_WITH +STATS +STDDEV +STDDEV_POP +STDDEV_SAMP +STORAGE_INFO +STRFTIME +STRING_AGG +STRING_SPLIT +STRING_SPLIT_REGEX +STRING_TO_ARRAY +STRIP_ACCENTS +STRLEN +STRPOS +STRPTIME +STRUCT_EXTRACT +STRUCT_INSERT +STRUCT_PACK +STR_SPLIT +STR_SPLIT_REGEX +SUBSTR +SUBSTRING +SUBSTRING_GRAPHEME +SUBTRACT +SUFFIX +SUM +SUMKAHAN +SUMMARY +SUM_NO_OVERFLOW +TABLE_INFO +TAN +TEST_ALL_TYPES +TEST_VECTOR_TYPES +TIMEZONE +TIMEZONE_HOUR +TIMEZONE_MINUTE +TIME_BUCKET +TODAY +TO_BASE +TO_BASE64 +TO_BINARY +TO_CENTURIES +TO_DAYS +TO_DECADES +TO_HEX +TO_HOURS +TO_JSON +TO_MICROSECONDS +TO_MILLENNIA +TO_MILLISECONDS +TO_MINUTES +TO_MONTHS +TO_SECONDS +TO_TIMESTAMP +TO_WEEKS +TO_YEARS +TRANSACTION_TIMESTAMP +TRANSLATE +TRIM +TRUNC +TRY_STRPTIME +TXID_CURRENT +TYPEOF +UCASE +UNBIN +UNHEX +UNICODE +UNION_EXTRACT +UNION_TAG +UNION_VALUE +UNNEST +UNPIVOT_LIST +UPPER +USER +USER_AGENT +UUID +VARIANCE +VAR_POP +VAR_SAMP +VECTOR_TYPE +VERIFY_EXTERNAL +VERIFY_FETCH_ROW +VERIFY_PARALLELISM +VERIFY_SERIALIZER +VERSION +WEEK +WEEKDAY +WEEKOFYEAR +WHICH_SECRET +WRITEFILE +XOR +YEAR +YEARWEEK diff --git a/duckdb_keywords.txt b/duckdb_keywords.txt new file mode 100644 index 0000000000..9a1b475b26 --- /dev/null +++ b/duckdb_keywords.txt @@ -0,0 +1,476 @@ +ABORT +ABSOLUTE +ACCESS +ACTION +ADD +ADMIN +AFTER +AGGREGATE +ALL +ALSO +ALTER +ALWAYS +ANALYSE +ANALYZE +AND +ANTI +ANY +ARRAY +AS +ASC +ASOF +ASSERTION +ASSIGNMENT +ASYMMETRIC +AT +ATTACH +ATTRIBUTE +AUTHORIZATION +BACKWARD +BEFORE +BEGIN +BETWEEN +BIGINT +BINARY +BIT +BOOLEAN +BOTH +BY +CACHE +CALL +CALLED +CASCADE +CASCADED +CASE +CAST +CATALOG +CENTURIES +CENTURY +CHAIN +CHAR +CHARACTER +CHARACTERISTICS +CHECK +CHECKPOINT +CLASS +CLOSE +CLUSTER +COALESCE +COLLATE +COLLATION +COLUMN +COLUMNS +COMMENT +COMMENTS +COMMIT +COMMITTED +COMPRESSION +CONCURRENTLY +CONFIGURATION +CONFLICT +CONNECTION +CONSTRAINT +CONSTRAINTS +CONTENT +CONTINUE +CONVERSION +COPY +COST +CREATE +CROSS +CSV +CUBE +CURRENT +CURSOR +CYCLE +DATA +DATABASE +DAY +DAYS +DEALLOCATE +DEC +DECADE +DECADES +DECIMAL +DECLARE +DEFAULT +DEFAULTS +DEFERRABLE +DEFERRED +DEFINER +DELETE +DELIMITER +DELIMITERS +DEPENDS +DESC +DESCRIBE +DETACH +DICTIONARY +DISABLE +DISCARD +DISTINCT +DO +DOCUMENT +DOMAIN +DOUBLE +DROP +EACH +ELSE +ENABLE +ENCODING +ENCRYPTED +END +ENUM +ESCAPE +EVENT +EXCEPT +EXCLUDE +EXCLUDING +EXCLUSIVE +EXECUTE +EXISTS +EXPLAIN +EXPORT +EXPORT_STATE +EXTENSION +EXTERNAL +EXTRACT +FALSE +FAMILY +FETCH +FILTER +FIRST +FLOAT +FOLLOWING +FOR +FORCE +FOREIGN +FORWARD +FREEZE +FROM +FULL +FUNCTION +FUNCTIONS +GENERATED +GLOB +GLOBAL +GRANT +GRANTED +GROUP +GROUPING +GROUPING_ID +GROUPS +HANDLER +HAVING +HEADER +HOLD +HOUR +HOURS +IDENTITY +IF +IGNORE +ILIKE +IMMEDIATE +IMMUTABLE +IMPLICIT +IMPORT +IN +INCLUDE +INCLUDING +INCREMENT +INDEX +INDEXES +INHERIT +INHERITS +INITIALLY +INLINE +INNER +INOUT +INPUT +INSENSITIVE +INSERT +INSTALL +INSTEAD +INT +INTEGER +INTERSECT +INTERVAL +INTO +INVOKER +IS +ISNULL +ISOLATION +JOIN +JSON +KEY +LABEL +LANGUAGE +LARGE +LAST +LATERAL +LEADING +LEAKPROOF +LEFT +LEVEL +LIKE +LIMIT +LISTEN +LOAD +LOCAL +LOCATION +LOCK +LOCKED +LOGGED +MACRO +MAP +MAPPING +MATCH +MATERIALIZED +MAXVALUE +METHOD +MICROSECOND +MICROSECONDS +MILLENNIA +MILLENNIUM +MILLISECOND +MILLISECONDS +MINUTE +MINUTES +MINVALUE +MODE +MONTH +MONTHS +MOVE +NAME +NAMES +NATIONAL +NATURAL +NCHAR +NEW +NEXT +NO +NONE +NOT +NOTHING +NOTIFY +NOTNULL +NOWAIT +NULL +NULLIF +NULLS +NUMERIC +OBJECT +OF +OFF +OFFSET +OIDS +OLD +ON +ONLY +OPERATOR +OPTION +OPTIONS +OR +ORDER +ORDINALITY +OTHERS +OUT +OUTER +OVER +OVERLAPS +OVERLAY +OVERRIDING +OWNED +OWNER +PARALLEL +PARSER +PARTIAL +PARTITION +PASSING +PASSWORD +PERCENT +PERSISTENT +PIVOT +PIVOT_LONGER +PIVOT_WIDER +PLACING +PLANS +POLICY +POSITION +POSITIONAL +PRAGMA +PRECEDING +PRECISION +PREPARE +PREPARED +PRESERVE +PRIMARY +PRIOR +PRIVILEGES +PROCEDURAL +PROCEDURE +PROGRAM +PUBLICATION +QUALIFY +QUOTE +RANGE +READ +REAL +REASSIGN +RECHECK +RECURSIVE +REF +REFERENCES +REFERENCING +REFRESH +REINDEX +RELATIVE +RELEASE +RENAME +REPEATABLE +REPLACE +REPLICA +RESET +RESPECT +RESTART +RESTRICT +RETURNING +RETURNS +REVOKE +RIGHT +ROLE +ROLLBACK +ROLLUP +ROW +ROWS +RULE +SAMPLE +SAVEPOINT +SCHEMA +SCHEMAS +SCOPE +SCROLL +SEARCH +SECOND +SECONDS +SECRET +SECURITY +SELECT +SEMI +SEQUENCE +SEQUENCES +SERIALIZABLE +SERVER +SESSION +SET +SETOF +SETS +SHARE +SHOW +SIMILAR +SIMPLE +SKIP +SMALLINT +SNAPSHOT +SOME +SQL +STABLE +STANDALONE +START +STATEMENT +STATISTICS +STDIN +STDOUT +STORAGE +STORED +STRICT +STRIP +STRUCT +SUBSCRIPTION +SUBSTRING +SUMMARIZE +SYMMETRIC +SYSID +SYSTEM +TABLE +TABLES +TABLESAMPLE +TABLESPACE +TEMP +TEMPLATE +TEMPORARY +TEXT +THEN +TIES +TIME +TIMESTAMP +TO +TRAILING +TRANSACTION +TRANSFORM +TREAT +TRIGGER +TRIM +TRUE +TRUNCATE +TRUSTED +TRY_CAST +TYPE +TYPES +UNBOUNDED +UNCOMMITTED +UNENCRYPTED +UNION +UNIQUE +UNKNOWN +UNLISTEN +UNLOGGED +UNPIVOT +UNTIL +UPDATE +USE +USER +USING +VACUUM +VALID +VALIDATE +VALIDATOR +VALUE +VALUES +VARCHAR +VARIADIC +VARYING +VERBOSE +VERSION +VIEW +VIEWS +VIRTUAL +VOLATILE +WEEK +WEEKS +WHEN +WHERE +WHITESPACE +WINDOW +WITH +WITHIN +WITHOUT +WORK +WRAPPER +WRITE +XML +XMLATTRIBUTES +XMLCONCAT +XMLELEMENT +XMLEXISTS +XMLFOREST +XMLNAMESPACES +XMLPARSE +XMLPI +XMLROOT +XMLSERIALIZE +XMLTABLE +YEAR +YEARS +YES +ZONE diff --git a/duckdb_types.txt b/duckdb_types.txt new file mode 100644 index 0000000000..e58d37a2ef --- /dev/null +++ b/duckdb_types.txt @@ -0,0 +1,33 @@ +BIGINT +BIT +BLOB +BOOLEAN +DATE +DECIMAL +DOUBLE +ENUM +FLOAT +HUGEINT +INTEGER +INTERVAL +LIST +MAP +NULL +SMALLINT +STRUCT +TIME +TIME WITH TIME ZONE +TIMESTAMP +TIMESTAMP WITH TIME ZONE +TIMESTAMP_MS +TIMESTAMP_NS +TIMESTAMP_S +TINYINT +UBIGINT +UHUGEINT +UINTEGER +UNION +USMALLINT +UTINYINT +UUID +VARCHAR diff --git a/duckdb_words.sql b/duckdb_words.sql new file mode 100644 index 0000000000..bb7b7ee053 --- /dev/null +++ b/duckdb_words.sql @@ -0,0 +1,20 @@ +COPY ( + SELECT DISTINCT upper(function_name) AS function_name + FROM duckdb_functions() + WHERE function_name SIMILAR TO '^[a-z].*' + ORDER BY function_name +) TO 'duckdb_functions.txt' WITH (sep ',', header FALSE); + + +COPY ( + SELECT upper(keyword_name) + FROM duckdb_keywords() + ORDER BY keyword_name +) TO 'duckdb_keywords.txt' WITH (sep ',', header FALSE); + + +COPY ( + SELECT DISTINCT upper(logical_type) + FROM duckdb_types() + ORDER BY logical_type +) TO 'duckdb_types.txt' WITH (sep ',', header FALSE); \ No newline at end of file From fc44804000f9a0ae26559b723077d31437012575 Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Tue, 30 Apr 2024 15:05:12 +1000 Subject: [PATCH 03/24] Setup tests --- test/duckdb.test.ts | 368 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 368 insertions(+) create mode 100644 test/duckdb.test.ts diff --git a/test/duckdb.test.ts b/test/duckdb.test.ts new file mode 100644 index 0000000000..ccb3eb5443 --- /dev/null +++ b/test/duckdb.test.ts @@ -0,0 +1,368 @@ +import dedent from 'dedent-js'; + +import { format as originalFormat, FormatFn } from '../src/sqlFormatter.js'; + +import behavesLikeSqlFormatter from './behavesLikeSqlFormatter.js'; +import supportsAlterTable from './features/alterTable.js'; +import supportsBetween from './features/between.js'; +import supportsCreateTable from './features/createTable.js'; +import supportsDropTable from './features/dropTable.js'; +import supportsJoin from './features/join.js'; +import supportsOperators from './features/operators.js'; +import supportsSchema from './features/schema.js'; +import supportsStrings from './features/strings.js'; +import supportsReturning from './features/returning.js'; +import supportsConstraints from './features/constraints.js'; +import supportsDeleteFrom from './features/deleteFrom.js'; +import supportsComments from './features/comments.js'; +import supportsCommentOn from './features/commentOn.js'; +import supportsIdentifiers from './features/identifiers.js'; +import supportsParams from './options/param.js'; +import supportsArrayAndMapAccessors from './features/arrayAndMapAccessors.js'; +import supportsWindow from './features/window.js'; +import supportsSetOperations from './features/setOperations.js'; +import supportsLimiting from './features/limiting.js'; +import supportsInsertInto from './features/insertInto.js'; +import supportsUpdate from './features/update.js'; +import supportsTruncateTable from './features/truncateTable.js'; +import supportsCreateView from './features/createView.js'; +import supportsOnConflict from './features/onConflict.js'; +import supportsIsDistinctFrom from './features/isDistinctFrom.js'; +import supportsArrayLiterals from './features/arrayLiterals.js'; +import supportsDataTypeCase from './options/dataTypeCase.js'; + +describe('DuckDBFormatter', () => { + const language = 'duckdb'; + const format: FormatFn = (query, cfg = {}) => originalFormat(query, { ...cfg, language }); + + behavesLikeSqlFormatter(format); + supportsComments(format, { nestedBlockComments: true }); + supportsCommentOn(format); + supportsCreateView(format, { orReplace: true, materialized: true, ifNotExists: true }); + supportsCreateTable(format, { ifNotExists: true }); + supportsDropTable(format, { ifExists: true }); + supportsConstraints(format, ['NO ACTION', 'RESTRICT', 'CASCADE', 'SET NULL', 'SET DEFAULT']); + supportsArrayLiterals(format, { withArrayPrefix: true }); + supportsArrayAndMapAccessors(format); + supportsAlterTable(format, { + addColumn: true, + dropColumn: true, + renameTo: true, + renameColumn: true, + }); + supportsDeleteFrom(format); + supportsInsertInto(format); + supportsOnConflict(format); + supportsUpdate(format, { whereCurrentOf: true }); + supportsTruncateTable(format, { withoutTable: true }); + supportsStrings(format, ["''-qq", "U&''", "X''", "B''"]); + supportsIdentifiers(format, [`""-qq`, 'U&""']); + supportsBetween(format); + supportsSchema(format); + // Missing: '::' type cast (tested separately) + supportsOperators( + format, + [ + // Arithmetic + '%', + '^', + '|/', + '||/', + '@', + // Assignment + ':=', + // Bitwise + '&', + '|', + '#', + '~', + '<<', + '>>', + // Byte comparison + '~>~', + '~<~', + '~>=~', + '~<=~', + // Geometric + '@-@', + '@@', + '##', + '<->', + '&&', + '&<', + '&>', + '<<|', + '&<|', + '|>>', + '|&>', + '<^', + '^>', + '?#', + '?-', + '?|', + '?-|', + '?||', + '@>', + '<@', + '~=', + // JSON + '?', + '@?', + '?&', + '->', + '->>', + '#>', + '#>>', + '#-', + // Named function params + '=>', + // Network address + '>>=', + '<<=', + // Pattern matching + '~~', + '~~*', + '!~~', + '!~~*', + // POSIX RegExp + '~', + '~*', + '!~', + '!~*', + // Range/multirange + '-|-', + // String concatenation + '||', + // Text search + '@@@', + '!!', + '^@', + // Trigram/trigraph + '<%', + '<<%', + '%>', + '%>>', + '<<->', + '<->>', + '<<<->', + '<->>>', + ], + { any: true } + ); + supportsIsDistinctFrom(format); + supportsJoin(format); + supportsSetOperations(format); + supportsReturning(format); + supportsParams(format, { numbered: ['$'] }); + supportsWindow(format); + supportsLimiting(format, { limit: true, offset: true, fetchFirst: true, fetchNext: true }); + supportsDataTypeCase(format); + + it('allows $ character as part of identifiers', () => { + expect(format('SELECT foo$, some$$ident')).toBe(dedent` + SELECT + foo$, + some$$ident + `); + }); + + // Postgres-specific string types + it("supports E'' strings with C-style escapes", () => { + expect(format("E'blah blah'")).toBe("E'blah blah'"); + expect(format("E'some \\' FROM escapes'")).toBe("E'some \\' FROM escapes'"); + expect(format("SELECT E'blah' FROM foo")).toBe(dedent` + SELECT + E'blah' + FROM + foo + `); + expect(format("E'blah''blah'")).toBe("E'blah''blah'"); + }); + + it('supports dollar-quoted strings', () => { + expect(format('$xxx$foo $$ LEFT JOIN $yyy$ bar$xxx$')).toBe( + '$xxx$foo $$ LEFT JOIN $yyy$ bar$xxx$' + ); + expect(format('$$foo JOIN bar$$')).toBe('$$foo JOIN bar$$'); + expect(format('$$foo $ JOIN bar$$')).toBe('$$foo $ JOIN bar$$'); + expect(format('$$foo \n bar$$')).toBe('$$foo \n bar$$'); + expect(format('SELECT $$where$$ FROM $$update$$')).toBe(dedent` + SELECT + $$where$$ + FROM + $$update$$ + `); + }); + + it('formats type-cast operator without spaces', () => { + expect(format('SELECT 2 :: numeric AS foo;')).toBe(dedent` + SELECT + 2::numeric AS foo; + `); + }); + + // issue #144 (unsolved) + // This is currently far from ideal. + it('formats SELECT DISTINCT ON () syntax', () => { + expect(format('SELECT DISTINCT ON (c1, c2) c1, c2 FROM tbl;')).toBe(dedent` + SELECT DISTINCT + ON (c1, c2) c1, + c2 + FROM + tbl; + `); + }); + + // Regression test for issue #447 + it('formats empty SELECT', () => { + expect(format('SELECT;')).toBe(dedent` + SELECT; + `); + }); + + // Regression test for issues #391 and #618 + it('formats TIMESTAMP WITH TIME ZONE syntax', () => { + expect( + format(` + CREATE TABLE time_table (id INT, + created_at TIMESTAMP WITH TIME ZONE, + deleted_at TIME WITH TIME ZONE, + modified_at TIMESTAMP(0) WITH TIME ZONE);`) + ).toBe(dedent` + CREATE TABLE time_table ( + id INT, + created_at TIMESTAMP WITH TIME ZONE, + deleted_at TIME WITH TIME ZONE, + modified_at TIMESTAMP(0) WITH TIME ZONE + ); + `); + }); + + // Regression test for issue #624 + it('supports array slice operator', () => { + expect(format('SELECT foo[:5], bar[1:], baz[1:5], zap[:];')).toBe(dedent` + SELECT + foo[:5], + bar[1:], + baz[1:5], + zap[:]; + `); + }); + + it('formats ALTER TABLE ... ALTER COLUMN', () => { + expect( + format( + `ALTER TABLE t ALTER COLUMN foo SET DATA TYPE VARCHAR; + ALTER TABLE t ALTER COLUMN foo SET DEFAULT 5; + ALTER TABLE t ALTER COLUMN foo DROP DEFAULT; + ALTER TABLE t ALTER COLUMN foo SET NOT NULL; + ALTER TABLE t ALTER COLUMN foo DROP NOT NULL;` + ) + ).toBe(dedent` + ALTER TABLE t + ALTER COLUMN foo + SET DATA TYPE VARCHAR; + + ALTER TABLE t + ALTER COLUMN foo + SET DEFAULT 5; + + ALTER TABLE t + ALTER COLUMN foo + DROP DEFAULT; + + ALTER TABLE t + ALTER COLUMN foo + SET NOT NULL; + + ALTER TABLE t + ALTER COLUMN foo + DROP NOT NULL; + `); + }); + + it('formats FOR UPDATE clause', () => { + expect( + format(` + SELECT * FROM tbl FOR UPDATE; + SELECT * FROM tbl FOR UPDATE OF tbl.salary; + `) + ).toBe(dedent` + SELECT + * + FROM + tbl + FOR UPDATE; + + SELECT + * + FROM + tbl + FOR UPDATE OF + tbl.salary; + `); + }); + + // Issue #685 + it('allows TYPE to be used as an identifier', () => { + expect(format(`SELECT type, modified_at FROM items;`)).toBe(dedent` + SELECT + type, + modified_at + FROM + items; + `); + }); + + // Issue #156, #709 + it('does not recognize common fields names as keywords', () => { + expect( + format(`SELECT id, type, name, location, label, password FROM release;`, { + keywordCase: 'upper', + }) + ).toBe(dedent` + SELECT + id, + type, + name, + location, + label, + password + FROM + release; + `); + }); + + it('formats DEFAULT VALUES clause', () => { + expect( + format(`INSERT INTO items default values RETURNING id;`, { + keywordCase: 'upper', + }) + ).toBe(dedent` + INSERT INTO + items + DEFAULT VALUES + RETURNING + id; + `); + }); + + // Issue #726 + it('treats TEXT as data-type (not as plain keyword)', () => { + expect( + format(`CREATE TABLE foo (items text);`, { + dataTypeCase: 'upper', + }) + ).toBe(dedent` + CREATE TABLE foo (items TEXT); + `); + + expect( + format(`CREATE TABLE foo (text VARCHAR(100));`, { + keywordCase: 'upper', + }) + ).toBe(dedent` + CREATE TABLE foo (text VARCHAR(100)); + `); + }); +}); From c51ccabd298db307014afb301cdc8567c87f4271 Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Tue, 30 Apr 2024 17:04:14 +1000 Subject: [PATCH 04/24] Add duckdb as dialect --- src/allDialects.ts | 1 + src/sqlFormatter.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/allDialects.ts b/src/allDialects.ts index 790ef2095b..8b41f97358 100644 --- a/src/allDialects.ts +++ b/src/allDialects.ts @@ -1,6 +1,7 @@ export { bigquery } from './languages/bigquery/bigquery.formatter.js'; export { db2 } from './languages/db2/db2.formatter.js'; export { db2i } from './languages/db2i/db2i.formatter.js'; +export { duckdb } from './languages/duckdb/duckdb.formatter.js'; export { hive } from './languages/hive/hive.formatter.js'; export { mariadb } from './languages/mariadb/mariadb.formatter.js'; export { mysql } from './languages/mysql/mysql.formatter.js'; diff --git a/src/sqlFormatter.ts b/src/sqlFormatter.ts index b35ac56e22..f89573c80c 100644 --- a/src/sqlFormatter.ts +++ b/src/sqlFormatter.ts @@ -9,6 +9,7 @@ const dialectNameMap: Record Date: Tue, 30 Apr 2024 17:04:40 +1000 Subject: [PATCH 05/24] Test updates --- src/languages/duckdb/duckdb.formatter.ts | 7 ++----- src/languages/duckdb/duckdb.functions.ts | 9 +++++++++ src/languages/duckdb/duckdb.keywords.ts | 2 -- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/languages/duckdb/duckdb.formatter.ts b/src/languages/duckdb/duckdb.formatter.ts index d2b0d9c8d0..b8c6881799 100644 --- a/src/languages/duckdb/duckdb.formatter.ts +++ b/src/languages/duckdb/duckdb.formatter.ts @@ -63,7 +63,6 @@ const tabularOnelineClauses = expandPhrases([ // other 'SET SCHEMA', 'AFTER', - // https://www.postgresql.org/docs/14/sql-commands.html 'ABORT', 'ALTER AGGREGATE', 'ALTER COLLATION', @@ -251,15 +250,13 @@ const reservedPhrases = expandPhrases([ 'GENERATED {ALWAYS | BY DEFAULT} AS IDENTITY', 'ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]', '{ROWS | RANGE | GROUPS} BETWEEN', - // https://www.postgresql.org/docs/current/datatype-datetime.html '[TIMESTAMP | TIME] {WITH | WITHOUT} TIME ZONE', // comparison operator 'IS [NOT] DISTINCT FROM', ]); -// https://www.postgresql.org/docs/14/index.html -export const postgresql: DialectOptions = { - name: 'postgresql', +export const duckdb: DialectOptions = { + name: 'duckdb', tokenizerOptions: { reservedSelect, reservedClauses: [...reservedClauses, ...standardOnelineClauses, ...tabularOnelineClauses], diff --git a/src/languages/duckdb/duckdb.functions.ts b/src/languages/duckdb/duckdb.functions.ts index 7a3bbe5756..6aeb36c9a7 100644 --- a/src/languages/duckdb/duckdb.functions.ts +++ b/src/languages/duckdb/duckdb.functions.ts @@ -651,4 +651,13 @@ export const functions: string[] = [ 'XOR', 'YEAR', 'YEARWEEK', + + // Keywords that also need to be listed as functions + 'ARRAY', + 'CAST', + 'COALESCE', + 'NULL', + 'RANK', + 'ROW_NUMBER', + 'INT', ]; diff --git a/src/languages/duckdb/duckdb.keywords.ts b/src/languages/duckdb/duckdb.keywords.ts index 1e113eead2..1f4cc82840 100644 --- a/src/languages/duckdb/duckdb.keywords.ts +++ b/src/languages/duckdb/duckdb.keywords.ts @@ -475,7 +475,6 @@ export const keywords: string[] = [ 'YEARS', 'YES', 'ZONE', - ]; export const dataTypes: string[] = [ @@ -512,5 +511,4 @@ export const dataTypes: string[] = [ 'UTINYINT', 'UUID', 'VARCHAR', - ]; From 56059a35d48680d7693292910fbf492774f3db1b Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Tue, 30 Apr 2024 17:06:30 +1000 Subject: [PATCH 06/24] Drop generation files --- duckdb_functions.txt | 652 ------------------------------------------- duckdb_keywords.txt | 476 ------------------------------- duckdb_types.txt | 33 --- duckdb_words.sql | 20 -- 4 files changed, 1181 deletions(-) delete mode 100644 duckdb_functions.txt delete mode 100644 duckdb_keywords.txt delete mode 100644 duckdb_types.txt delete mode 100644 duckdb_words.sql diff --git a/duckdb_functions.txt b/duckdb_functions.txt deleted file mode 100644 index d3e82941ca..0000000000 --- a/duckdb_functions.txt +++ /dev/null @@ -1,652 +0,0 @@ -ABS -ACOS -ADD -ADD_PARQUET_KEY -AGE -AGGREGATE -ALIAS -ALL_PROFILING_OUTPUT -ANY_VALUE -APPLY -APPROX_COUNT_DISTINCT -APPROX_QUANTILE -ARBITRARY -ARGMAX -ARGMIN -ARG_MAX -ARG_MAX_NULL -ARG_MIN -ARG_MIN_NULL -ARRAY_AGG -ARRAY_AGGR -ARRAY_AGGREGATE -ARRAY_APPEND -ARRAY_APPLY -ARRAY_CAT -ARRAY_CONCAT -ARRAY_CONTAINS -ARRAY_COSINE_SIMILARITY -ARRAY_CROSS_PRODUCT -ARRAY_DISTANCE -ARRAY_DISTINCT -ARRAY_DOT_PRODUCT -ARRAY_EXTRACT -ARRAY_FILTER -ARRAY_GRADE_UP -ARRAY_HAS -ARRAY_HAS_ALL -ARRAY_HAS_ANY -ARRAY_INDEXOF -ARRAY_INNER_PRODUCT -ARRAY_INTERSECT -ARRAY_LENGTH -ARRAY_POP_BACK -ARRAY_POP_FRONT -ARRAY_POSITION -ARRAY_PREPEND -ARRAY_PUSH_BACK -ARRAY_PUSH_FRONT -ARRAY_REDUCE -ARRAY_RESIZE -ARRAY_REVERSE -ARRAY_REVERSE_SORT -ARRAY_SELECT -ARRAY_SLICE -ARRAY_SORT -ARRAY_TO_JSON -ARRAY_TO_STRING -ARRAY_TRANSFORM -ARRAY_UNIQUE -ARRAY_VALUE -ARRAY_WHERE -ARRAY_ZIP -ARROW_SCAN -ARROW_SCAN_DUMB -ASCII -ASIN -ATAN -ATAN2 -AVG -BAR -BASE64 -BIN -BITSTRING -BITSTRING_AGG -BIT_AND -BIT_COUNT -BIT_LENGTH -BIT_OR -BIT_POSITION -BIT_XOR -BOOL_AND -BOOL_OR -CARDINALITY -CBRT -CEIL -CEILING -CENTURY -CHECKPOINT -CHR -COLLATIONS -COL_DESCRIPTION -COMBINE -CONCAT -CONCAT_WS -CONSTANT_OR_NULL -CONTAINS -COPY_DATABASE -CORR -COS -COT -COUNT -COUNT_IF -COUNT_STAR -COVAR_POP -COVAR_SAMP -CREATE_SORT_KEY -CURRENT_CATALOG -CURRENT_DATABASE -CURRENT_DATE -CURRENT_LOCALTIME -CURRENT_LOCALTIMESTAMP -CURRENT_QUERY -CURRENT_ROLE -CURRENT_SCHEMA -CURRENT_SCHEMAS -CURRENT_SETTING -CURRENT_USER -CURRVAL -DAMERAU_LEVENSHTEIN -DATABASE_LIST -DATABASE_SIZE -DATEDIFF -DATEPART -DATESUB -DATETRUNC -DATE_ADD -DATE_DIFF -DATE_PART -DATE_SUB -DATE_TRUNC -DAY -DAYNAME -DAYOFMONTH -DAYOFWEEK -DAYOFYEAR -DECADE -DECODE -DEGREES -DISABLE_CHECKPOINT_ON_SHUTDOWN -DISABLE_OBJECT_CACHE -DISABLE_OPTIMIZER -DISABLE_PRINT_PROGRESS_BAR -DISABLE_PROFILE -DISABLE_PROFILING -DISABLE_PROGRESS_BAR -DISABLE_VERIFICATION -DISABLE_VERIFY_EXTERNAL -DISABLE_VERIFY_FETCH_ROW -DISABLE_VERIFY_PARALLELISM -DISABLE_VERIFY_SERIALIZER -DIVIDE -DUCKDB_COLUMNS -DUCKDB_CONSTRAINTS -DUCKDB_DATABASES -DUCKDB_DEPENDENCIES -DUCKDB_EXTENSIONS -DUCKDB_FUNCTIONS -DUCKDB_INDEXES -DUCKDB_KEYWORDS -DUCKDB_MEMORY -DUCKDB_OPTIMIZERS -DUCKDB_SCHEMAS -DUCKDB_SECRETS -DUCKDB_SEQUENCES -DUCKDB_SETTINGS -DUCKDB_TABLES -DUCKDB_TEMPORARY_FILES -DUCKDB_TYPES -DUCKDB_VIEWS -EDIT -EDITDIST3 -ELEMENT_AT -ENABLE_CHECKPOINT_ON_SHUTDOWN -ENABLE_OBJECT_CACHE -ENABLE_OPTIMIZER -ENABLE_PRINT_PROGRESS_BAR -ENABLE_PROFILE -ENABLE_PROFILING -ENABLE_PROGRESS_BAR -ENABLE_VERIFICATION -ENCODE -ENDS_WITH -ENTROPY -ENUM_CODE -ENUM_FIRST -ENUM_LAST -ENUM_RANGE -ENUM_RANGE_BOUNDARY -EPOCH -EPOCH_MS -EPOCH_NS -EPOCH_US -ERA -ERROR -EVEN -EXP -FACTORIAL -FAVG -FDIV -FILTER -FINALIZE -FIRST -FLATTEN -FLOOR -FMOD -FORCE_CHECKPOINT -FORMAT -FORMATREADABLEDECIMALSIZE -FORMATREADABLESIZE -FORMAT_BYTES -FORMAT_PG_TYPE -FORMAT_TYPE -FROM_BASE64 -FROM_BINARY -FROM_HEX -FROM_JSON -FROM_JSON_STRICT -FSUM -FUNCTIONS -GAMMA -GCD -GENERATE_SERIES -GENERATE_SUBSCRIPTS -GEN_RANDOM_UUID -GEOMEAN -GEOMETRIC_MEAN -GETENV -GET_BIT -GET_BLOCK_SIZE -GET_CURRENT_TIME -GET_CURRENT_TIMESTAMP -GLOB -GRADE_UP -GREATEST -GREATEST_COMMON_DIVISOR -GROUP_CONCAT -HAMMING -HASH -HAS_ANY_COLUMN_PRIVILEGE -HAS_COLUMN_PRIVILEGE -HAS_DATABASE_PRIVILEGE -HAS_FOREIGN_DATA_WRAPPER_PRIVILEGE -HAS_FUNCTION_PRIVILEGE -HAS_LANGUAGE_PRIVILEGE -HAS_SCHEMA_PRIVILEGE -HAS_SEQUENCE_PRIVILEGE -HAS_SERVER_PRIVILEGE -HAS_TABLESPACE_PRIVILEGE -HAS_TABLE_PRIVILEGE -HEX -HISTOGRAM -HOUR -ICU_CALENDAR_NAMES -ICU_SORT_KEY -ILIKE_ESCAPE -IMPORT_DATABASE -INDEX_SCAN -INET_CLIENT_ADDR -INET_CLIENT_PORT -INET_SERVER_ADDR -INET_SERVER_PORT -INSTR -IN_SEARCH_PATH -ISFINITE -ISINF -ISNAN -ISODOW -ISOYEAR -JACCARD -JARO_SIMILARITY -JARO_WINKLER_SIMILARITY -JSON -JSON_ARRAY -JSON_ARRAY_LENGTH -JSON_CONTAINS -JSON_DESERIALIZE_SQL -JSON_EXECUTE_SERIALIZED_SQL -JSON_EXTRACT -JSON_EXTRACT_PATH -JSON_EXTRACT_PATH_TEXT -JSON_EXTRACT_STRING -JSON_GROUP_ARRAY -JSON_GROUP_OBJECT -JSON_GROUP_STRUCTURE -JSON_KEYS -JSON_MERGE_PATCH -JSON_OBJECT -JSON_QUOTE -JSON_SERIALIZE_PLAN -JSON_SERIALIZE_SQL -JSON_STRUCTURE -JSON_TRANSFORM -JSON_TRANSFORM_STRICT -JSON_TYPE -JSON_VALID -JULIAN -KAHAN_SUM -KURTOSIS -KURTOSIS_POP -LAST -LAST_DAY -LCASE -LCM -LEAST -LEAST_COMMON_MULTIPLE -LEFT -LEFT_GRAPHEME -LEN -LENGTH -LENGTH_GRAPHEME -LEVENSHTEIN -LGAMMA -LIKE_ESCAPE -LIST -LISTAGG -LIST_AGGR -LIST_AGGREGATE -LIST_ANY_VALUE -LIST_APPEND -LIST_APPLY -LIST_APPROX_COUNT_DISTINCT -LIST_AVG -LIST_BIT_AND -LIST_BIT_OR -LIST_BIT_XOR -LIST_BOOL_AND -LIST_BOOL_OR -LIST_CAT -LIST_CONCAT -LIST_CONTAINS -LIST_COSINE_SIMILARITY -LIST_COUNT -LIST_DISTANCE -LIST_DISTINCT -LIST_DOT_PRODUCT -LIST_ELEMENT -LIST_ENTROPY -LIST_EXTRACT -LIST_FILTER -LIST_FIRST -LIST_GRADE_UP -LIST_HAS -LIST_HAS_ALL -LIST_HAS_ANY -LIST_HISTOGRAM -LIST_INDEXOF -LIST_INNER_PRODUCT -LIST_INTERSECT -LIST_KURTOSIS -LIST_KURTOSIS_POP -LIST_LAST -LIST_MAD -LIST_MAX -LIST_MEDIAN -LIST_MIN -LIST_MODE -LIST_PACK -LIST_POSITION -LIST_PREPEND -LIST_PRODUCT -LIST_REDUCE -LIST_RESIZE -LIST_REVERSE -LIST_REVERSE_SORT -LIST_SELECT -LIST_SEM -LIST_SKEWNESS -LIST_SLICE -LIST_SORT -LIST_STDDEV_POP -LIST_STDDEV_SAMP -LIST_STRING_AGG -LIST_SUM -LIST_TRANSFORM -LIST_UNIQUE -LIST_VALUE -LIST_VAR_POP -LIST_VAR_SAMP -LIST_WHERE -LIST_ZIP -LN -LOG -LOG10 -LOG2 -LOWER -LPAD -LSMODE -LTRIM -MAD -MAKE_DATE -MAKE_TIME -MAKE_TIMESTAMP -MAKE_TIMESTAMPTZ -MAP -MAP_CONCAT -MAP_ENTRIES -MAP_EXTRACT -MAP_FROM_ENTRIES -MAP_KEYS -MAP_VALUES -MAX -MAX_BY -MD5 -MD5_NUMBER -MD5_NUMBER_LOWER -MD5_NUMBER_UPPER -MEAN -MEDIAN -METADATA_INFO -MICROSECOND -MILLENNIUM -MILLISECOND -MIN -MINUTE -MIN_BY -MISMATCHES -MOD -MODE -MONTH -MONTHNAME -MULTIPLY -NEXTAFTER -NEXTVAL -NFC_NORMALIZE -NOT_ILIKE_ESCAPE -NOT_LIKE_ESCAPE -NOW -NULLIF -OBJ_DESCRIPTION -OCTET_LENGTH -ORD -PARQUET_FILE_METADATA -PARQUET_KV_METADATA -PARQUET_METADATA -PARQUET_SCAN -PARQUET_SCHEMA -PARSE_DIRNAME -PARSE_DIRPATH -PARSE_FILENAME -PARSE_PATH -PG_COLLATION_IS_VISIBLE -PG_CONF_LOAD_TIME -PG_CONVERSION_IS_VISIBLE -PG_FUNCTION_IS_VISIBLE -PG_GET_CONSTRAINTDEF -PG_GET_EXPR -PG_GET_VIEWDEF -PG_HAS_ROLE -PG_IS_OTHER_TEMP_SCHEMA -PG_MY_TEMP_SCHEMA -PG_OPCLASS_IS_VISIBLE -PG_OPERATOR_IS_VISIBLE -PG_OPFAMILY_IS_VISIBLE -PG_POSTMASTER_START_TIME -PG_SIZE_PRETTY -PG_TABLE_IS_VISIBLE -PG_TIMEZONE_NAMES -PG_TS_CONFIG_IS_VISIBLE -PG_TS_DICT_IS_VISIBLE -PG_TS_PARSER_IS_VISIBLE -PG_TS_TEMPLATE_IS_VISIBLE -PG_TYPEOF -PG_TYPE_IS_VISIBLE -PI -PLATFORM -POSITION -POW -POWER -PRAGMA_COLLATIONS -PRAGMA_DATABASE_SIZE -PRAGMA_METADATA_INFO -PRAGMA_PLATFORM -PRAGMA_SHOW -PRAGMA_STORAGE_INFO -PRAGMA_TABLE_INFO -PRAGMA_USER_AGENT -PRAGMA_VERSION -PREFIX -PRINTF -PRODUCT -QUANTILE -QUANTILE_CONT -QUANTILE_DISC -QUARTER -RADIANS -RANDOM -RANGE -READFILE -READ_BLOB -READ_CSV -READ_CSV_AUTO -READ_JSON -READ_JSON_AUTO -READ_JSON_OBJECTS -READ_JSON_OBJECTS_AUTO -READ_NDJSON -READ_NDJSON_AUTO -READ_NDJSON_OBJECTS -READ_PARQUET -READ_TEXT -REDUCE -REGEXP_ESCAPE -REGEXP_EXTRACT -REGEXP_EXTRACT_ALL -REGEXP_FULL_MATCH -REGEXP_MATCHES -REGEXP_REPLACE -REGEXP_SPLIT_TO_ARRAY -REGEXP_SPLIT_TO_TABLE -REGR_AVGX -REGR_AVGY -REGR_COUNT -REGR_INTERCEPT -REGR_R2 -REGR_SLOPE -REGR_SXX -REGR_SXY -REGR_SYY -REPEAT -REPEAT_ROW -REPLACE -RESERVOIR_QUANTILE -REVERSE -RIGHT -RIGHT_GRAPHEME -ROUND -ROUNDBANKERS -ROUND_EVEN -ROW -ROW_TO_JSON -RPAD -RTRIM -SECOND -SEM -SEQ_SCAN -SESSION_USER -SETSEED -SET_BIT -SHA256 -SHA3 -SHELL_ADD_SCHEMA -SHELL_ESCAPE_CRNL -SHELL_IDQUOTE -SHELL_MODULE_SCHEMA -SHELL_PUTSNL -SHOBJ_DESCRIPTION -SHOW -SHOW_DATABASES -SHOW_TABLES -SHOW_TABLES_EXPANDED -SIGN -SIGNBIT -SIN -SKEWNESS -SNIFF_CSV -SPLIT -SPLIT_PART -SQL_AUTO_COMPLETE -SQRT -STARTS_WITH -STATS -STDDEV -STDDEV_POP -STDDEV_SAMP -STORAGE_INFO -STRFTIME -STRING_AGG -STRING_SPLIT -STRING_SPLIT_REGEX -STRING_TO_ARRAY -STRIP_ACCENTS -STRLEN -STRPOS -STRPTIME -STRUCT_EXTRACT -STRUCT_INSERT -STRUCT_PACK -STR_SPLIT -STR_SPLIT_REGEX -SUBSTR -SUBSTRING -SUBSTRING_GRAPHEME -SUBTRACT -SUFFIX -SUM -SUMKAHAN -SUMMARY -SUM_NO_OVERFLOW -TABLE_INFO -TAN -TEST_ALL_TYPES -TEST_VECTOR_TYPES -TIMEZONE -TIMEZONE_HOUR -TIMEZONE_MINUTE -TIME_BUCKET -TODAY -TO_BASE -TO_BASE64 -TO_BINARY -TO_CENTURIES -TO_DAYS -TO_DECADES -TO_HEX -TO_HOURS -TO_JSON -TO_MICROSECONDS -TO_MILLENNIA -TO_MILLISECONDS -TO_MINUTES -TO_MONTHS -TO_SECONDS -TO_TIMESTAMP -TO_WEEKS -TO_YEARS -TRANSACTION_TIMESTAMP -TRANSLATE -TRIM -TRUNC -TRY_STRPTIME -TXID_CURRENT -TYPEOF -UCASE -UNBIN -UNHEX -UNICODE -UNION_EXTRACT -UNION_TAG -UNION_VALUE -UNNEST -UNPIVOT_LIST -UPPER -USER -USER_AGENT -UUID -VARIANCE -VAR_POP -VAR_SAMP -VECTOR_TYPE -VERIFY_EXTERNAL -VERIFY_FETCH_ROW -VERIFY_PARALLELISM -VERIFY_SERIALIZER -VERSION -WEEK -WEEKDAY -WEEKOFYEAR -WHICH_SECRET -WRITEFILE -XOR -YEAR -YEARWEEK diff --git a/duckdb_keywords.txt b/duckdb_keywords.txt deleted file mode 100644 index 9a1b475b26..0000000000 --- a/duckdb_keywords.txt +++ /dev/null @@ -1,476 +0,0 @@ -ABORT -ABSOLUTE -ACCESS -ACTION -ADD -ADMIN -AFTER -AGGREGATE -ALL -ALSO -ALTER -ALWAYS -ANALYSE -ANALYZE -AND -ANTI -ANY -ARRAY -AS -ASC -ASOF -ASSERTION -ASSIGNMENT -ASYMMETRIC -AT -ATTACH -ATTRIBUTE -AUTHORIZATION -BACKWARD -BEFORE -BEGIN -BETWEEN -BIGINT -BINARY -BIT -BOOLEAN -BOTH -BY -CACHE -CALL -CALLED -CASCADE -CASCADED -CASE -CAST -CATALOG -CENTURIES -CENTURY -CHAIN -CHAR -CHARACTER -CHARACTERISTICS -CHECK -CHECKPOINT -CLASS -CLOSE -CLUSTER -COALESCE -COLLATE -COLLATION -COLUMN -COLUMNS -COMMENT -COMMENTS -COMMIT -COMMITTED -COMPRESSION -CONCURRENTLY -CONFIGURATION -CONFLICT -CONNECTION -CONSTRAINT -CONSTRAINTS -CONTENT -CONTINUE -CONVERSION -COPY -COST -CREATE -CROSS -CSV -CUBE -CURRENT -CURSOR -CYCLE -DATA -DATABASE -DAY -DAYS -DEALLOCATE -DEC -DECADE -DECADES -DECIMAL -DECLARE -DEFAULT -DEFAULTS -DEFERRABLE -DEFERRED -DEFINER -DELETE -DELIMITER -DELIMITERS -DEPENDS -DESC -DESCRIBE -DETACH -DICTIONARY -DISABLE -DISCARD -DISTINCT -DO -DOCUMENT -DOMAIN -DOUBLE -DROP -EACH -ELSE -ENABLE -ENCODING -ENCRYPTED -END -ENUM -ESCAPE -EVENT -EXCEPT -EXCLUDE -EXCLUDING -EXCLUSIVE -EXECUTE -EXISTS -EXPLAIN -EXPORT -EXPORT_STATE -EXTENSION -EXTERNAL -EXTRACT -FALSE -FAMILY -FETCH -FILTER -FIRST -FLOAT -FOLLOWING -FOR -FORCE -FOREIGN -FORWARD -FREEZE -FROM -FULL -FUNCTION -FUNCTIONS -GENERATED -GLOB -GLOBAL -GRANT -GRANTED -GROUP -GROUPING -GROUPING_ID -GROUPS -HANDLER -HAVING -HEADER -HOLD -HOUR -HOURS -IDENTITY -IF -IGNORE -ILIKE -IMMEDIATE -IMMUTABLE -IMPLICIT -IMPORT -IN -INCLUDE -INCLUDING -INCREMENT -INDEX -INDEXES -INHERIT -INHERITS -INITIALLY -INLINE -INNER -INOUT -INPUT -INSENSITIVE -INSERT -INSTALL -INSTEAD -INT -INTEGER -INTERSECT -INTERVAL -INTO -INVOKER -IS -ISNULL -ISOLATION -JOIN -JSON -KEY -LABEL -LANGUAGE -LARGE -LAST -LATERAL -LEADING -LEAKPROOF -LEFT -LEVEL -LIKE -LIMIT -LISTEN -LOAD -LOCAL -LOCATION -LOCK -LOCKED -LOGGED -MACRO -MAP -MAPPING -MATCH -MATERIALIZED -MAXVALUE -METHOD -MICROSECOND -MICROSECONDS -MILLENNIA -MILLENNIUM -MILLISECOND -MILLISECONDS -MINUTE -MINUTES -MINVALUE -MODE -MONTH -MONTHS -MOVE -NAME -NAMES -NATIONAL -NATURAL -NCHAR -NEW -NEXT -NO -NONE -NOT -NOTHING -NOTIFY -NOTNULL -NOWAIT -NULL -NULLIF -NULLS -NUMERIC -OBJECT -OF -OFF -OFFSET -OIDS -OLD -ON -ONLY -OPERATOR -OPTION -OPTIONS -OR -ORDER -ORDINALITY -OTHERS -OUT -OUTER -OVER -OVERLAPS -OVERLAY -OVERRIDING -OWNED -OWNER -PARALLEL -PARSER -PARTIAL -PARTITION -PASSING -PASSWORD -PERCENT -PERSISTENT -PIVOT -PIVOT_LONGER -PIVOT_WIDER -PLACING -PLANS -POLICY -POSITION -POSITIONAL -PRAGMA -PRECEDING -PRECISION -PREPARE -PREPARED -PRESERVE -PRIMARY -PRIOR -PRIVILEGES -PROCEDURAL -PROCEDURE -PROGRAM -PUBLICATION -QUALIFY -QUOTE -RANGE -READ -REAL -REASSIGN -RECHECK -RECURSIVE -REF -REFERENCES -REFERENCING -REFRESH -REINDEX -RELATIVE -RELEASE -RENAME -REPEATABLE -REPLACE -REPLICA -RESET -RESPECT -RESTART -RESTRICT -RETURNING -RETURNS -REVOKE -RIGHT -ROLE -ROLLBACK -ROLLUP -ROW -ROWS -RULE -SAMPLE -SAVEPOINT -SCHEMA -SCHEMAS -SCOPE -SCROLL -SEARCH -SECOND -SECONDS -SECRET -SECURITY -SELECT -SEMI -SEQUENCE -SEQUENCES -SERIALIZABLE -SERVER -SESSION -SET -SETOF -SETS -SHARE -SHOW -SIMILAR -SIMPLE -SKIP -SMALLINT -SNAPSHOT -SOME -SQL -STABLE -STANDALONE -START -STATEMENT -STATISTICS -STDIN -STDOUT -STORAGE -STORED -STRICT -STRIP -STRUCT -SUBSCRIPTION -SUBSTRING -SUMMARIZE -SYMMETRIC -SYSID -SYSTEM -TABLE -TABLES -TABLESAMPLE -TABLESPACE -TEMP -TEMPLATE -TEMPORARY -TEXT -THEN -TIES -TIME -TIMESTAMP -TO -TRAILING -TRANSACTION -TRANSFORM -TREAT -TRIGGER -TRIM -TRUE -TRUNCATE -TRUSTED -TRY_CAST -TYPE -TYPES -UNBOUNDED -UNCOMMITTED -UNENCRYPTED -UNION -UNIQUE -UNKNOWN -UNLISTEN -UNLOGGED -UNPIVOT -UNTIL -UPDATE -USE -USER -USING -VACUUM -VALID -VALIDATE -VALIDATOR -VALUE -VALUES -VARCHAR -VARIADIC -VARYING -VERBOSE -VERSION -VIEW -VIEWS -VIRTUAL -VOLATILE -WEEK -WEEKS -WHEN -WHERE -WHITESPACE -WINDOW -WITH -WITHIN -WITHOUT -WORK -WRAPPER -WRITE -XML -XMLATTRIBUTES -XMLCONCAT -XMLELEMENT -XMLEXISTS -XMLFOREST -XMLNAMESPACES -XMLPARSE -XMLPI -XMLROOT -XMLSERIALIZE -XMLTABLE -YEAR -YEARS -YES -ZONE diff --git a/duckdb_types.txt b/duckdb_types.txt deleted file mode 100644 index e58d37a2ef..0000000000 --- a/duckdb_types.txt +++ /dev/null @@ -1,33 +0,0 @@ -BIGINT -BIT -BLOB -BOOLEAN -DATE -DECIMAL -DOUBLE -ENUM -FLOAT -HUGEINT -INTEGER -INTERVAL -LIST -MAP -NULL -SMALLINT -STRUCT -TIME -TIME WITH TIME ZONE -TIMESTAMP -TIMESTAMP WITH TIME ZONE -TIMESTAMP_MS -TIMESTAMP_NS -TIMESTAMP_S -TINYINT -UBIGINT -UHUGEINT -UINTEGER -UNION -USMALLINT -UTINYINT -UUID -VARCHAR diff --git a/duckdb_words.sql b/duckdb_words.sql deleted file mode 100644 index bb7b7ee053..0000000000 --- a/duckdb_words.sql +++ /dev/null @@ -1,20 +0,0 @@ -COPY ( - SELECT DISTINCT upper(function_name) AS function_name - FROM duckdb_functions() - WHERE function_name SIMILAR TO '^[a-z].*' - ORDER BY function_name -) TO 'duckdb_functions.txt' WITH (sep ',', header FALSE); - - -COPY ( - SELECT upper(keyword_name) - FROM duckdb_keywords() - ORDER BY keyword_name -) TO 'duckdb_keywords.txt' WITH (sep ',', header FALSE); - - -COPY ( - SELECT DISTINCT upper(logical_type) - FROM duckdb_types() - ORDER BY logical_type -) TO 'duckdb_types.txt' WITH (sep ',', header FALSE); \ No newline at end of file From 879eb5ff7b7c60ab5958b6dc311781953fd90f5c Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Tue, 30 Apr 2024 17:13:27 +1000 Subject: [PATCH 07/24] Add duckdb to docs --- docs/dialect.md | 2 ++ docs/language.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/docs/dialect.md b/docs/dialect.md index 798f3cc7c5..49ce69594b 100644 --- a/docs/dialect.md +++ b/docs/dialect.md @@ -24,6 +24,7 @@ The following dialects can be imported from `"sql-formatter"` module: - `bigquery` - [GCP BigQuery][] - `db2` - [IBM DB2][] - `db2i` - [IBM DB2i][] (experimental) +- `"duckdb"` - [duckdb][] - `hive` - [Apache Hive][] - `mariadb` - [MariaDB][] - `mysql` - [MySQL][] @@ -78,6 +79,7 @@ You likely only want to use this if your other alternative is to fork SQL Format [mysql]: https://www.mysql.com/ [tidb]: https://github.com/pingcap/tidb/ [couchbase n1ql]: http://www.couchbase.com/n1ql +[duckdb]: https://duckdb.org/ [oracle pl/sql]: http://www.oracle.com/technetwork/database/features/plsql/index.html [postgresql]: https://www.postgresql.org/ [presto]: https://prestodb.io/docs/current/ diff --git a/docs/language.md b/docs/language.md index 83b0328c98..13d019437f 100644 --- a/docs/language.md +++ b/docs/language.md @@ -16,6 +16,7 @@ const result = format('SELECT * FROM tbl', { dialect: 'sqlite' }); - `"bigquery"` - [GCP BigQuery][] - `"db2"` - [IBM DB2][] - `"db2i"` - [IBM DB2i][] (experimental) +- `"duckdb"` - [duckdb][] - `"hive"` - [Apache Hive][] - `"mariadb"` - [MariaDB][] - `"mysql"` - [MySQL][] @@ -55,6 +56,7 @@ See docs for [dialect][] option. [mysql]: https://www.mysql.com/ [tidb]: https://github.com/pingcap/tidb/ [couchbase n1ql]: http://www.couchbase.com/n1ql +[duckdb]: https://duckdb.org/ [oracle pl/sql]: http://www.oracle.com/technetwork/database/features/plsql/index.html [postgresql]: https://www.postgresql.org/ [presto]: https://prestodb.io/docs/current/ From 42abaf525267f08b6ea21dfead4d21194c0b6af4 Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Tue, 30 Apr 2024 19:53:51 +1000 Subject: [PATCH 08/24] Reduce keyword list to reserved only. --- src/languages/duckdb/duckdb.keywords.ts | 402 +----------------------- 1 file changed, 1 insertion(+), 401 deletions(-) diff --git a/src/languages/duckdb/duckdb.keywords.ts b/src/languages/duckdb/duckdb.keywords.ts index 1f4cc82840..c5946c2e10 100644 --- a/src/languages/duckdb/duckdb.keywords.ts +++ b/src/languages/duckdb/duckdb.keywords.ts @@ -1,480 +1,80 @@ export const keywords: string[] = [ - 'ABORT', - 'ABSOLUTE', - 'ACCESS', - 'ACTION', - 'ADD', - 'ADMIN', - 'AFTER', - 'AGGREGATE', 'ALL', - 'ALSO', - 'ALTER', - 'ALWAYS', 'ANALYSE', 'ANALYZE', 'AND', - 'ANTI', 'ANY', 'ARRAY', 'AS', 'ASC', - 'ASOF', - 'ASSERTION', - 'ASSIGNMENT', 'ASYMMETRIC', - 'AT', - 'ATTACH', - 'ATTRIBUTE', - 'AUTHORIZATION', - 'BACKWARD', - 'BEFORE', - 'BEGIN', - 'BETWEEN', - 'BIGINT', - 'BINARY', - 'BIT', - 'BOOLEAN', 'BOTH', - 'BY', - 'CACHE', - 'CALL', - 'CALLED', - 'CASCADE', - 'CASCADED', 'CASE', 'CAST', - 'CATALOG', - 'CENTURIES', - 'CENTURY', - 'CHAIN', - 'CHAR', - 'CHARACTER', - 'CHARACTERISTICS', 'CHECK', - 'CHECKPOINT', - 'CLASS', - 'CLOSE', - 'CLUSTER', - 'COALESCE', 'COLLATE', - 'COLLATION', 'COLUMN', - 'COLUMNS', - 'COMMENT', - 'COMMENTS', - 'COMMIT', - 'COMMITTED', - 'COMPRESSION', - 'CONCURRENTLY', - 'CONFIGURATION', - 'CONFLICT', - 'CONNECTION', 'CONSTRAINT', - 'CONSTRAINTS', - 'CONTENT', - 'CONTINUE', - 'CONVERSION', - 'COPY', - 'COST', 'CREATE', - 'CROSS', - 'CSV', - 'CUBE', - 'CURRENT', - 'CURSOR', - 'CYCLE', - 'DATA', - 'DATABASE', - 'DAY', - 'DAYS', - 'DEALLOCATE', - 'DEC', - 'DECADE', - 'DECADES', - 'DECIMAL', - 'DECLARE', 'DEFAULT', - 'DEFAULTS', 'DEFERRABLE', - 'DEFERRED', - 'DEFINER', - 'DELETE', - 'DELIMITER', - 'DELIMITERS', - 'DEPENDS', 'DESC', 'DESCRIBE', - 'DETACH', - 'DICTIONARY', - 'DISABLE', - 'DISCARD', 'DISTINCT', 'DO', - 'DOCUMENT', - 'DOMAIN', - 'DOUBLE', - 'DROP', - 'EACH', 'ELSE', - 'ENABLE', - 'ENCODING', - 'ENCRYPTED', 'END', - 'ENUM', - 'ESCAPE', - 'EVENT', 'EXCEPT', - 'EXCLUDE', - 'EXCLUDING', - 'EXCLUSIVE', - 'EXECUTE', - 'EXISTS', - 'EXPLAIN', - 'EXPORT', - 'EXPORT_STATE', - 'EXTENSION', - 'EXTERNAL', - 'EXTRACT', 'FALSE', - 'FAMILY', 'FETCH', - 'FILTER', - 'FIRST', - 'FLOAT', - 'FOLLOWING', 'FOR', - 'FORCE', 'FOREIGN', - 'FORWARD', - 'FREEZE', 'FROM', - 'FULL', - 'FUNCTION', - 'FUNCTIONS', - 'GENERATED', - 'GLOB', - 'GLOBAL', 'GRANT', - 'GRANTED', 'GROUP', - 'GROUPING', - 'GROUPING_ID', - 'GROUPS', - 'HANDLER', 'HAVING', - 'HEADER', - 'HOLD', - 'HOUR', - 'HOURS', - 'IDENTITY', - 'IF', - 'IGNORE', - 'ILIKE', - 'IMMEDIATE', - 'IMMUTABLE', - 'IMPLICIT', - 'IMPORT', 'IN', - 'INCLUDE', - 'INCLUDING', - 'INCREMENT', - 'INDEX', - 'INDEXES', - 'INHERIT', - 'INHERITS', 'INITIALLY', - 'INLINE', - 'INNER', - 'INOUT', - 'INPUT', - 'INSENSITIVE', - 'INSERT', - 'INSTALL', - 'INSTEAD', - 'INT', - 'INTEGER', 'INTERSECT', - 'INTERVAL', 'INTO', - 'INVOKER', - 'IS', - 'ISNULL', - 'ISOLATION', - 'JOIN', - 'JSON', - 'KEY', - 'LABEL', - 'LANGUAGE', - 'LARGE', - 'LAST', 'LATERAL', 'LEADING', - 'LEAKPROOF', - 'LEFT', - 'LEVEL', - 'LIKE', 'LIMIT', - 'LISTEN', - 'LOAD', - 'LOCAL', - 'LOCATION', - 'LOCK', - 'LOCKED', - 'LOGGED', - 'MACRO', - 'MAP', - 'MAPPING', - 'MATCH', - 'MATERIALIZED', - 'MAXVALUE', - 'METHOD', - 'MICROSECOND', - 'MICROSECONDS', - 'MILLENNIA', - 'MILLENNIUM', - 'MILLISECOND', - 'MILLISECONDS', - 'MINUTE', - 'MINUTES', - 'MINVALUE', - 'MODE', - 'MONTH', - 'MONTHS', - 'MOVE', - 'NAME', - 'NAMES', - 'NATIONAL', - 'NATURAL', - 'NCHAR', - 'NEW', - 'NEXT', - 'NO', - 'NONE', 'NOT', - 'NOTHING', - 'NOTIFY', - 'NOTNULL', - 'NOWAIT', 'NULL', - 'NULLIF', - 'NULLS', - 'NUMERIC', - 'OBJECT', - 'OF', - 'OFF', 'OFFSET', - 'OIDS', - 'OLD', 'ON', 'ONLY', - 'OPERATOR', - 'OPTION', - 'OPTIONS', 'OR', 'ORDER', - 'ORDINALITY', - 'OTHERS', - 'OUT', - 'OUTER', - 'OVER', - 'OVERLAPS', - 'OVERLAY', - 'OVERRIDING', - 'OWNED', - 'OWNER', - 'PARALLEL', - 'PARSER', - 'PARTIAL', - 'PARTITION', - 'PASSING', - 'PASSWORD', - 'PERCENT', - 'PERSISTENT', 'PIVOT', 'PIVOT_LONGER', 'PIVOT_WIDER', 'PLACING', - 'PLANS', - 'POLICY', - 'POSITION', - 'POSITIONAL', - 'PRAGMA', - 'PRECEDING', - 'PRECISION', - 'PREPARE', - 'PREPARED', - 'PRESERVE', 'PRIMARY', - 'PRIOR', - 'PRIVILEGES', - 'PROCEDURAL', - 'PROCEDURE', - 'PROGRAM', - 'PUBLICATION', 'QUALIFY', - 'QUOTE', - 'RANGE', - 'READ', - 'REAL', - 'REASSIGN', - 'RECHECK', - 'RECURSIVE', - 'REF', 'REFERENCES', - 'REFERENCING', - 'REFRESH', - 'REINDEX', - 'RELATIVE', - 'RELEASE', - 'RENAME', - 'REPEATABLE', - 'REPLACE', - 'REPLICA', - 'RESET', - 'RESPECT', - 'RESTART', - 'RESTRICT', 'RETURNING', - 'RETURNS', - 'REVOKE', - 'RIGHT', - 'ROLE', - 'ROLLBACK', - 'ROLLUP', - 'ROW', - 'ROWS', - 'RULE', - 'SAMPLE', - 'SAVEPOINT', - 'SCHEMA', - 'SCHEMAS', - 'SCOPE', - 'SCROLL', - 'SEARCH', - 'SECOND', - 'SECONDS', - 'SECRET', - 'SECURITY', 'SELECT', - 'SEMI', - 'SEQUENCE', - 'SEQUENCES', - 'SERIALIZABLE', - 'SERVER', - 'SESSION', - 'SET', - 'SETOF', - 'SETS', - 'SHARE', 'SHOW', - 'SIMILAR', - 'SIMPLE', - 'SKIP', - 'SMALLINT', - 'SNAPSHOT', 'SOME', - 'SQL', - 'STABLE', - 'STANDALONE', - 'START', - 'STATEMENT', - 'STATISTICS', - 'STDIN', - 'STDOUT', - 'STORAGE', - 'STORED', - 'STRICT', - 'STRIP', - 'STRUCT', - 'SUBSCRIPTION', - 'SUBSTRING', 'SUMMARIZE', 'SYMMETRIC', - 'SYSID', - 'SYSTEM', 'TABLE', - 'TABLES', - 'TABLESAMPLE', - 'TABLESPACE', - 'TEMP', - 'TEMPLATE', - 'TEMPORARY', - 'TEXT', 'THEN', - 'TIES', - 'TIME', - 'TIMESTAMP', 'TO', 'TRAILING', - 'TRANSACTION', - 'TRANSFORM', - 'TREAT', - 'TRIGGER', - 'TRIM', 'TRUE', - 'TRUNCATE', - 'TRUSTED', - 'TRY_CAST', - 'TYPE', - 'TYPES', - 'UNBOUNDED', - 'UNCOMMITTED', - 'UNENCRYPTED', 'UNION', 'UNIQUE', - 'UNKNOWN', - 'UNLISTEN', - 'UNLOGGED', 'UNPIVOT', - 'UNTIL', - 'UPDATE', - 'USE', - 'USER', 'USING', - 'VACUUM', - 'VALID', - 'VALIDATE', - 'VALIDATOR', - 'VALUE', - 'VALUES', - 'VARCHAR', 'VARIADIC', - 'VARYING', - 'VERBOSE', - 'VERSION', - 'VIEW', - 'VIEWS', - 'VIRTUAL', - 'VOLATILE', - 'WEEK', - 'WEEKS', 'WHEN', 'WHERE', - 'WHITESPACE', 'WINDOW', 'WITH', - 'WITHIN', - 'WITHOUT', - 'WORK', - 'WRAPPER', - 'WRITE', - 'XML', - 'XMLATTRIBUTES', - 'XMLCONCAT', - 'XMLELEMENT', - 'XMLEXISTS', - 'XMLFOREST', - 'XMLNAMESPACES', - 'XMLPARSE', - 'XMLPI', - 'XMLROOT', - 'XMLSERIALIZE', - 'XMLTABLE', - 'YEAR', - 'YEARS', - 'YES', - 'ZONE', + ]; export const dataTypes: string[] = [ From 57f272ac763e49e91930e1be1ecd00520a6fb1ff Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Tue, 30 Apr 2024 20:14:54 +1000 Subject: [PATCH 09/24] Extend Data Types List --- src/languages/duckdb/duckdb.keywords.ts | 45 +++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/languages/duckdb/duckdb.keywords.ts b/src/languages/duckdb/duckdb.keywords.ts index c5946c2e10..7e943dfacc 100644 --- a/src/languages/duckdb/duckdb.keywords.ts +++ b/src/languages/duckdb/duckdb.keywords.ts @@ -78,37 +78,78 @@ export const keywords: string[] = [ ]; export const dataTypes: string[] = [ + 'INET', + 'JSON', 'BIGINT', + 'BINARY', 'BIT', + 'BITSTRING', 'BLOB', + 'BOOL', 'BOOLEAN', + 'BPCHAR', + 'BYTEA', + 'CHAR', 'DATE', + 'DATETIME', + 'DEC', 'DECIMAL', 'DOUBLE', 'ENUM', 'FLOAT', + 'FLOAT4', + 'FLOAT8', + 'GUID', 'HUGEINT', + 'INT', + 'INT1', + 'INT128', + 'INT16', + 'INT2', + 'INT32', + 'INT4', + 'INT64', + 'INT8', 'INTEGER', + 'INTEGRAL', 'INTERVAL', 'LIST', + 'LOGICAL', + 'LONG', 'MAP', 'NULL', + 'NUMERIC', + 'NVARCHAR', + 'OID', + 'REAL', + 'ROW', + 'SHORT', + 'SIGNED', 'SMALLINT', + 'STRING', 'STRUCT', + 'TEXT', 'TIME', - 'TIME WITH TIME ZONE', 'TIMESTAMP', - 'TIMESTAMP WITH TIME ZONE', 'TIMESTAMP_MS', 'TIMESTAMP_NS', 'TIMESTAMP_S', + 'TIMESTAMP_US', + 'TIMESTAMPTZ', + 'TIMETZ', 'TINYINT', 'UBIGINT', 'UHUGEINT', + 'UINT128', + 'UINT16', + 'UINT32', + 'UINT64', + 'UINT8', 'UINTEGER', 'UNION', 'USMALLINT', 'UTINYINT', 'UUID', + 'VARBINARY', 'VARCHAR', ]; From 5da1023e4183e5e763f16834616703d569f94881 Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Tue, 30 Apr 2024 20:19:00 +1000 Subject: [PATCH 10/24] Drop INT from functions --- src/languages/duckdb/duckdb.functions.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/languages/duckdb/duckdb.functions.ts b/src/languages/duckdb/duckdb.functions.ts index 6aeb36c9a7..fe87957006 100644 --- a/src/languages/duckdb/duckdb.functions.ts +++ b/src/languages/duckdb/duckdb.functions.ts @@ -659,5 +659,4 @@ export const functions: string[] = [ 'NULL', 'RANK', 'ROW_NUMBER', - 'INT', ]; From 826ee55347dd2978d82fe1700879b860f0e28328 Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Wed, 1 May 2024 08:44:37 +1000 Subject: [PATCH 11/24] Adding clauses by @PMassicotte --- src/languages/duckdb/duckdb.formatter.ts | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/languages/duckdb/duckdb.formatter.ts b/src/languages/duckdb/duckdb.formatter.ts index b8c6881799..b8508f4ada 100644 --- a/src/languages/duckdb/duckdb.formatter.ts +++ b/src/languages/duckdb/duckdb.formatter.ts @@ -3,7 +3,9 @@ import { expandPhrases } from '../../expandPhrases.js'; import { functions } from './duckdb.functions.js'; import { dataTypes, keywords } from './duckdb.keywords.js'; -const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT]']); +const reservedSelect = expandPhrases([ + 'SELECT [ALL | DISTINCT | EXCLUDE | REPLACE]', +]); const reservedClauses = expandPhrases([ // queries @@ -201,6 +203,7 @@ const tabularOnelineClauses = expandPhrases([ 'EXPLAIN', 'FETCH', 'GRANT', + 'INSTALL', 'IMPORT FOREIGN SCHEMA', 'LISTEN', 'LOAD', @@ -231,19 +234,17 @@ const tabularOnelineClauses = expandPhrases([ 'VACUUM', ]); -const reservedSetOperations = expandPhrases([ - 'UNION [ALL | DISTINCT]', - 'EXCEPT [ALL | DISTINCT]', - 'INTERSECT [ALL | DISTINCT]', -]); - -const reservedJoins = expandPhrases([ - 'JOIN', - '{LEFT | RIGHT | FULL} [OUTER] JOIN', - '{INNER | CROSS} JOIN', - 'NATURAL [INNER] JOIN', - 'NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN', -]); +const reservedJoins = expandPhrases([ + 'ASOF {LEFT} JOIN', + 'JOIN', + 'NATURAL [INNER] JOIN', + 'NATURAL [LEFT] {ANTI | SEMI} JOIN', + 'NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN', + 'POSITIONAL JOIN', + '[LEFT] {ANTI | SEMI} JOIN', + '{INNER | CROSS} JOIN', + '{LEFT | RIGHT | FULL} [OUTER] JOIN', +]); const reservedPhrases = expandPhrases([ 'PRIMARY KEY', From 7f308149b2b4f473203beef386674aceec6681aa Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Wed, 1 May 2024 08:48:04 +1000 Subject: [PATCH 12/24] Restate reservedSetOperations --- src/languages/duckdb/duckdb.formatter.ts | 34 ++++++++++++++---------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/languages/duckdb/duckdb.formatter.ts b/src/languages/duckdb/duckdb.formatter.ts index b8508f4ada..df856324de 100644 --- a/src/languages/duckdb/duckdb.formatter.ts +++ b/src/languages/duckdb/duckdb.formatter.ts @@ -3,9 +3,9 @@ import { expandPhrases } from '../../expandPhrases.js'; import { functions } from './duckdb.functions.js'; import { dataTypes, keywords } from './duckdb.keywords.js'; -const reservedSelect = expandPhrases([ - 'SELECT [ALL | DISTINCT | EXCLUDE | REPLACE]', -]); +const reservedSelect = expandPhrases([ + 'SELECT [ALL | DISTINCT | EXCLUDE | REPLACE]', +]); const reservedClauses = expandPhrases([ // queries @@ -234,17 +234,23 @@ const tabularOnelineClauses = expandPhrases([ 'VACUUM', ]); -const reservedJoins = expandPhrases([ - 'ASOF {LEFT} JOIN', - 'JOIN', - 'NATURAL [INNER] JOIN', - 'NATURAL [LEFT] {ANTI | SEMI} JOIN', - 'NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN', - 'POSITIONAL JOIN', - '[LEFT] {ANTI | SEMI} JOIN', - '{INNER | CROSS} JOIN', - '{LEFT | RIGHT | FULL} [OUTER] JOIN', -]); +const reservedSetOperations = expandPhrases([ + 'UNION [ALL | DISTINCT]', + 'EXCEPT [ALL | DISTINCT]', + 'INTERSECT [ALL | DISTINCT]', +]); + +const reservedJoins = expandPhrases([ + 'ASOF {LEFT} JOIN', + 'JOIN', + 'NATURAL [INNER] JOIN', + 'NATURAL [LEFT] {ANTI | SEMI} JOIN', + 'NATURAL {LEFT | RIGHT | FULL} [OUTER] JOIN', + 'POSITIONAL JOIN', + '[LEFT] {ANTI | SEMI} JOIN', + '{INNER | CROSS} JOIN', + '{LEFT | RIGHT | FULL} [OUTER] JOIN', +]); const reservedPhrases = expandPhrases([ 'PRIMARY KEY', From eb7d9b1ecfb2adefbd41b563ab68015faa073980 Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Fri, 3 May 2024 08:31:45 +1000 Subject: [PATCH 13/24] Function Updates - Tests Success --- src/languages/duckdb/duckdb.functions.ts | 2 -- src/languages/duckdb/duckdb.keywords.ts | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/languages/duckdb/duckdb.functions.ts b/src/languages/duckdb/duckdb.functions.ts index fe87957006..962a6bf078 100644 --- a/src/languages/duckdb/duckdb.functions.ts +++ b/src/languages/duckdb/duckdb.functions.ts @@ -68,7 +68,6 @@ export const functions: string[] = [ 'ATAN', 'ATAN2', 'AVG', - 'BAR', 'BASE64', 'BIN', 'BITSTRING', @@ -653,7 +652,6 @@ export const functions: string[] = [ 'YEARWEEK', // Keywords that also need to be listed as functions - 'ARRAY', 'CAST', 'COALESCE', 'NULL', diff --git a/src/languages/duckdb/duckdb.keywords.ts b/src/languages/duckdb/duckdb.keywords.ts index 7e943dfacc..a150bb1665 100644 --- a/src/languages/duckdb/duckdb.keywords.ts +++ b/src/languages/duckdb/duckdb.keywords.ts @@ -4,7 +4,6 @@ export const keywords: string[] = [ 'ANALYZE', 'AND', 'ANY', - 'ARRAY', 'AS', 'ASC', 'ASYMMETRIC', @@ -78,8 +77,7 @@ export const keywords: string[] = [ ]; export const dataTypes: string[] = [ - 'INET', - 'JSON', + 'ARRAY', 'BIGINT', 'BINARY', 'BIT', @@ -101,6 +99,7 @@ export const dataTypes: string[] = [ 'FLOAT8', 'GUID', 'HUGEINT', + 'INET', 'INT', 'INT1', 'INT128', @@ -113,6 +112,7 @@ export const dataTypes: string[] = [ 'INTEGER', 'INTEGRAL', 'INTERVAL', + 'JSON', 'LIST', 'LOGICAL', 'LONG', @@ -130,11 +130,11 @@ export const dataTypes: string[] = [ 'STRUCT', 'TEXT', 'TIME', - 'TIMESTAMP', 'TIMESTAMP_MS', 'TIMESTAMP_NS', 'TIMESTAMP_S', 'TIMESTAMP_US', + 'TIMESTAMP', 'TIMESTAMPTZ', 'TIMETZ', 'TINYINT', From 925dd49519f04239ac7eea34aa6c1ecc267f87e6 Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Fri, 3 May 2024 08:32:47 +1000 Subject: [PATCH 14/24] Run Yarn Pretty --- .pre-commit-hooks.yaml | 12 ++++++------ src/languages/duckdb/duckdb.formatter.ts | 4 +--- src/languages/duckdb/duckdb.keywords.ts | 1 - 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index dd05051561..a850a3d93c 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,6 +1,6 @@ -- id: sql-formatter - name: sql-formatter - description: "Reformat SQL files with sql-formatter" - entry: sql-formatter --fix - language: node - types: [sql] +- id: sql-formatter + name: sql-formatter + description: 'Reformat SQL files with sql-formatter' + entry: sql-formatter --fix + language: node + types: [sql] diff --git a/src/languages/duckdb/duckdb.formatter.ts b/src/languages/duckdb/duckdb.formatter.ts index df856324de..6e80897517 100644 --- a/src/languages/duckdb/duckdb.formatter.ts +++ b/src/languages/duckdb/duckdb.formatter.ts @@ -3,9 +3,7 @@ import { expandPhrases } from '../../expandPhrases.js'; import { functions } from './duckdb.functions.js'; import { dataTypes, keywords } from './duckdb.keywords.js'; -const reservedSelect = expandPhrases([ - 'SELECT [ALL | DISTINCT | EXCLUDE | REPLACE]', -]); +const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT | EXCLUDE | REPLACE]']); const reservedClauses = expandPhrases([ // queries diff --git a/src/languages/duckdb/duckdb.keywords.ts b/src/languages/duckdb/duckdb.keywords.ts index a150bb1665..23a750ac33 100644 --- a/src/languages/duckdb/duckdb.keywords.ts +++ b/src/languages/duckdb/duckdb.keywords.ts @@ -73,7 +73,6 @@ export const keywords: string[] = [ 'WHERE', 'WINDOW', 'WITH', - ]; export const dataTypes: string[] = [ From 08182dc77f6cee72be83b3beec3e4c25a42424bb Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Fri, 3 May 2024 08:41:17 +1000 Subject: [PATCH 15/24] Small fixes --- .pre-commit-hooks.yaml | 12 ++++++------ docs/dialect.md | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index a850a3d93c..2c8a8a9e98 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,6 +1,6 @@ -- id: sql-formatter - name: sql-formatter - description: 'Reformat SQL files with sql-formatter' - entry: sql-formatter --fix - language: node - types: [sql] +- id: sql-formatter + name: sql-formatter + description: "Reformat SQL files with sql-formatter" + entry: sql-formatter --fix + language: node + types: [sql] \ No newline at end of file diff --git a/docs/dialect.md b/docs/dialect.md index 49ce69594b..cb9dd66b23 100644 --- a/docs/dialect.md +++ b/docs/dialect.md @@ -24,7 +24,7 @@ The following dialects can be imported from `"sql-formatter"` module: - `bigquery` - [GCP BigQuery][] - `db2` - [IBM DB2][] - `db2i` - [IBM DB2i][] (experimental) -- `"duckdb"` - [duckdb][] +- `duckdb` - [duckdb][] - `hive` - [Apache Hive][] - `mariadb` - [MariaDB][] - `mysql` - [MySQL][] From 348eeacd1a5d655289110063c11d4c1e8e113a9c Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Fri, 3 May 2024 08:42:11 +1000 Subject: [PATCH 16/24] pre-commit-hooks new line --- .pre-commit-hooks.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 2c8a8a9e98..dd05051561 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -3,4 +3,4 @@ description: "Reformat SQL files with sql-formatter" entry: sql-formatter --fix language: node - types: [sql] \ No newline at end of file + types: [sql] From 159911fe6e8ebb7ac04ba5f9bddf76d72739ebcd Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Tue, 21 May 2024 15:09:56 +1000 Subject: [PATCH 17/24] Share source query on keywords & functions --- src/languages/duckdb/duckdb.functions.ts | 5 +++++ src/languages/duckdb/duckdb.keywords.ts | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/languages/duckdb/duckdb.functions.ts b/src/languages/duckdb/duckdb.functions.ts index 962a6bf078..b08e14029b 100644 --- a/src/languages/duckdb/duckdb.functions.ts +++ b/src/languages/duckdb/duckdb.functions.ts @@ -1,4 +1,9 @@ export const functions: string[] = [ + // Functions from DuckDB (excluding those that start with an underscore): + // SELECT DISTINCT upper(function_name) AS function_name + // FROM duckdb_functions() + // WHERE function_name SIMILAR TO '^[a-z].*' + // ORDER BY function_name 'ABS', 'ACOS', 'ADD', diff --git a/src/languages/duckdb/duckdb.keywords.ts b/src/languages/duckdb/duckdb.keywords.ts index 23a750ac33..720925c239 100644 --- a/src/languages/duckdb/duckdb.keywords.ts +++ b/src/languages/duckdb/duckdb.keywords.ts @@ -1,4 +1,9 @@ export const keywords: string[] = [ + // Keywords from DuckDB: + // SELECT upper(keyword_name) + // FROM duckdb_keywords() + // WHERE keyword_category = 'reserved' + // ORDER BY keyword_name 'ALL', 'ANALYSE', 'ANALYZE', @@ -76,6 +81,10 @@ export const keywords: string[] = [ ]; export const dataTypes: string[] = [ + // Types from DuckDB: + // SELECT DISTINCT upper(type_name) + // FROM duckdb_types() + // ORDER BY type_name 'ARRAY', 'BIGINT', 'BINARY', From 0c6a830010f5251eb3c57e1e2a65d77182944235 Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Sun, 2 Jun 2024 08:17:56 +1000 Subject: [PATCH 18/24] Amend Set Operations --- src/languages/duckdb/duckdb.formatter.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/languages/duckdb/duckdb.formatter.ts b/src/languages/duckdb/duckdb.formatter.ts index 6e80897517..e57fa274ad 100644 --- a/src/languages/duckdb/duckdb.formatter.ts +++ b/src/languages/duckdb/duckdb.formatter.ts @@ -233,9 +233,9 @@ const tabularOnelineClauses = expandPhrases([ ]); const reservedSetOperations = expandPhrases([ - 'UNION [ALL | DISTINCT]', - 'EXCEPT [ALL | DISTINCT]', - 'INTERSECT [ALL | DISTINCT]', + 'UNION [ALL] BY NAME', + 'EXCEPT [ALL]', + 'INTERSECT [ALL]', ]); const reservedJoins = expandPhrases([ From 179be69595398fb9daf394c892a76c1097b908ec Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Sun, 2 Jun 2024 08:21:21 +1000 Subject: [PATCH 19/24] Drop square and cube root --- src/languages/duckdb/duckdb.formatter.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/languages/duckdb/duckdb.formatter.ts b/src/languages/duckdb/duckdb.formatter.ts index e57fa274ad..954880d1da 100644 --- a/src/languages/duckdb/duckdb.formatter.ts +++ b/src/languages/duckdb/duckdb.formatter.ts @@ -286,8 +286,6 @@ export const duckdb: DialectOptions = { // Arithmetic '%', '^', - '|/', - '||/', '@', // Assignment ':=', From 8fb9a4f97fa97437f53d3b7f3cc720417605a071 Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Sun, 2 Jun 2024 08:30:47 +1000 Subject: [PATCH 20/24] Drop POSIX RegExp - not compatible --- src/languages/duckdb/duckdb.formatter.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/languages/duckdb/duckdb.formatter.ts b/src/languages/duckdb/duckdb.formatter.ts index 954880d1da..7686625faa 100644 --- a/src/languages/duckdb/duckdb.formatter.ts +++ b/src/languages/duckdb/duckdb.formatter.ts @@ -342,11 +342,8 @@ export const duckdb: DialectOptions = { '~~*', '!~~', '!~~*', - // POSIX RegExp '~', - '~*', '!~', - '!~*', // Range/multirange '-|-', // String concatenation From 9a56b6dadb0a0cc4948cfb84d9efcbb9cfbc666f Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Sun, 2 Jun 2024 09:52:09 +1000 Subject: [PATCH 21/24] Address Postrges DuckDB Differences --- src/languages/duckdb/duckdb.formatter.ts | 230 ++--------------------- 1 file changed, 16 insertions(+), 214 deletions(-) diff --git a/src/languages/duckdb/duckdb.formatter.ts b/src/languages/duckdb/duckdb.formatter.ts index 7686625faa..9474084eec 100644 --- a/src/languages/duckdb/duckdb.formatter.ts +++ b/src/languages/duckdb/duckdb.formatter.ts @@ -3,7 +3,7 @@ import { expandPhrases } from '../../expandPhrases.js'; import { functions } from './duckdb.functions.js'; import { dataTypes, keywords } from './duckdb.keywords.js'; -const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT | EXCLUDE | REPLACE]']); +const reservedSelect = expandPhrases(['SELECT [ALL | DISTINCT] [EXCLUDE | REPLACE]']); const reservedClauses = expandPhrases([ // queries @@ -17,8 +17,6 @@ const reservedClauses = expandPhrases([ 'ORDER BY', 'LIMIT', 'OFFSET', - 'FETCH {FIRST | NEXT}', - 'FOR {UPDATE | NO KEY UPDATE | SHARE | KEY SHARE} [OF]', // Data manipulation // - insert: 'INSERT INTO', @@ -31,205 +29,64 @@ const reservedClauses = expandPhrases([ ]); const standardOnelineClauses = expandPhrases([ - 'CREATE [GLOBAL | LOCAL] [TEMPORARY | TEMP | UNLOGGED] TABLE [IF NOT EXISTS]', + 'CREATE [OR REPLACE] [TEMP | TEMPORARY] TABLE', ]); const tabularOnelineClauses = expandPhrases([ // - create - 'CREATE [OR REPLACE] [TEMP | TEMPORARY] [RECURSIVE] VIEW', - 'CREATE [MATERIALIZED] VIEW [IF NOT EXISTS]', + 'CREATE [OR REPLACE] [TEMP | TEMPORARY] VIEW', // - update: - 'UPDATE [ONLY]', - 'WHERE CURRENT OF', + 'UPDATE', // - insert: 'ON CONFLICT', // - delete: - 'DELETE FROM [ONLY]', + 'DELETE FROM', // - drop table: 'DROP TABLE [IF EXISTS]', // - alter table: - 'ALTER TABLE [IF EXISTS] [ONLY]', + 'ALTER TABLE [IF EXISTS]', 'ALTER TABLE ALL IN TABLESPACE', 'RENAME [COLUMN]', 'RENAME TO', 'ADD [COLUMN] [IF NOT EXISTS]', 'DROP [COLUMN] [IF EXISTS]', + 'DROP [PERSISTENT] SECRET', + 'DROP [SEQUENCE | MACRO | FUNCTION | INDEX | TYPE | SCHEMA] [IF EXISTS]', + 'DROP [VIEW] [IF EXISTS]', 'ALTER [COLUMN]', 'SET DATA TYPE', // for alter column '{SET | DROP} DEFAULT', // for alter column '{SET | DROP} NOT NULL', // for alter column // - truncate: - 'TRUNCATE [TABLE] [ONLY]', + 'TRUNCATE [TABLE]', // other - 'SET SCHEMA', - 'AFTER', 'ABORT', - 'ALTER AGGREGATE', - 'ALTER COLLATION', - 'ALTER CONVERSION', - 'ALTER DATABASE', - 'ALTER DEFAULT PRIVILEGES', - 'ALTER DOMAIN', - 'ALTER EVENT TRIGGER', - 'ALTER EXTENSION', - 'ALTER FOREIGN DATA WRAPPER', - 'ALTER FOREIGN TABLE', - 'ALTER FUNCTION', - 'ALTER GROUP', - 'ALTER INDEX', - 'ALTER LANGUAGE', - 'ALTER LARGE OBJECT', - 'ALTER MATERIALIZED VIEW', - 'ALTER OPERATOR', - 'ALTER OPERATOR CLASS', - 'ALTER OPERATOR FAMILY', - 'ALTER POLICY', - 'ALTER PROCEDURE', - 'ALTER PUBLICATION', - 'ALTER ROLE', - 'ALTER ROUTINE', - 'ALTER RULE', - 'ALTER SCHEMA', - 'ALTER SEQUENCE', - 'ALTER SERVER', - 'ALTER STATISTICS', - 'ALTER SUBSCRIPTION', - 'ALTER SYSTEM', - 'ALTER TABLESPACE', - 'ALTER TEXT SEARCH CONFIGURATION', - 'ALTER TEXT SEARCH DICTIONARY', - 'ALTER TEXT SEARCH PARSER', - 'ALTER TEXT SEARCH TEMPLATE', - 'ALTER TRIGGER', - 'ALTER TYPE', - 'ALTER USER', - 'ALTER USER MAPPING', 'ALTER VIEW', 'ANALYZE', 'BEGIN', 'CALL', 'CHECKPOINT', - 'CLOSE', - 'CLUSTER', 'COMMIT', - 'COMMIT PREPARED', 'COPY', - 'CREATE ACCESS METHOD', - 'CREATE AGGREGATE', - 'CREATE CAST', - 'CREATE COLLATION', - 'CREATE CONVERSION', - 'CREATE DATABASE', - 'CREATE DOMAIN', - 'CREATE EVENT TRIGGER', - 'CREATE EXTENSION', - 'CREATE FOREIGN DATA WRAPPER', - 'CREATE FOREIGN TABLE', 'CREATE FUNCTION', - 'CREATE GROUP', 'CREATE INDEX', - 'CREATE LANGUAGE', - 'CREATE OPERATOR', - 'CREATE OPERATOR CLASS', - 'CREATE OPERATOR FAMILY', - 'CREATE POLICY', - 'CREATE PROCEDURE', - 'CREATE PUBLICATION', - 'CREATE ROLE', - 'CREATE RULE', + 'CREATE MACRO', 'CREATE SCHEMA', + 'CREATE SECRET', 'CREATE SEQUENCE', - 'CREATE SERVER', - 'CREATE STATISTICS', - 'CREATE SUBSCRIPTION', - 'CREATE TABLESPACE', - 'CREATE TEXT SEARCH CONFIGURATION', - 'CREATE TEXT SEARCH DICTIONARY', - 'CREATE TEXT SEARCH PARSER', - 'CREATE TEXT SEARCH TEMPLATE', - 'CREATE TRANSFORM', - 'CREATE TRIGGER', 'CREATE TYPE', - 'CREATE USER', - 'CREATE USER MAPPING', 'DEALLOCATE', 'DECLARE', - 'DISCARD', - 'DROP ACCESS METHOD', - 'DROP AGGREGATE', - 'DROP CAST', - 'DROP COLLATION', - 'DROP CONVERSION', - 'DROP DATABASE', - 'DROP DOMAIN', - 'DROP EVENT TRIGGER', - 'DROP EXTENSION', - 'DROP FOREIGN DATA WRAPPER', - 'DROP FOREIGN TABLE', - 'DROP FUNCTION', - 'DROP GROUP', - 'DROP INDEX', - 'DROP LANGUAGE', - 'DROP MATERIALIZED VIEW', - 'DROP OPERATOR', - 'DROP OPERATOR CLASS', - 'DROP OPERATOR FAMILY', - 'DROP OWNED', - 'DROP POLICY', - 'DROP PROCEDURE', - 'DROP PUBLICATION', - 'DROP ROLE', - 'DROP ROUTINE', - 'DROP RULE', - 'DROP SCHEMA', - 'DROP SEQUENCE', - 'DROP SERVER', - 'DROP STATISTICS', - 'DROP SUBSCRIPTION', - 'DROP TABLESPACE', - 'DROP TEXT SEARCH CONFIGURATION', - 'DROP TEXT SEARCH DICTIONARY', - 'DROP TEXT SEARCH PARSER', - 'DROP TEXT SEARCH TEMPLATE', - 'DROP TRANSFORM', - 'DROP TRIGGER', - 'DROP TYPE', - 'DROP USER', - 'DROP USER MAPPING', - 'DROP VIEW', 'EXECUTE', 'EXPLAIN', - 'FETCH', - 'GRANT', 'INSTALL', - 'IMPORT FOREIGN SCHEMA', - 'LISTEN', 'LOAD', - 'LOCK', - 'MOVE', - 'NOTIFY', 'PREPARE', - 'PREPARE TRANSACTION', - 'REASSIGN OWNED', - 'REFRESH MATERIALIZED VIEW', - 'REINDEX', - 'RELEASE SAVEPOINT', - 'RESET', - 'REVOKE', - 'ROLLBACK', - 'ROLLBACK PREPARED', - 'ROLLBACK TO SAVEPOINT', - 'SAVEPOINT', - 'SECURITY LABEL', - 'SELECT INTO', - 'SET CONSTRAINTS', - 'SET ROLE', - 'SET SESSION AUTHORIZATION', - 'SET TRANSACTION', + 'INSERT INTO', 'SHOW', - 'START TRANSACTION', + 'BEGIN TRANSACTION', 'UNLISTEN', - 'VACUUM', + 'VACUUM [ANALYZE | FULL]', ]); const reservedSetOperations = expandPhrases([ @@ -252,7 +109,7 @@ const reservedJoins = expandPhrases([ const reservedPhrases = expandPhrases([ 'PRIMARY KEY', - 'GENERATED {ALWAYS | BY DEFAULT} AS IDENTITY', + 'GENERATED ALWAYS', 'ON {UPDATE | DELETE} [SET NULL | SET DEFAULT]', '{ROWS | RANGE | GROUPS} BETWEEN', '[TIMESTAMP | TIME] {WITH | WITHOUT} TIME ZONE', @@ -292,51 +149,12 @@ export const duckdb: DialectOptions = { // Bitwise '&', '|', - '#', '~', '<<', '>>', - // Byte comparison - '~>~', - '~<~', - '~>=~', - '~<=~', - // Geometric - '@-@', - '@@', - '##', - '<->', - '&&', - '&<', - '&>', - '<<|', - '&<|', - '|>>', - '|&>', - '<^', - '^>', - '?#', - '?-', - '?|', - '?-|', - '?||', - '@>', - '<@', - '~=', // JSON - '?', - '@?', - '?&', '->', '->>', - '#>', - '#>>', - '#-', - // Named function params - '=>', - // Network address - '>>=', - '<<=', // Pattern matching '~~', '~~*', @@ -344,26 +162,10 @@ export const duckdb: DialectOptions = { '!~~*', '~', '!~', - // Range/multirange - '-|-', // String concatenation '||', // Text search - '@@@', - '!!', '^@', - // Trigram/trigraph - '<%', - '%>', - '<<%', - '%>>', - '<<->', - '<->>', - '<<<->', - '<->>>', - // Type cast - '::', - ':', ], }, formatOptions: { From b295cbd6de9d75db7da89e27b3441d018e9728e8 Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Sun, 2 Jun 2024 13:27:19 +1000 Subject: [PATCH 22/24] Move Qualify to Reserved Clause --- src/languages/duckdb/duckdb.formatter.ts | 1 + src/languages/duckdb/duckdb.keywords.ts | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/duckdb/duckdb.formatter.ts b/src/languages/duckdb/duckdb.formatter.ts index 9474084eec..e3e04e8529 100644 --- a/src/languages/duckdb/duckdb.formatter.ts +++ b/src/languages/duckdb/duckdb.formatter.ts @@ -12,6 +12,7 @@ const reservedClauses = expandPhrases([ 'WHERE', 'GROUP BY [ALL | DISTINCT]', 'HAVING', + 'QUALIFY', 'WINDOW', 'PARTITION BY', 'ORDER BY', diff --git a/src/languages/duckdb/duckdb.keywords.ts b/src/languages/duckdb/duckdb.keywords.ts index 720925c239..5c45e3d0c7 100644 --- a/src/languages/duckdb/duckdb.keywords.ts +++ b/src/languages/duckdb/duckdb.keywords.ts @@ -56,7 +56,6 @@ export const keywords: string[] = [ 'PIVOT_WIDER', 'PLACING', 'PRIMARY', - 'QUALIFY', 'REFERENCES', 'RETURNING', 'SELECT', From 1aec041cc5ee9bc014ef3a7dea4dd638a11dded2 Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Sun, 2 Jun 2024 13:27:44 +1000 Subject: [PATCH 23/24] Insert Supports By Position, Name --- src/languages/duckdb/duckdb.formatter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/languages/duckdb/duckdb.formatter.ts b/src/languages/duckdb/duckdb.formatter.ts index e3e04e8529..8269cef339 100644 --- a/src/languages/duckdb/duckdb.formatter.ts +++ b/src/languages/duckdb/duckdb.formatter.ts @@ -23,6 +23,7 @@ const reservedClauses = expandPhrases([ 'INSERT INTO', 'VALUES', 'DEFAULT VALUES', + 'BY [POSITION | NAME]', // - update: 'SET', // other From 5f787f31d8d256b86f6c0db01160625228bba28b Mon Sep 17 00:00:00 2001 From: Hugh Cameron Date: Sun, 2 Jun 2024 13:31:31 +1000 Subject: [PATCH 24/24] Attach/Detach --- src/languages/duckdb/duckdb.keywords.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/languages/duckdb/duckdb.keywords.ts b/src/languages/duckdb/duckdb.keywords.ts index 5c45e3d0c7..7c9de4c6f3 100644 --- a/src/languages/duckdb/duckdb.keywords.ts +++ b/src/languages/duckdb/duckdb.keywords.ts @@ -11,6 +11,7 @@ export const keywords: string[] = [ 'ANY', 'AS', 'ASC', + 'ATTACH', 'ASYMMETRIC', 'BOTH', 'CASE', @@ -24,6 +25,7 @@ export const keywords: string[] = [ 'DEFERRABLE', 'DESC', 'DESCRIBE', + 'DETACH', 'DISTINCT', 'DO', 'ELSE',