Compare commits

...

1899 Commits
0.10.1 ... main

Author SHA1 Message Date
F
7783c3014e fixes #6463: Set Variable Parsing for SparkSQL and Databricks (#6464)
Co-authored-by: F STG <fritz.steingrube@extern.stromnetz-hamburg.de>
2024-11-25 22:11:12 +00:00
V-D-L-P
8e26bd4ff7 Teradata: support REPLACE VIEW and LOCKING ... FOR ... syntax (#6467) 2024-11-25 22:10:27 +00:00
Luigi Cerone
787b58e58d Rule names in warnings logic (#6459)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-11-21 15:55:51 +00:00
Cameron
65ef3d0ec3 Bigquery: Support column level key definitions (#6465) 2024-11-21 15:40:34 +00:00
Danny Jones
ed9d0c98ad Add Implicit Indents to Qualify (#6438) 2024-11-21 15:39:21 +00:00
Danny Jones
a4658769b3 Postgres: Fix Select statement ordering (#6446) 2024-11-21 15:39:09 +00:00
F
190c4946f5 fixes #6457: databricks dialect alter table foo drop column bar (#6461)
Co-authored-by: F STG <fritz.steingrube@extern.stromnetz-hamburg.de>
2024-11-21 15:38:58 +00:00
Alan Cruickshank
4dc390f077 Switch from appdirs to platformdirs (#6399)
Co-authored-by: Alan Cruickshank <alan@Alans-MacBook-Pro.local>
Co-authored-by: Alan Cruickshank <alan+git@a14k.co.uk>
2024-11-21 15:02:09 +00:00
Matt Baker
80f4fc2d3b Impala: support CREATE TABLE AS SELECT (#6458) 2024-11-17 11:46:56 +00:00
F
50a1c4b6ff Databricks Dialect: Backticked function identifiers now parsable (#6453)
Co-authored-by: F STG <fritz.steingrube@extern.stromnetz-hamburg.de>
2024-11-16 20:09:20 +00:00
F
391449eb47 Issue #6417: Leading -- MAGIC Cells don't break parsing of notebooks (#6454)
Co-authored-by: F STG <fritz.steingrube@extern.stromnetz-hamburg.de>
2024-11-13 16:48:04 +00:00
Adolfo Rodriguez
79b168374b Add "target_path" configuration to the dbt templater (#6423)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2024-11-12 15:53:02 +00:00
Danny Jones
171c71e6e3 Sparksql: Fix ordering of create table options (#6441) 2024-11-12 15:21:36 +00:00
Matt Baker
0e333c3246 Dialect: Impala (#6445) 2024-11-11 10:30:50 +00:00
Cameron
02bca484a6 RF02: Allows for lambda functions in Databricks (#6444) 2024-11-10 10:52:29 +00:00
Cameron
5cb916ac74 SQLite: Support any order of VARYING/NATIVE in CHAR types (#6443) 2024-11-10 10:51:46 +00:00
Danny Jones
e864e174ae Snowflake: Allow literals in match_by_column_name (#6442) 2024-11-10 05:00:46 +00:00
Danny Jones
c6b39aae57 Trino: Remove TemporaryTransientGrammar (#6440) 2024-11-10 04:57:21 +00:00
Danny Jones
b9bcb9bc71 Mysql: Fix parsing of system variables (#6439) 2024-11-10 04:55:48 +00:00
Danny Jones
fb1be11571 Sparksql: Fix hint function for proper spacing (#6437) 2024-11-10 04:50:12 +00:00
Danny Jones
cbcbe52676 Snowflake: Support ORDER BY boolean (#6435) 2024-11-10 04:44:46 +00:00
Tim Zalk
f0602da8df TSQL: allow NEXT VALUE FOR use as expression (#6431)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-11-09 19:19:56 +00:00
Łukasz Rogalski
b5ef93c06e Prework for introducing mypyc (#6433) 2024-11-09 19:10:10 +00:00
Łukasz Rogalski
2106716132 Fix pre-commit on main branch (#6432) 2024-11-09 15:19:12 +00:00
Maciej Bryński
ffc7af43c0 Initial support for Starrocks dialect (#6415) 2024-11-02 15:15:25 +00:00
F
51e8cf43c2 Databricks: Parse Table Valued Functions (#6417)
Co-authored-by: Fritz Steingrube <fritz.steingrube@extern.stromnetz-hamburg.de>
Co-authored-by: fstg1992 <fritz@steingrube.eu>
2024-11-02 05:20:56 +00:00
ninazacharia-toast
6b8faf86fc Snowflake: Support PARTITION_TYPE for CREATE EXTERNAL TABLE (#6422)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2024-11-02 05:16:00 +00:00
Alan Cruickshank
8422eb7826 Fix docs for CP04 config and add test cases (#6416) 2024-11-01 10:48:06 +00:00
Joao Amaral
e63c337b17 Fix: Parse violations not being shown when run fix command with --show-lint-violations (#6382)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-10-30 08:18:35 +00:00
Łukasz Rogalski
b8d9c2b0a5 RF01: refine support for dialects with dot access syntax (#6400) 2024-10-29 22:36:04 +00:00
mroy-seedbox
c039d2f28d Add new TYPE property to Snowflake users (#6411) 2024-10-29 22:32:04 +00:00
Alan Cruickshank
48fcb75967 Document the config API (#6384) 2024-10-29 22:37:01 +00:00
Alan Cruickshank
1db76206c7 Error handling for trying to render callable builtins #5463 (#6388) 2024-10-29 22:32:28 +00:00
SongYoungUk
a2f773d9f4 SQLite : Add CREATE VIRTUAL TABLE Statement (#6406) 2024-10-28 18:41:03 +00:00
27Jashshah
e12c5d0100 Updated README with Table Of Contents (#6407) 2024-10-28 12:51:36 +00:00
github-actions[bot]
36ad37b2a3 Prep version 3.2.5 (#6401)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-10-25 10:14:01 +01:00
Alan Cruickshank
baa32b8836 Guides for custom rules and for troubleshooting (#6379) 2024-10-24 13:18:34 +01:00
Alan Cruickshank
c83c73535e Documentation and small overhaul of parametrized rule test cases (#6380) 2024-10-24 10:08:52 +01:00
Simon Bonde
8c63de4277 TSQL: add missing unreserved keyword NULLS (#5212) (#6390) 2024-10-24 08:37:10 +00:00
Kürşat Aktaş
052019e206 Introducing SQLFluff Guru on Gurubase.io (#6373)
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-10-24 08:12:15 +00:00
Łukasz Rogalski
62ee9d6abb Improve heuristics for inline config (#6391) 2024-10-24 08:07:38 +00:00
Cameron
bc2da1a54c Postgres: Handle expressions that occur in IN functions (#6393) 2024-10-24 08:05:52 +00:00
Cameron
34f51497bc Snowflake: Support bracketed lambda functions without datatypes (#6394) 2024-10-24 08:05:16 +00:00
Cameron
9f6a6c3b7c LT01: Add default config for match_condition to touch (#6395) 2024-10-24 08:04:48 +00:00
Cameron
069be3a01d Snowflake: Allow for additional CONNECT BY expressions that may use PRIOR (#6396) 2024-10-24 08:04:07 +00:00
Alan Cruickshank
64baf05302 Details on debugging and setup for diff-quality (#6381) 2024-10-24 09:11:55 +01:00
Łukasz Rogalski
693381882a Fix edge case in Jinja reindents (#6383) 2024-10-22 23:18:53 +00:00
Paul Burridge
6fb5a84e6d Support identifier clause for Databricks (#6377)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-10-21 08:15:49 +00:00
Mike Chen
a5e0549195 Enable AM02 for snowflake and trino by default. (#6369) 2024-10-20 19:41:32 +00:00
Cameron
17ce19e743 Postgres: Support identifiers in ALTER DATABASE SET (#6376) 2024-10-20 19:40:19 +00:00
Cameron
cc2be1475e SparkSQL: Improved lexing and parsing of file literals (#6375) 2024-10-20 19:39:46 +00:00
Greg Finley
54e4304e77 Fix Snowflake alter share (#6372) 2024-10-20 02:53:59 +00:00
Alan Cruickshank
cd75984ad3 Resolve collision between ST02 and LT01 (#6366) 2024-10-17 16:25:18 +00:00
Alan Cruickshank
f483159b0d Prevent false positives with AL05 and array functions (#6365) 2024-10-17 16:24:09 +00:00
Alan Cruickshank
2ffb5ec851 Handle iteration and getting undefined jinja variables (#6364) 2024-10-17 16:22:57 +00:00
Mike Chen
514690958e Update documentation with new dialects (#6337) 2024-10-17 08:41:51 +00:00
VictorAtIfInsurance
160361d79a enable default values when creating databricks tables (#6362)
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-10-16 17:22:25 +00:00
SongYoungUk
e21abac164 Postgres : Add ALTER AGGREGATE Statement (#6353) 2024-10-16 16:40:28 +00:00
Alan Cruickshank
e92210c4f6 Revise AL09 (self aliasing) - stricter case sensitivity (#6333)
Co-authored-by: aayushr7 <rohatgi.aayush@gmail.com>
Co-authored-by: Cameron <105471409+keraion@users.noreply.github.com>
2024-10-16 15:53:26 +00:00
mroy-seedbox
50420fb6ac Make dbt RelationEmulator safely callable (#6358) 2024-10-15 09:59:28 +00:00
github-actions[bot]
eb77eb1a5d Prep version 3.2.4 (#6356)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-10-14 19:37:58 +01:00
Brandon Schabell
4e7367596e Utilize a deepcopy of the config object when parsing files (#6344)
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-10-14 16:02:02 +00:00
Alan Cruickshank
d3c084b9b9 Snowflake supports other literals in system functions (#6355) 2024-10-14 16:01:17 +00:00
Alan Cruickshank
86645c6cbd Snowflake: Un-reserve CURRENT_USER (#6354) 2024-10-14 16:00:48 +00:00
Cameron
faa6c070dc tsql: handle additional primary/foreign key options in constraints (#6347) 2024-10-13 21:29:46 +00:00
Cameron
abe9a0caba Add DROP COLUMN support for multiple dialects (#6348) 2024-10-13 21:28:47 +00:00
Cameron
48fc88cd73 TSQL: allow UPDATE to be a function name (#6349) 2024-10-13 21:28:08 +00:00
Cameron
0bc27a0e6f tsql: allow both on delete and on update in a reference_constraint (#6346) 2024-10-13 03:15:22 +00:00
SongYoungUk
70d4060087 Postgres : Allow Extensions with Special Characters in Name (#6345) 2024-10-12 19:03:35 +00:00
SongYoungUk
3f5d53e102 Fix tox command in test/fixtures/dialects/README.md (#6342) 2024-10-12 16:34:35 +00:00
Alan Cruickshank
37bffc387c Revise dbt warnings when a file fails to compile (#6338) 2024-10-12 16:21:26 +00:00
Cameron
1007f00c74 Postgres: Add CREATE FOREIGN DATA WRAPPER statement (#6335) 2024-10-11 18:21:59 +00:00
Cameron
1031a3342f Trino: Add some support to json_query functions (#6336) 2024-10-11 16:45:33 +00:00
Alan Cruickshank
015b1301c1 Handle deprecation warning of "fork" (#6332) 2024-10-11 13:35:24 +00:00
Alan Cruickshank
109fa6ffd0 Python 3.13 support and make it default for test coverage (#6269) 2024-10-11 07:14:56 +00:00
Łukasz Rogalski
2b76370a40 ST06 - Fix union of CTE/Subquery (#6298) 2024-10-11 07:13:41 +00:00
Greg Finley
b8a5d533ea Refactor timestamp grammar (#6331) 2024-10-11 07:11:33 +00:00
github-actions[bot]
6f808ffdcb Prep version 3.2.3 (#6329)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-10-10 14:02:01 +01:00
Cameron
e3aa1995a0 BigQuery: Support Tuple syntax in other locations (#6328) 2024-10-10 09:38:00 +00:00
Cameron
914d930244 Trino: Fix rule interactions with lambda functions (#6327) 2024-10-10 09:37:19 +00:00
Alan Cruickshank
8c83583a6b Resolve some more edge cases in LT02 (#6324) 2024-10-10 01:45:15 +00:00
Łukasz Rogalski
5c90dfa7ef RF05 - fine tuning for snowflake dialect (#6297) 2024-10-10 00:30:29 +00:00
Cameron
74a19bb555 Indentation: UPDATE and RETURNING clauses (#6314) 2024-10-09 10:00:38 +00:00
Cameron
0a32baa44f Postgres: Fix lexing some JSON operators (#6323) 2024-10-09 09:59:52 +00:00
mroy-seedbox
8ca4e0a1dc Add support for grant monitor on user ... in Snowflake dialect (#6322) 2024-10-08 23:44:10 +00:00
Alan Cruickshank
3c9648a661 Exclude templated casts from CV11 (#6320) 2024-10-08 21:47:25 +00:00
Greg Finley
9cf325302c Snowflake allow double-quoted comments (#6318) 2024-10-08 17:56:32 +00:00
Greg Finley
ca0c0fbe28 Databricks materialized view (#6319) 2024-10-08 17:55:52 +00:00
Alan Cruickshank
7030b5b6aa Allow double quotes to be escaped by writing twice (#6316) 2024-10-08 16:53:22 +00:00
Alan Cruickshank
b0f9412127 Resolve an oscillation bug with LT02 (#6306) 2024-10-08 16:51:40 +00:00
Alan Cruickshank
2088f4cd0c Create a "Guides and Howtos" section of the docs. (#6301) 2024-10-08 16:49:18 +00:00
Alan Cruickshank
06e1fff328 Add groups to the github-annotation-native format option. (#6312) 2024-10-08 16:47:20 +00:00
Cameron
f5d98615e3 Snowflake: Support CTEs and multiple orders of CopyOptions in COPY INTO (#6313) 2024-10-08 11:02:07 +00:00
Alan Cruickshank
642ee248c7 Allow expressions in ORDER BY for clickhouse (#6311) 2024-10-08 04:01:31 +00:00
Łukasz Rogalski
00f865f037 Snowflake: support temp UDFs (#6309) 2024-10-07 23:59:07 +00:00
Christopher Marriott
73823d4237 fix: tsql create function syntax corrections (#6289)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-10-07 14:12:40 +00:00
github-actions[bot]
64f80278be Prep version 3.2.2 (#6305)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-10-07 12:10:32 +01:00
Alan Cruickshank
563d2dc817 Hotfix for JJ01 (#6304) 2024-10-07 11:53:36 +01:00
Alan Cruickshank
9ceff0a3ee Add note on 3.0.x to main docs page. (#6302) 2024-10-07 09:19:55 +01:00
github-actions[bot]
76ceb29a30 Prep version 3.2.1 (#6279)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-10-06 19:35:58 +01:00
Cameron
e267cbebfe Postgres: Support walrus operator named arguments (#6299) 2024-10-06 11:03:23 +00:00
Cameron
057972bde8 TSQL: handle nested joins, RF01 better aliasing (#6300) 2024-10-06 11:01:46 +00:00
Grant Culp
2ab8424302 Exclude Macros - Allow multiple paths. (#6221)
Co-authored-by: Grant Culp <grant.culp@kraftheinz.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-10-04 17:35:54 +00:00
Alan Cruickshank
e48729fc4b Dededuplicate rule ignore docs (#6296) 2024-10-04 15:17:15 +00:00
Alan Cruickshank
e7b7af65ec Bugfix for LT07 with consumed newlines. (#6294) 2024-10-04 15:11:04 +00:00
Alan Cruickshank
b6c101a66c Bugfix for LT12 with jinja whitespace consumption (#6292) 2024-10-04 15:03:20 +00:00
Cameron
8f8b5d3f9d RF02: Ignore DECLARE variables in BigQuery (#6295) 2024-10-04 14:57:26 +00:00
Alan Cruickshank
f78289e361 Bugfix for JJ01 in parallel mode (#6293) 2024-10-04 14:44:11 +00:00
mroy-seedbox
c86e1f76ab Allow arbitrary attributes & methods for ThisEmulator (#6254)
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-10-04 14:06:33 +00:00
Cameron
8251ffc9d5 RF05: Add table_aliases option (#6273)
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-10-04 13:00:28 +00:00
Cameron
0c53a13694 BigQuery: Add support for concatenating in EXECUTE IMMEDIATE (#6287) 2024-10-04 11:58:38 +00:00
Cameron
dd6c667eae BigQuery: Add support for SET with system variables (#6288) 2024-10-04 11:56:57 +00:00
Cameron
5658f2f36c Plugins: Migrate example plugin to pyproject.toml (#6286) 2024-10-04 11:55:53 +00:00
Payton Snider III
f1455c7ce1 TSQL: Add DATETRUC to date_part_function_name list (#6283) 2024-10-03 05:10:05 +00:00
Greg Finley
236e986827 MySQL Alter table convert to character set (#6277) 2024-10-03 01:42:31 +00:00
Alan Cruickshank
7b7df01fc5 Remove dependency on coveralls. (#6284) 2024-10-02 22:31:06 +00:00
Edgar Ramírez Mondragón
8f26aa0736 Test dbt Templater Plugin with dbt 1.9.0 (#6280) 2024-10-02 22:16:36 +00:00
Cameron
99b3f9261b AM06: Ignore array expressions in BigQuery (#6276) 2024-10-01 12:43:19 +00:00
Greg Finley
8b5854febc Add mariadb to issue labeler (#6278) 2024-10-01 12:15:26 +00:00
Cameron
252d4b4d4b BigQuery: Add GROUPING SETS clause (#6275) 2024-10-01 03:45:03 +00:00
Cameron
885d50defc Snowflake: Support ARRAY types (#6272) 2024-09-30 09:59:53 +00:00
Alan Cruickshank
158054cf39 Move most of the config validation settings out into rule bundles. (#6262) 2024-09-29 21:08:54 +01:00
Alan Cruickshank
dbbf765e8e Revise warnings with fixing unfixable files. (#6257) 2024-09-28 18:54:21 +01:00
Alan Cruickshank
8abc2f49f5 Strict mypy on sqlfluff.core (#6246) 2024-09-28 18:52:29 +01:00
Cameron
98cd54f54f DuckDB: Add DROP MACRO (#6270) 2024-09-28 08:35:36 +00:00
Gabe Pesco
d2c94a0bc3 Added Support for Databricks SQL Notebook Cells (#6267)
Co-authored-by: Gabe Pesco <PescoG@medinsight.milliman.com>
2024-09-27 22:21:21 +00:00
Alan Cruickshank
3805139cb0 dbt templater pyproject.toml nits (#6268) 2024-09-27 23:31:06 +01:00
troshnev
b75f51103e Add UTF8 support for identifiers in Vertica dialect (#6183)
Co-authored-by: sergey.kry <Kryzhanovskiy.S@merlion.ru>
Co-authored-by: skryzh <sergeikryzh95@gmail.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-09-27 21:54:11 +00:00
Alan Cruickshank
d69a5119a2 Almost all of util up to strict typing (#6263) 2024-09-27 15:36:19 +00:00
Alan Cruickshank
0539c78741 Update link to diff-cover docs (#6256) 2024-09-27 12:02:41 +01:00
Cameron
6dd6433a51 MySQL: AL09 handle double quoted identifiers (#6249) 2024-09-24 09:30:35 +00:00
Clément
0cc067c78e fix: complex file extensions discovery (#6228)
Co-authored-by: Clément Delpech <clement.delpech@adevinta.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-09-23 22:45:33 +00:00
fvankrieken
49ceab1d33 fix RF06 issue in postgres naked identifier regex (#6247) 2024-09-23 21:03:16 +00:00
Alan Cruickshank
d0e8b271d3 Strict typing for sqlfluff.core.linter (#6240) 2024-09-23 09:12:47 +00:00
Cameron
d7ed7026d7 DuckDB: Fixed DatatypeSegment references (#6244) 2024-09-23 09:04:57 +00:00
Cameron
0623bbb9d3 Postgres: Support SET with double quoted identifiers (#6243) 2024-09-23 09:04:23 +00:00
Greg Finley
2537a84e25 Consolidate Teradata tests (#6241) 2024-09-23 09:03:51 +00:00
Cameron
33f1deb8f1 RF02: Ignore alias references that are self-inner (#6242) 2024-09-23 09:02:46 +00:00
Pierce
efcf0691bf Add additional CREATE TABLE support for Databricks (#6216) 2024-09-22 22:05:24 +00:00
Fellipe Sebastiam
372f7ffc2f Complete the support for PIVOT in Snowflake dialect (#6217) 2024-09-22 22:03:49 +00:00
stephnan
868fc75a83 Exasol - allow function calls in values clause (#6226) 2024-09-22 20:48:13 +00:00
Babak Tourani
9113369fd0 Snowflake: Support defining virtual columns (#6237) 2024-09-22 20:40:10 +00:00
Greg Finley
9db1622e5b Teradata order of VOLATILE and MULTISET (#6233) 2024-09-22 20:37:32 +00:00
Jeppe Fihl-Pearson
9da0f625a0 Remove duplicate timing columns from the timing records (#6229) 2024-09-20 19:56:51 +00:00
Fellipe Sebastiam
9f0e3d9625 Fix time travel clauses in Snowflake dialect (#6230) 2024-09-20 13:04:38 +00:00
github-actions[bot]
2605df0f9a Prep version 3.2.0 (#6187)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Cameron <105471409+keraion@users.noreply.github.com>
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-09-18 22:53:26 +02:00
Alan Cruickshank
9463a7af75 Handle multi-processing dbt exceptions much better. (#6138) 2024-09-18 20:21:55 +00:00
Tim Church
d6789562dc Support variables with dot in python templater (#5872)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-09-18 08:12:12 +00:00
Francis Nimick
178a0c990c Add postgres normalization operator support (#6211) 2024-09-18 07:47:45 +00:00
Cameron
b619b4fa75 Fix patch will anchor on first buffer insertion point (#6212) 2024-09-18 07:46:05 +00:00
Alan Cruickshank
91690be6f9 Allow ignore patterns in other config files. (#6130) 2024-09-17 12:52:20 +00:00
Alan Cruickshank
712556bb2e Strict typing in config and helpers. (#6206) 2024-09-17 07:19:41 +00:00
Cameron
59d89dfb57 TSQL: Support multiple options in SET statement (#6205) 2024-09-16 12:09:47 +00:00
Cameron
261633c17c DuckDB: Support CREATE TYPE statement (#6204) 2024-09-16 12:08:50 +00:00
Greg Finley
b3b78f588a Update Slack link (#6203) 2024-09-16 01:25:27 +00:00
Michael Vastarelli
75a83f28d0 Add quoted literal checking for Snowflake TARGET_LAG in dynamic tables. (#6201) 2024-09-15 15:27:28 +00:00
Cameron
fa1459eac2 Databricks: Support COMMENT ON statement (#6196) 2024-09-15 15:25:14 +00:00
Cameron
db505172ee DuckDB: Support STRUCT datatype (#6198) 2024-09-15 15:21:45 +00:00
Alan Cruickshank
ed3e1f3f76 Deprecate the ConfigLoader (#6177)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-09-15 13:53:48 +02:00
Cameron
0fa176b680 DuckDB: Support CREATE MACRO/CREATE FUNCTION (#6194) 2024-09-13 15:17:36 +00:00
Cameron
4ea97b5141 DuckDB: Support functions with walrus operators (#6193) 2024-09-13 14:27:01 +00:00
Adam Weeden
92db7ffcbd Add volume syntax support for Databricks (#6179) 2024-09-13 11:58:56 +00:00
Alan Cruickshank
b7404fb29a Handle errors better in AL09 (#6186) 2024-09-12 20:27:25 +00:00
Adam Weeden
ac9e30ce05 Add support for managed locations to databricks dialect schemas (#6182) 2024-09-12 12:10:13 +00:00
Danny Jones
9cf3603942 MYSQL: Create Table Optional AS (#6109)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-09-10 12:56:13 +00:00
Alan Cruickshank
99af2834b1 More dialect documentation (#6165) 2024-09-10 12:02:24 +00:00
Alan Cruickshank
e75931c8e5 Better documentation on how to cross reference rules and fix a few. (#6162) 2024-09-10 11:49:47 +00:00
Alan Cruickshank
c54f99b7a3 RF06: Case Sensitivity (#6173) 2024-09-09 22:27:03 +00:00
Cameron
791e0ad411 SparkSQL/Databricks: Support for VARIANT type (#6167) 2024-09-09 12:11:39 +00:00
Cameron
e731b0f6eb sparksql: Allow INSERT OVERWRITE after a CTE (#6172) 2024-09-09 09:10:19 +00:00
Cameron
f5cace3c65 postgres: Add SET CONSTRAINTS statement (#6171) 2024-09-09 09:09:45 +00:00
Cameron
67fbabe2d7 TSQL: Fix MERGE without a target alias (#6170) 2024-09-09 09:09:08 +00:00
Cameron
df8b47ab69 TSQL: add OFFSET and FETCH (#6169) 2024-09-09 09:08:34 +00:00
Cameron
d5f84846c7 postgres: Add support for SUBSCRIPTION statements (#6168) 2024-09-09 09:07:26 +00:00
Cameron
86f937752d Duckdb: Add support for list comprehensions (#6166) 2024-09-09 08:57:53 +00:00
Alan Cruickshank
4afa68539c Update Docs and tests for CP02 (#6163) 2024-09-09 05:00:32 +00:00
Alan Cruickshank
c376ddf314 Cached property in RF06 rather than DIY (#6164) 2024-09-09 04:53:09 +00:00
Cameron
f24b9d6a7f CI: Update util.py for dbt templater pyproject.toml (#6160) 2024-09-08 15:17:42 +00:00
Alan Cruickshank
2464d36c28 Auto generate dialect docs (#6153)
Co-authored-by: Cameron <105471409+keraion@users.noreply.github.com>
2024-09-08 14:28:30 +00:00
Danny Jones
f4229899ec Deprecate support for dbt 1.1-1.3 (#6159) 2024-09-08 14:19:03 +00:00
Cameron
bb13ee9edb ST08: Ignore DISTINCTs with subqueries (#6146) 2024-09-08 14:18:30 +00:00
Danny Jones
fd4aeb9724 Duckdb: Fix Create View coverage (#6158) 2024-09-08 11:15:38 +00:00
Danny Jones
bf97994096 Snowflake: Support Password Policies (#6154)
Co-authored-by: Cameron <105471409+keraion@users.noreply.github.com>
2024-09-08 11:12:46 +00:00
Danny Jones
c76818c65f Postgres: Allow negative integers in sequences (#6111) 2024-09-08 00:56:00 +00:00
Danny Jones
7ca1c2a430 Postgres: Add SHOW Statement (#6110) 2024-09-08 00:54:19 +00:00
Cameron
9b1b138fe1 Migrate dbt templater to pyproject.toml (#6155) 2024-09-07 22:35:11 +00:00
Cameron
2a9e3a109b Snowflake: Add DEFAULT option for function parameters (#6145) 2024-09-06 18:45:23 +00:00
Joe Crobak
9438f29867 Snowflake: fixes parsing for INCLUDE_METADATA in COPY INTO statement (#6150) 2024-09-06 18:43:50 +00:00
babak-l1
efbe57f962 [SNOWFLAKE] Adding support for extended constraint definitions (#6151) 2024-09-06 18:42:18 +00:00
Joe Crobak
8ed84cb071 Snowflake: fixes parsing for PARSE_HEADER in FILE FORMAT statement (#6149) 2024-09-05 17:07:37 +00:00
ChengShujun
2ea52947f2 fix: avoid strip_newlines when encounter comments in inline segments (#6140) 2024-09-04 21:15:32 +00:00
Alan Cruickshank
a833aa153b More robust exception handling for dbt. (#6144) 2024-09-04 19:01:32 +00:00
Cameron
7f4a1cf26f postgres: Add ENCRYPTED PASSWORD option in CREATE USER (#6143) 2024-09-04 18:35:09 +00:00
Pavel-Strybuk
31e0a5bc82 Fix support of INTERVAL in ClickHouse (#6112)
Co-authored-by: Pavel Strybuk <pstr@tut.by>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-09-03 12:18:24 +00:00
amardatar
ba2570262c Add support for Snowflake Higher-Order Functions (#6136) 2024-09-03 10:38:48 +00:00
Alan Cruickshank
caa827c743 Method extraction and more robust typing in config. (#6135) 2024-09-03 10:25:20 +00:00
Pierce
0ee95b654a Add missing databricks and sparksql ALTER statements (#6102)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-09-03 09:21:17 +00:00
ChengShujun
16915b5248 fix: program_counter move in JinjaTracer (#6121) (#6123)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-09-03 07:43:43 +00:00
Cameron
763e453e7f CI: allow hidden file upload for coverage files (#6139) 2024-09-03 07:11:30 +00:00
Michael Vastarelli
be6105d9ad Fix: added DOWNSTREAM keyword for TARGET_LAG on dynamic tables in Snowflake. (#6131) 2024-09-02 07:31:31 +00:00
Kirk Hansen
ed9646f0fc Trino Dialect: update ARRAY type handling (#6127)
Co-authored-by: Kirk Hansen <kirk.hansen@corteva.com>
2024-09-02 07:24:11 +00:00
Alan Cruickshank
b80f145c96 Split apart config module (#6128) 2024-09-02 07:23:32 +00:00
Cameron
4d0185a153 Add option for allowing only a subset of rules for noqa (#6115) 2024-08-29 10:58:18 +00:00
Cameron
60a612f437 TSQL: Allow for empty catch block in try-catch (#6116) 2024-08-28 14:33:56 +00:00
Cameron
1a8f884737 Change evaluation order of literals before column refs in bracketed, delimited expressions (#6117)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-08-28 12:13:33 +00:00
Danny Jones
18293ce419 Fix spacing rules for functions (#5809)
Co-authored-by: Cameron <105471409+keraion@users.noreply.github.com>
2024-08-28 10:02:13 +00:00
Danny Jones
617942d0f5 SQLite: Add conflict_clause to unique table constraint (#6106) 2024-08-24 17:26:57 +00:00
Danny Jones
6ce5026c51 SQLite: Support Raise Function (#6108) 2024-08-24 17:24:45 +00:00
Danny Jones
ae9dc4666b SQLite: Create Trigger WHEN optionally bracketed (#6107) 2024-08-24 17:22:37 +00:00
Cameron
b1cf6c3964 Snowflake: Added INTERVALs to Frame Clause (#6105) 2024-08-24 11:35:36 +00:00
Cameron
3b3c7dae4d Postgres: Add IS UNKNOWN (#6094)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-08-23 14:35:01 +00:00
Cameron
92e1bf376f RF02: Handle subquery column qualification (#6091) 2024-08-21 09:13:52 +00:00
Cameron
7eae679074 tsql: Allow leading dots in table references (#6093) 2024-08-21 09:12:32 +00:00
github-actions[bot]
35ffbfb8f4 Prep version 3.1.1 (#6072)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-08-20 23:27:33 +01:00
Cameron
f7557854de dbt Templater: Increase dbt deps test fixture timeout (#6088) 2024-08-19 18:08:13 +00:00
D-to-the-K
8bbd42f355 SparkSQL + Databricks: Add support for raw string literals (#6089)
Co-authored-by: Daniel Brum <daniel.brum@toptal.com>
2024-08-19 18:07:51 +00:00
Yung-Chun
861b9824d5 fixes #4855 - Add DECLARE statement in snowflake dialect (#6059) 2024-08-19 04:01:42 +00:00
Ben Beecher
1e4876bd4a Adding CTE to mysql views (#6077) 2024-08-19 02:22:24 +00:00
Alan Cruickshank
16006dd0f0 Rationalise config discovery routines. (#6080) 2024-08-18 12:44:48 +00:00
Balazs Bonis
6aa2cfbd2e fix(dialect-trino): Trino ROW datatype definition in queries (#6085) 2024-08-18 12:43:15 +00:00
D-to-the-K
3dd233513f Databricks: Add support for GROUP BY ALL (#6082)
Co-authored-by: Daniel Brum <daniel.horus@toptal.com>
2024-08-18 12:40:50 +00:00
Olivier Girardot
e754d282d4 fix(clickhouse): add support for tuple() and ENGINE MergeTree (#6079) 2024-08-15 22:58:34 +00:00
Alan Cruickshank
733636d53f Add perma-links for rules (#6066) 2024-08-15 15:36:24 +00:00
Olivier Girardot
32e7704aa8 fix(clickhouse): add support for rename statement (#6073) 2024-08-15 15:35:47 +00:00
Olivier Girardot
1de8109abb fix(clickhouse): add support for INTO OUTFILE and supported FORMATs (#6065) 2024-08-14 11:49:40 +00:00
Cameron
dc18175db0 LT04: Fix indentation conflict with LT02 (#6068) 2024-08-14 11:47:32 +00:00
Cameron
dfca944024 pre-commit: Disable progress bar (#6069) 2024-08-14 11:45:20 +00:00
Olivier Girardot
473b6f1a08 feat(clickhouse): add support for decimal(x,y), decimal32(x) and match (#6063)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-08-13 08:31:00 +00:00
Alan Cruickshank
d26cc1658f Big docs refactor. (#6052)
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-08-12 14:23:08 +00:00
Cameron
5eeb7cd4ca ST05: Handle set statement's subsequent queries (#6062) 2024-08-12 10:35:05 +00:00
Olivier Girardot
d11f39a5d1 fix(clickhouse): add support for limit by and bracketed format (#6061) 2024-08-12 10:21:55 +00:00
Olivier Girardot
898fe9458f fix(clickhouse): add support for DateTime64(precision, tz) and Tuples() (#6060) 2024-08-11 21:49:24 +00:00
Christian Soto
2516b5d636 Copy statement postgres v9 compatibility support (#5181)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-08-11 16:35:08 +00:00
Alan Cruickshank
e8042b0ae9 Run dbt tests in py312 by default (#5861)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-08-11 17:09:05 +01:00
Alan Cruickshank
c7e791d5ff Extract path discovery routines from config and linter. (#6057)
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-08-10 02:04:53 +00:00
Jay B
cc40b83919 MySQL: Added SET TRANSACTION parsing (#5781)
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-08-09 22:17:46 +00:00
Uros Stankovic
0d20542509 Support declare or replace variable statement for Databricks dialect (#6054)
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-08-09 22:09:39 +00:00
Grant Culp
498bc632da Exclude Macros from a path provided (#6031)
Co-authored-by: Grant Culp <grant.culp@kraftheinz.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-08-09 22:09:29 +00:00
Cameron
5210291d2d ST03: Detect CTE usage in nested WITH clauses (#6017)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-08-09 21:57:40 +00:00
Riley McDowell
079e8487f3 TRINO: support FILTER after WITHIN GROUP agg expression (#6056) 2024-08-09 21:47:46 +00:00
Starstruckk
9252ea96fe Fix/snowflake double quotes (#5727)
Co-authored-by: Starstruckk <asya.dimitrova@dxc.com>
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-08-09 00:56:31 +00:00
moh-lch
7336b7dc3a bq_table_function : Added functionality to parse table functionsin BigQuery (#5480)
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-08-09 00:31:50 +00:00
Jacob
7d6d6a2555 Fix Athena Partitioned By format for iceberg tables (#5399)
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-08-09 00:24:18 +00:00
rafalbog
f08a86e455 fix: redshift dialect, EXTENSION added (#6025)
Co-authored-by: Bogusz <rafal.bogusz@dxc.com>
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-08-08 23:58:37 +00:00
Ales Bukovsky
585ecf1299 Fix ignored inline rule overrides (#5697) (#6010) 2024-08-08 23:48:55 +00:00
Alan Cruickshank
9d0a4990e3 Update the docs on RF03 (#6051)
Co-authored-by: Alan Cruickshank <alan+git@designingoverload.com>
2024-08-09 00:40:05 +01:00
Cameron
5ff8cbe27a RF03: Fixed some subquery reference scenarios (#6046) 2024-08-08 21:09:53 +00:00
Cameron
b05161decd CV11: Remove rogue print statement (#6047) 2024-08-08 20:43:17 +00:00
Gergely Havlicsek
3836b3d92a Snowflake: fixes parsing for AGGREGATE in CREATE FUNCTION statement (#6049) 2024-08-08 20:42:34 +00:00
Gergely Havlicsek
4a9ad582b8 Snowflake:adds optional IF NOT EXISTS to ADD COLUMN (#6050) 2024-08-08 14:46:26 +00:00
Cameron
a3043fec09 Replace types-pkg-resources with types-setuptools (#6039) 2024-08-06 15:20:15 +00:00
Alan Cruickshank
1dd8200596 Remove old deps for dbt templater (#6028) 2024-07-28 17:29:41 +00:00
nicolb2305
9ec348ccd6 Added GENERATED AS IDENTITY support to DataBricks dialect (#6004)
Co-authored-by: Seyedsoroush Hashemi <hashemi.soroush@gmail.com>
2024-07-25 20:28:27 +00:00
Mal Curtis
565b073660 Add support for Clickhouse ORDER BY WITH FILL (#6018)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2024-07-24 08:07:03 +00:00
Alan Cruickshank
60e3a34dfb Parse API example (#6021) 2024-07-23 10:05:42 +01:00
yorickbouma
583d89989a Add additional dateparts from DATEPART() (#6012)
Co-authored-by: Yorick Bouma <boumay01@heiway.net>
2024-07-22 20:26:32 +00:00
Heinz Wiesinger
68f8f6548a MariaDB: Add support for GROUP BY ... ASC/DESC and GROUP BY ... WITH ROLLUP (#6009) 2024-07-15 19:29:57 +00:00
Cameron
68f09b1629 AM07: Handle set expressions with bracketed selects (#6005) 2024-07-15 18:01:21 +00:00
Heinz Wiesinger
819c8b5161 MariaDB: Add support for DELETE/INSERT/REPLACE ... RETURNING (#6008) 2024-07-15 17:17:52 +00:00
Heinz Wiesinger
775681d4d5 MariaDB: Add mariadb specific syntax for generated columns (#6007) 2024-07-15 17:16:34 +00:00
Gergely Havlicsek
e52e7e1268 Snowflake: fixes drop column if exists parsing rules (#5999)
Co-authored-by: Gergely Havlicsek <ghavlicsek@apple.com>
2024-07-05 13:12:26 +00:00
Mayur Singal
1e75212f5e Fix TSQL Post Table Expr intrepreted as function (#6001) 2024-07-05 13:11:06 +00:00
github-actions[bot]
3ef765df7a Prep version 3.1.0 (#5998)
Co-authored-by: WittierDinosaur <WittierDinosaur@users.noreply.github.com>
Co-authored-by: WittierDinosaur <daniel.jones@deliveroo.co.uk>
2024-07-03 17:19:20 +00:00
Gergely Havlicsek
dae258eade Snowflake: alter procedure & function updates (#5997)
Co-authored-by: Gergely Havlicsek <ghavlicsek@apple.com>
2024-07-03 15:04:37 +00:00
Gergely Havlicsek
77d40d23c3 Snowflake: fix connect by prior selects (#5996)
Co-authored-by: Gergely Havlicsek <ghavlicsek@apple.com>
2024-07-03 14:35:46 +00:00
Gergely Havlicsek
9d656921f0 Snowflake: adds EVENT TABLE support (#5995)
Co-authored-by: Gergely Havlicsek <ghavlicsek@apple.com>
2024-07-03 14:34:56 +00:00
Jay B
6a753df728 Feature/MariaDB dialect (#5856)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-07-03 09:45:46 +00:00
Cameron
cfcc3df00c Postgres: Fix multiline concat for special literals (#5965)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-07-02 09:51:33 +00:00
Cameron
6db990ca7d ST05: Evaluate nested queries as a whole (#5990) 2024-07-02 09:18:18 +00:00
Alan Cruickshank
bca33b72a8 Naïve multi-variant jinja linting (#5822) 2024-07-01 11:39:21 +00:00
Dan Goldberg
8552291f1a Update Snowflake Unpivot Dialect to INCLUDE/EXCLUDE NULLs (#5961)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2024-06-28 20:49:23 +00:00
Gergely Havlicsek
4f53b45fdb Snowflake: Adds parsing fixes for external access integrations in create procedure and function (#5986)
Co-authored-by: Gergely Havlicsek <ghavlicsek@apple.com>
2024-06-26 11:11:41 +00:00
keraion
6a11cafd08 Select Analysis: Don't recursively crawl merge subselects (#5981) 2024-06-26 10:58:19 +00:00
j-svensmark
1e2e54e1fd Parent dir config search (#5958) 2024-06-26 10:56:15 +00:00
Danny Jones
0b669600ee Enable AM02 for bigquery, clickhouse, databricks, db2 (#5979) 2024-06-26 10:49:04 +00:00
Barry Pollard
dd487f9d9d Add COMMENT ON support to Trino dialect (#5984) 2024-06-26 08:59:33 +00:00
Gergely Havlicsek
23ef79c290 Snowflake: fix scriptless stored procedure parsing (#5982)
Co-authored-by: Gergely Havlicsek <ghavlicsek@apple.com>
2024-06-25 22:12:57 +00:00
James Johnston
d4ec93f11f Add support for custom JinjaTracer implementations (#5937) 2024-06-22 16:25:34 +00:00
Kazuhito Osabe
91bddc100e MySQL: Fix variable handlings inside expressions (#5967) 2024-06-22 15:11:06 +00:00
Adam Weeden
d1b640623e Allow anonymous PIVOTs in Databricks (#5968)
Co-authored-by: Adam Weeden <adam.weeden@encoura.org>
2024-06-22 15:05:54 +00:00
keraion
a01e3172f8 Rebreak: Fix meta dedent segment order (#5972) 2024-06-22 15:01:36 +00:00
Dmytro Kulyk
9f8dbce96b Update athena dialect for CTAS (#5974)
Co-authored-by: Dmytro Kulyk <dmytro.kulyk@gr8.tech>
2024-06-22 14:55:24 +00:00
Joao Boto
be1df0a981 fix(dialect-trino): Support Grouping Sets (#5970) 2024-06-22 14:53:10 +00:00
Kazuhito Osabe
e962fc1e62 BigQuery: Support various DROP statements (#5966) 2024-06-18 21:21:53 +00:00
keraion
dde5eda7fa AL07: Fix self-referencing table aliases (#5963) 2024-06-13 18:40:53 +00:00
Dmytro Samodurov
69b4f968b7 Clickhouse 'create view' support (#5910)
Co-authored-by: Dmytro Samodurov <dima@EPUALVIW07F4>
2024-06-09 23:52:33 +00:00
Danny Jones
6951328233 Capitalisation: Add camelCase (#5777)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-06-09 19:28:33 +00:00
stephnan
9f1446fea8 Exasol: Use ANSI value_clause to handle insert_stmts correctly (#5959) 2024-06-09 15:14:47 +00:00
fvankrieken
b01895aa73 Support quoted psql parameters with placeholder templater (#5880) 2024-06-08 18:53:59 +00:00
James Johnston
e969fd32d7 Don't indent invisible template slices (#5938) 2024-06-08 18:32:40 +00:00
Adam Weeden
dc9f74e73d 5944: Add support for databricks named parameters (#5946)
Co-authored-by: Adam Weeden <adam.weeden@encoura.org>
2024-06-05 19:20:23 +00:00
Adam Weeden
5976a2c6ce Add support for Databricks TRACK HISTORY (#5948)
Co-authored-by: Adam Weeden <adam.weeden@encoura.org>
2024-06-05 19:17:46 +00:00
Kazuhito Osabe
f87d46c35e BigQuery: Support various ALTER statements (#5943) 2024-06-05 19:11:40 +00:00
Filipp Abapolov
600a31c6cf ClickHouse query-level SETTINGS support (#5941) 2024-06-04 16:37:54 +00:00
Heinz Wiesinger
0349fa7178 MySQL: Add support for generated columns (#5939) 2024-06-03 20:25:40 +00:00
stephnan
11026bdca5 Exasol: add REGEXP_LIKE (#5936) 2024-06-02 06:17:21 +00:00
Atishay Jain
aed2060788 SQLite: Over clause support for window functions (#5935) 2024-06-02 06:06:27 +00:00
Dr J Welch
67615e77bb T-SQL: Parameter assignment in SELECT vs alias (#5934)
Co-authored-by: Jason Welch <jwelch@calrom.com>
Co-authored-by: Jason Welch <jwelch@kalrom.local>
2024-05-31 19:58:03 +00:00
Atishay Jain
cb958d93cd SQLite: Add named parameters support (#5914) 2024-05-31 17:17:43 +00:00
Atishay Jain
85c85079c6 SQLite: Support with key as a column name (as needed by json_each) (#5918)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-05-30 19:22:15 +00:00
James Johnston
580d5cc983 Add loader_search_path setting to Jinja templater (#5930) 2024-05-30 18:23:23 +00:00
Atishay Jain
cd30f3c9f1 SQLite: Add support for JSON functions. Fixes #5896 (#5917) 2024-05-30 09:53:29 +00:00
keraion
804a38af74 dbt Templater: Suppress dbt 1.8 log messages (#5907) 2024-05-30 09:42:53 +00:00
James Johnston
67e9ce031a Clarify docs around subdir handling when loading macros (#5924) 2024-05-30 09:33:00 +00:00
Andrey Nikolaev
06b22f56a8 fix: add missing comma in Snowflake file types list (#5923) 2024-05-29 14:52:09 +00:00
Atishay Jain
9b17c57cab SQLite: Specialize create view with support for temporary views. (#5919) 2024-05-29 11:55:24 +00:00
Kazuhito Osabe
b813cc68ab BigQuery: Fix array type parsing (#5912) 2024-05-26 04:17:17 +00:00
Kazuhito Osabe
7c41272e39 BigQuery: Support unimplemented alter table and view statements (#5911) 2024-05-26 04:16:16 +00:00
github-actions[bot]
6c22f5ecd9 Prep version 3.0.7 (#5903)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-05-23 10:14:31 +01:00
Enduriel
b4318273fa Add more minor features and fixes to sqlite dialect (#5894) 2024-05-21 00:58:11 +00:00
Pavel-Strybuk
3aae379b24 Fix Clickhouse identifiers format (#5890)
Co-authored-by: Pavel Strybuk <pstr@tut.by>
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2024-05-20 18:21:01 +00:00
Enduriel
a2b55e7d32 Add full support for on conflict clause in SQLite (#5888)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2024-05-20 18:07:41 +00:00
keraion
d649e97240 dbt Templater Plugin: dbt 1.8 support (#5892)
Co-authored-by: Kazuhito Osabe <kzosabe@wip.place>
2024-05-20 17:36:27 +00:00
harshsoni2024
dd04c83c9e Added support for oracle materialized view (#5883)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2024-05-16 18:17:36 +00:00
Kazuhito Osabe
c05b0f99b3 BigQuery: Support ALTER TABLE ADD KEY statements (#5881) 2024-05-14 21:56:05 +00:00
Kazuhito Osabe
5040383080 MySQL: Support DIV and MOD operators (#5879) 2024-05-14 21:36:24 +00:00
Tim Church
78af450129 Update documentation to include all templaters (#5873) 2024-05-14 21:22:38 +00:00
Kazuhito Osabe
bd67302ef3 MySQL: Define date part function names (#5874) 2024-05-14 20:09:26 +00:00
Arkadiy Illarionov
1d4fd8d288 Remove typing_extensions requirement (#5860) 2024-05-08 21:17:50 +00:00
Kazuhito Osabe
d574b46e3e BigQuery: Fix EXPORT DATA statement (#5859) 2024-05-07 16:12:37 +00:00
Kazuhito Osabe
edce4978d9 BigQuery: Support CREATE INDEX statements (#5858) 2024-05-07 16:11:05 +00:00
github-actions[bot]
75cf64841b Prep version 3.0.6 (#5853)
Co-authored-by: WittierDinosaur <WittierDinosaur@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-05-06 20:36:13 +01:00
Konstantin Smirnov
4838e89e7a [fix_clickhouse] Temporary Table Create AS SELECT (#5843)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-05-06 15:04:42 +00:00
Danny Jones
99b09d42ea Bugfix: ST02 - Compare entire condition expression (#5850) 2024-05-06 09:39:44 +00:00
Konstantin Smirnov
49d48a5960 Clichouse prewhere (#5849) 2024-05-06 09:38:36 +00:00
Kazuhito Osabe
d48ded5606 BigQuery: Support missing DROP statements (#5848) 2024-05-04 14:09:50 +00:00
Greg Finley
019922a90b BigQuery: various CREATE statements (#5846) 2024-05-04 14:06:54 +00:00
Greg Finley
4f6760e4d8 BigQuery Alter Schema (#5835) 2024-05-03 17:32:00 +00:00
Greg Finley
d2e448a1aa Snowflake execute immediate from (#5836) 2024-05-03 17:29:17 +00:00
Danny Jones
b326066d1a Support dbt 1.7 (#5842) 2024-05-03 17:11:14 +00:00
Greg Finley
baceed9907 Postgres: Create extension cascade (#5834) 2024-05-01 09:17:38 +00:00
burhan
442a583886 Postgres: Add Support for PostGIS operators (#5830) 2024-04-30 14:00:46 +00:00
keraion
66eca75e07 Db2: Support additional CREATE INDEX options (#5827) 2024-04-30 09:19:59 +00:00
Oliver Borchert
965d08789e Allow to align all siblings when respacing (#5826)
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-04-29 17:25:35 +00:00
keraion
9579a2418b BigQuery: Support EXECUTE IMMEDIATE (#5820) 2024-04-28 13:33:42 +00:00
Kazuhito Osabe
d78c8daa8f BigQuery: Support CREATE ROW ACCESS POLICY statement (#5821) 2024-04-28 13:25:44 +00:00
Alan Cruickshank
22fc89ee7b Fix Jinja variant location correction (#5814) 2024-04-26 15:47:44 +00:00
Alan Cruickshank
3844bbc1ca Test cases for linter fails. (#5815) 2024-04-26 08:53:50 +00:00
keraion
fa54b61843 BigQuery: Support nested BEGIN, Fix CREATE PROCEDURE OPTIONS (#5816) 2024-04-26 07:19:47 +00:00
Alan Cruickshank
4830bbc45a Bring multiple jinja variants through to the parser. (#5794)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-04-25 21:42:43 +00:00
Alan Cruickshank
7ccbcd2d8f Fix placeholder labelling (#5813) 2024-04-25 18:16:15 +00:00
Alan Cruickshank
56095d4910 Tighten up the return from .process() (#5810) 2024-04-25 11:31:33 +00:00
Kazuhito Osabe
b5efbff16b BigQuery: Support CREATE MATERIALIZED VIEW AS REPLICA OF (#5811) 2024-04-25 11:28:35 +00:00
Kazuhito Osabe
baaea2e8ed BigQuery: Support OPTIONS in CREATE FUNCTION statement (#5812) 2024-04-25 11:27:49 +00:00
Martin
697eda1633 TSQL: fix ALTER TABLE ... SWITCH PARTITION (#5807) 2024-04-23 19:43:34 +00:00
keraion
9be4505df8 SparkSQL: Add functions that use UNIT keywords (#5806) 2024-04-23 14:24:54 +00:00
keraion
81af63d31c CLI: Add --stdin-filename option (#5805) 2024-04-23 14:23:53 +00:00
Martin
d28db5732d TSQL: parse CREATE/ALTER/DROP MASTER KEY (#5802) 2024-04-22 23:48:14 +00:00
Alan Cruickshank
6b77cecc29 Jinja Variant Configuration (#5785) 2024-04-22 16:34:52 +00:00
Alan Cruickshank
1362505951 Small refactor in jinja templater (#5786) 2024-04-22 13:51:44 +00:00
Kazuhito Osabe
da072050a4 BigQuery: Support FOR SYSTEM_TIME AS OF in CREATE TABLE CLONE statement (#5798) 2024-04-22 10:58:03 +00:00
Martin
feccf0000c TSQL: support for CREATE/ALTER PARTITION FUNCTION/SCHEME (#5793) 2024-04-21 21:27:40 +00:00
Kazuhito Osabe
8d4611bdc2 BigQuery: Support DEFAULT COLLATE segment (#5790) 2024-04-21 21:26:16 +00:00
Martin
7de3f0885c TSQL: support computed columns (#5792) 2024-04-21 15:23:08 +00:00
Alan Cruickshank
65895ca382 Simplify one of the lexer methods (#5788) 2024-04-20 12:50:57 +00:00
Alan Cruickshank
c168f35905 Improve light colour highlight (#5784) 2024-04-20 12:03:27 +00:00
Padraic McAtee
7435b0d3f7 SparkSQL: Support TIMESTAMP_LTZ and TIMESTAMP_NTZ types (#5783) 2024-04-20 12:01:59 +00:00
github-actions[bot]
fbf8fadf81 Prep version 3.0.5 (#5775)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-04-19 14:46:30 +01:00
Kazuhito Osabe
1f651ef573 BigQuery: Support CREATE SNAPSHOT TABLE statement (#5779) 2024-04-18 10:05:34 +00:00
Alan Cruickshank
bd07b605cd Upgrades to release actions. (#5774) 2024-04-15 18:17:10 +00:00
Kawashiro Nitori
f2b0c89fc8 Improve Snowflake syntax support (#5770)
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-04-14 18:31:44 +00:00
Martijn Hoogendoorn
26630cef9d TSQL: allow 'OR ALTER' on 'CREATE TRIGGER' (#5772) 2024-04-13 23:46:59 +00:00
keraion
4722f992bb Enhancement: Improved Identifiers - casefolding, quoted values, and basic escaping (#5726)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-04-13 19:29:09 +00:00
Mark
cbddd6d121 TSQL: Fix bare functions in default constraints (#5771) 2024-04-13 19:15:17 +00:00
Mateusz Olszewski
422a92b646 MySQL: Fix parsing 'ALTER TABLE ts ADD COLUMN modified_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP;' (#5766) (#5767) 2024-04-13 15:29:40 +00:00
github-actions[bot]
cda058e552 Prep version 3.0.4 (#5763)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-04-09 18:43:02 +01:00
Danny Jones
a88478c5d2 TSQL: Move PROPERTY to unreserved (#5759)
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-04-07 21:14:15 +00:00
Danny Jones
217c706bc9 Mysql: Add Character Set Literals (#5755) 2024-04-07 21:06:39 +00:00
Danny Jones
594782a8a2 Snowflake: Support ASOF Joins (#5756) 2024-04-07 21:05:54 +00:00
Danny Jones
c42c0434ce Mysql: Support scoped function calls (#5757) 2024-04-07 21:03:18 +00:00
Danny Jones
199a6cd071 Postgres: Support pgvector vector type (#5758) 2024-04-07 21:01:53 +00:00
Danny Jones
24a4b12578 SQLite: Support RETURNING Clause (#5760) 2024-04-07 20:56:40 +00:00
Danny Jones
f1bd34b2fb Postgres: Allow return control structures in atomic functions (#5761) 2024-04-07 20:56:04 +00:00
keraion
032ce0fb2a ST04: Retain comments when flattening CASE (#5753) 2024-04-07 14:07:35 +00:00
keraion
081a526670 dbt templater: Raise UserError when using stdin (#5752) 2024-04-07 12:49:09 +00:00
keraion
ca60440d91 SQLite: Add GLOB, MATCH. Improved REGEXP (#5745) 2024-04-04 10:25:05 +00:00
keraion
57b4266d7a Databricks: Fix Aliases for Join-like objects (#5748) 2024-04-04 10:24:56 +00:00
Danny Jones
e20d906fdf Add missing README ref, and issues labels (#5741) 2024-04-03 14:50:10 +00:00
MDW
127e07e8ad Qual: Add pre-commit to CI (#5730) 2024-04-01 21:19:41 +00:00
Iliyan Kostov
f400d6d1b2 Added support for 'greater/less than or equal' on ANSI CASE statement (#5728) 2024-04-01 18:49:32 +00:00
Oliver Borchert
ae0a45f3b2 Remove --force flag from pre-commit hook definition (#5739) 2024-04-01 18:44:08 +00:00
alecsgonz
68a3d12a64 adding snake_case to CP01 extended_capitalisation_policy (#5736)
Co-authored-by: alecsgonz <>
2024-04-01 14:13:04 +00:00
keraion
c6a4c7f5b0 ST04: Ignore simplifying CASEs with different expressions (#5735) 2024-04-01 13:59:28 +00:00
MDW
a9606c9f1f Fix #5724 mysql: Allow Line comments without space after -- (#5731) 2024-04-01 13:56:16 +00:00
MDW
7197f3fedf Fix spelling (#5729) 2024-04-01 10:57:53 +00:00
Kazuhito Osabe
50c4dcec76 Fix implementation for view_column_name_list in BigQuery's CREATE VIEW (#5738) 2024-04-01 10:55:07 +00:00
keraion
1e65dcd4dc CLI: Suppress tracebacks on render/fix/format (#5734) 2024-03-31 16:57:31 +00:00
Tom Chappell
125a4ab4ed Clickhouse: add parsing for select except clause (#5725) 2024-03-31 16:51:05 +00:00
Kirk Hansen
4f41700817 Add array type support to Trino dialect (#5722)
Co-authored-by: Kirk Hansen <kirk.hansen@corteva.com>
2024-03-27 16:36:01 +00:00
mariq41
48ee5e261b Fix/snowflake unparsable tag in create stmt (#5720)
Co-authored-by: Maria Velichkova <maria.velichkova@nestle.com>
2024-03-27 14:04:59 +00:00
mariq41
cc7a37eed7 Fix/snowflake ext storage (#5714)
Co-authored-by: Maria Velichkova <maria.velichkova@nestle.com>
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-03-27 13:57:49 +00:00
Tom Chappell
bab50f35a1 Clickhouse: add parsing for "distinct on" syntax (#5716) 2024-03-27 11:09:58 +00:00
Iliyan Kostov
cf60a4a402 added refresh mode init on create table statement (#5715) 2024-03-26 20:06:49 +00:00
Iliyan Kostov
0ce1ab9542 added ifNotExistsGrammar to Snowflake procedure (#5709)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-03-23 14:10:57 +00:00
Riley McDowell
c69d4c54cb Trino: 'TIMESTAMP(p)' no longer triggers LT01 (#5711) 2024-03-22 16:17:24 +00:00
Chris Kruger
cd3c511a5a Snowflake: add support for streamlit (#5692)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-03-22 12:25:39 +00:00
github-actions[bot]
40bdc4b95e Prep version 3.0.3 (#5707)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-03-22 11:56:49 +00:00
Payton Snider III
c994a3d926 [TSQL] Create columnstore indexes (#5708) 2024-03-21 22:29:46 +00:00
PolitePp
41a63f4755 [Vertica] fix gaps for some datatypes, complex alias support, fix group by for DDL (#5691)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-03-21 14:58:09 +00:00
Greg Finley
b2a4eab26f BigQuery: Unreserve KEY keyword (#5703) 2024-03-21 10:22:41 +00:00
Riley McDowell
13a438187c Trino: Add INTEGER synonym of INT (#5702) 2024-03-21 05:07:54 +00:00
Alan Cruickshank
ff9bfd799b Snowflake shouldn't reserve DO as a keyword. (#5699) 2024-03-20 02:36:54 +00:00
Alan Cruickshank
fcd9d02b47 Allow use of STREAM in snowflake CHANGES clause (#5698) 2024-03-19 22:26:37 +00:00
Riley McDowell
d996e9256f Trino: Parse regexp_replace with lambda func (#5683) 2024-03-19 21:32:16 +00:00
Maegan Whytock
10382dd5b7 Documentation update: Remove reference to alias' default config being "consistent" (#5689) 2024-03-19 21:22:43 +00:00
github-actions[bot]
5ac7e6e7bb Prep version 3.0.2 (#5686)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
2024-03-17 19:45:48 +00:00
Danny Jones
c3bbd71816 Snowflake: Support External Volumes (#5684) 2024-03-17 18:43:37 +00:00
Danny Jones
a8117b49cd T-SQL: Support Reconfigure (#5685) 2024-03-17 18:42:42 +00:00
keraion
9fdf539a55 CLI: Make --force deprecation print on stderr (#5681) 2024-03-16 12:36:28 +00:00
github-actions[bot]
5b39b51049 Prep version 3.0.1 (#5677)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-03-13 23:07:37 +00:00
Alan Cruickshank
1f13d9ab13 Fix 5673 (#5676) 2024-03-13 22:41:51 +00:00
github-actions[bot]
85c85bf0de Prep version 3.0.0 (#5660)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-03-12 19:39:28 +00:00
Alan Cruickshank
a1e28b733d Progressively load plugins (#5661) 2024-03-11 22:28:06 +00:00
keraion
5b5c6e1e24 Postgres: AL05, ignore aliases in values clause (#5669) 2024-03-10 20:46:21 +00:00
Ed Fawcett-Taylor
3fa56eeb05 Add Postgres CREATE FOREIGN TABLE statement (#5657)
Co-authored-by: Ed Fawcett-Taylor <Ed.Fawcett-Taylor@gigaclear.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-03-10 17:23:57 +00:00
keraion
4572998ddc Lexer: Handle escaped curly brace slices from the python templater (#5666) 2024-03-10 12:04:43 +00:00
keraion
d09b2de661 [CI]: Update pre-commit hook versions (#5665) 2024-03-10 12:03:20 +00:00
Andy Chan
cc4a84cfc1 Resolves #5624: Snowflake unparsable unset table options (#5664) 2024-03-10 12:02:20 +00:00
Alan Cruickshank
f8fd0fd2db Revert Ruff Changes (#5662) 2024-03-09 20:46:56 +00:00
Alan Cruickshank
f8fcd8b146 Complete the memory overhead work on cli fix (#5653) 2024-03-08 14:56:14 +00:00
andychannery
09fcb696b2 Resolve #5647: Snowflake unparsable variant access after cast (#5658) 2024-03-08 12:58:48 +00:00
Michael O Toole
ac42cd09f1 BQ PK and FK (#5654) 2024-03-06 15:24:35 +00:00
github-actions[bot]
ee8e5365a2 Prep version 3.0.0a6 (#5652)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-03-05 21:16:03 +00:00
Mitchell van Rijkom
55c411d900 Add Support for Databricks CREATE FUNCTION Syntax in SparkSQL Parser (#5615)
Co-authored-by: Mitchell van Rijkom <153460058+mvanrijkom@users.noreply.github.com>
2024-03-05 17:21:26 +00:00
Alan Cruickshank
27cebd93ae Swap fix --force for --check (#5650) 2024-03-05 16:26:49 +00:00
Alan Cruickshank
8029b1865c Remove DeprecatedOption (#5649) 2024-03-05 14:35:51 +00:00
Alan Cruickshank
c534d50c2f Resolve broken loop limit test (#5651) 2024-03-05 13:34:03 +00:00
Greg Finley
4548f0c46c Snowflake: Move NOTIFY to non-reserved words (#5645) 2024-03-04 10:50:07 +00:00
Greg Finley
cf47b769e6 BigQuery: GROUP BY ALL (#5646) 2024-03-04 10:49:47 +00:00
Andrey Nikolaev
b06d3f5a99 chore: use pre-calculated _code_indices in `BaseSegment::raw_segmen… (#5644) 2024-03-01 12:13:54 +00:00
Danny Mor
a1ec67514b Fix Snowflake Semistructured identifier parsing regex-expression (#5635)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2024-02-28 20:38:23 +00:00
Danny Jones
5d4c1d9775 Postgres: Update ReferentialActionGrammar to support sets of columns (#5628) 2024-02-28 20:18:22 +00:00
Danny Jones
d5375a6613 Snowflake: Add syntax for masking policy force (#5629) 2024-02-28 20:17:36 +00:00
Danny Jones
e6cac8b526 Postgres: Allow nested block comments (#5630) 2024-02-28 20:17:08 +00:00
Danny Jones
83a662a838 Postgres: Add Create, Alter, Drop Statistics (#5631) 2024-02-28 20:15:52 +00:00
Danny Jones
97d8600522 T-SQL Fix relative sql filepath lexer (#5632) 2024-02-28 20:15:07 +00:00
Danny Jones
b61abf094c Tech Debt: Replace some sequences with their Ref equivalents (#5633) 2024-02-28 20:13:53 +00:00
Danny Jones
c6bff3afaf ANSI/MYSQL: Support Create Role If Not Exists (#5634) 2024-02-28 20:12:24 +00:00
PolitePp
5e5b6929fd Add Vertica dialect (#5640)
Co-authored-by: Vladimir Krokodilov <vladimir.krokodilov@exness.com>
2024-02-28 12:26:46 +00:00
Mayur Singal
19650febcf Add Support for Snowflake Materialised View and Column Masking Policy (#5637) 2024-02-26 16:45:40 +00:00
Gary Shen
3ec5a0c898 [snowflake dialect] support ALTER TABLE ... ADD COLUMN IF NOT EXISTS (#5621) 2024-02-25 14:02:35 +00:00
keraion
f4712a09fe SQLite: Make DISTINCT FROM optional; SQLite/TSQL/Exasol: Nothing'd NanLiteralSegment (#5620) 2024-02-12 17:04:46 +00:00
Kirill Kozhakin
da223d238a Upgrade greenplum dialect (#5546)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-02-09 10:58:51 +00:00
Jeffrey Vo
83894f769f Oracle: parse length qualifier in types (#5613) 2024-02-09 10:40:04 +00:00
keraion
bc222cffd7 Multiple Dialects: Fix handling of nested sets expressions (#5606) 2024-02-08 17:33:46 +00:00
keraion
93c7429e26 DB2: Add labeled durations and special registers (#5612) 2024-02-08 17:32:36 +00:00
keraion
cb10b8cbc5 Sparksql: Fix LATERAL VIEW following JOIN; CLUSTER|SORT|DISTRIBUTE BY or QUALIFY without FROM (#5602) 2024-02-05 14:46:17 +00:00
Alan Cruickshank
b7f6933ac5 File helpers and config test parameterisation. (#5579) 2024-02-05 09:58:34 +00:00
Alan Cruickshank
304e974d04 Memory overhead optimisations during linting (#5585) 2024-02-02 09:46:54 +00:00
maoxd
cdf013c8b9 fix: multiple columns foreign key constraint (#5592) (#5594) 2024-02-01 17:30:09 +00:00
Antoine Facchini
ddc3b46f38 [CI] Add no_implicit_reexport mypy check (#5509)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-01-31 15:53:22 +00:00
github-actions[bot]
36c918597c Prep version 3.0.0a5 (#5512)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2024-01-30 23:09:32 +00:00
Francis Nimick
fa8a237118 Add support & test for postgres alter policy with multiple clauses (#5577)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-01-30 22:01:57 +00:00
Alan Cruickshank
018e881e1a Update github actions to latest versions (#5584) 2024-01-30 21:34:42 +00:00
alangner
9b0a0bc011 Allows using dbt cross project ref in jinja templater (#5574)
Co-authored-by: Andy Langner <git@alangner.de>
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-01-30 13:23:52 +00:00
James Johnston
9ae31ff0aa Improve support for Jinja templater plugins with custom tags (#5543)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-01-29 20:08:02 +00:00
keraion
5d5ffb1983 Databricks: fix EXCEPT with qualified column reference (#5557)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2024-01-29 13:36:17 +00:00
Alan Cruickshank
d44bcbbdf7 Stricter recommended config for not_equals convention (#5580) 2024-01-29 13:35:09 +00:00
keraion
273c3d86c3 CV01: Add options for ANSI and consistent style. (#5539) 2024-01-29 12:55:41 +00:00
keraion
16c28afd40 DuckDB: Fix REPLACE after EXCLUDE. Fix AL03 linting for wildcard like expression. (#5556)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-01-29 10:32:04 +00:00
keraion
6f44680bad Clickhouse: Add GLOBAL JOIN, GLOBAL IN, and PASTE JOIN (#5560)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2024-01-29 10:22:23 +00:00
j-svensmark
c738fc7fd0 [Docs] Use extended policy for identifier capitalisation in starter config (#5562) 2024-01-29 10:05:53 +00:00
keraion
de7bf4213e Build: linting black 24.1.0 rules update (#5573) 2024-01-29 10:04:15 +00:00
k1drobot
0591b0ace9 Snowflake: Updating Snowflake dialect to pass acceptable RLS policy objects (#5559)
Co-authored-by: Brandon Ng <brandon.ng@disneystreaming.com>
2024-01-25 23:37:25 +00:00
Michael O Toole
8b61b2d4de Redshift Syntax: ALTER APPEND (#5545) 2024-01-16 15:48:03 +00:00
keraion
c37deca8cb DuckDB: Add ANTI, SEMI, ASOF, and POSITIONAL joins (#5544) 2024-01-15 11:59:25 +00:00
Anton Stukanov
a524ba9cb1 MySQL: fix FIRST keyword in ALTER ADD/MODIFY (#5537) 2024-01-15 08:07:52 +00:00
keraion
ba10957fb4 Postgres/DB2/Oracle: Fix comma join LATERAL. (#5533) 2024-01-11 06:57:42 +00:00
aayushr7
f8c4651270 Add new Rule AL09: Avoid Self Alias (#5528) 2024-01-10 08:41:58 +00:00
keraion
bd611d0966 Rule AL01: disabled for Oracle dialect (#5517) 2024-01-09 09:35:27 +00:00
Remy
5b8335e66a Postgres ALTER EXTENSION support: dialect & tests (#5527) 2024-01-09 00:38:37 +00:00
keraion
68736e3142 SparkSQL: Add UNPIVOT syntax. Fix TABLESAMPLE aliases. (#5524) 2024-01-08 17:09:02 +00:00
keraion
c8ee7fcd4f DuckDB: Added support for PIVOT and UNPIVOT (#5514) 2024-01-08 17:05:31 +00:00
Sönke Korfhage
ee9a5b8205 Fix parse error databricks window function starts with order by (#5493)
Co-authored-by: Sönke Korfhage <s.korfhage@oraylis.de>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-12-27 15:12:08 +00:00
reata
3a5cc7e4df Hive: allow UDTF to return multiple column aliases in SELECT (#5495)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-12-27 15:11:03 +00:00
keraion
9b08260b6a DB2: Add support for DECLARE GLOBAL TEMPORARY TABLES, OFFSET, CALL, and non-bracketed VALUES (#5508)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-12-27 15:09:38 +00:00
keraion
b56ad469d9 DuckDB: Add CREATE OR REPLACE TABLE syntax (#5511) 2023-12-27 10:42:38 +00:00
Greg Finley
f09c9c8225 TSQL: Top and Distinct in same query (#5491)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-12-26 18:36:29 +00:00
Roc Wong
4c349be745 [Spark/Databricks] Fix: make COLUMNS in APPLY CHANGES INTO optional (#5498)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-12-26 17:51:26 +00:00
reata
b274ffc920 SparkSQL: exclamation mark as logical not (#5500)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-12-26 17:46:51 +00:00
reata
671bd91503 SparkSQL: allow value in set_statement to be Java class name (#5504)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-12-26 17:44:43 +00:00
reata
206265891f SparkSQL: allow distribute/sort/cluster by at end of set operation (#5502) 2023-12-26 17:38:05 +00:00
Antoine Facchini
c736639d0a [CI] Add a few more mypy ckecks (#5505) 2023-12-26 16:27:18 +00:00
Dhiraj Gupta
ea10860c4f Snowflake dialect: Add support for DATABASE ROLE in GRANT/REVOKE (#5490) 2023-12-22 22:55:11 +00:00
keraion
e49248cd7b DuckDB: Qualify and From-First (#5485)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-12-21 18:40:16 +00:00
Anton Stukanov
6789bbedae MySql: create table: allow null/not null in any position (#5473) 2023-12-21 16:27:41 +00:00
Dhiraj Gupta
5df81e6da1 Snowflake dialect: Support for CREATE DATABASE ROLE (#5475)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-12-21 10:07:43 +00:00
Kai-Yanna Meighu
4668f1de8c Clickhouse Dialect - Support BackQuoted Identifiers (#5457) 2023-12-11 21:15:15 +00:00
Ryan Despain
c9fa71b3f9 Change Color.lightgrey to have a white background - dark theme friendly (#5458) 2023-12-10 18:02:56 +00:00
Barry Pollard
ec6f46d865 Fix indentation for single cube clause (#5462) 2023-12-07 15:35:54 +00:00
github-actions[bot]
cd725c61a9 Prep version 3.0.0a4 (#5455)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-12-05 10:54:34 +00:00
Alan Cruickshank
100c628bba Build out rule and fix serialisation (#5364) 2023-12-05 09:43:11 +00:00
Alan Cruickshank
44143cfdad Add warning about github actions annotations limit (#5450) 2023-12-04 15:42:44 +00:00
gvozdvmozgu
cae3f932ca chore: remove unused line initialization in ParseContext (#5448) 2023-11-30 23:09:42 +00:00
Alan Cruickshank
9225f27463 Refine CLI testing fixture (#5446) 2023-11-30 22:21:58 +00:00
Alan Cruickshank
a4f389916f Update black linting (#5447) 2023-11-30 18:35:15 +00:00
github-actions[bot]
2574709112 Prep version 3.0.0a3 (#5444)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-11-29 16:48:53 +00:00
gvozdvmozgu
46f467d759 fix assertion in test__api__lint_string_specific_exclude_single (#5437) 2023-11-27 21:21:09 +00:00
Greg Finley
b883304c68 Databricks CLUSTER BY and OPTIMIZE (#5436) 2023-11-27 20:57:35 +00:00
Greg Finley
e41767058a TSQL: ON DELETE NO ACTION (#5434) 2023-11-27 19:47:21 +00:00
Greg Finley
4e36eafaf8 Snowflake dynamic table (#5435) 2023-11-27 19:45:12 +00:00
Roc Wong
e9a40e3794 Support parsing CONSTRAINT definitions when creating Delta Live Tables in SparkSQL/Databricks (#5438) 2023-11-27 19:23:17 +00:00
Mark Baas
4433a18735 adds few fixes for databricks/sparksql (#5431)
Co-authored-by: Mark Baas <m.baas@farmtrace.com>
2023-11-24 18:17:45 +00:00
Greg Finley
2a4f7d5d12 TSQL: CREATE USER {FOR|FROM} LOGIN (#5426) 2023-11-23 13:50:23 +00:00
Greg Finley
38939ac454 Snowflake Create table order/noorder (#5421) 2023-11-21 12:19:13 +00:00
Greg Finley
83d57f16b7 Simplify Snowflake regexes (#5419) 2023-11-18 14:11:43 +00:00
Yoichi NAKAYAMA
a9c2072127 Permit .* after each tbl_name in multi-table delete syntax (#5408) 2023-11-18 02:21:43 +00:00
Jon Grace-Cox
bc794fb504 Fix snowflake add search optimization grant (#5412) 2023-11-17 20:22:38 +00:00
Yoichi NAKAYAMA
f31a0b0f11 ANSI: Allow combination of UNION clause and WITH clause (#5413) 2023-11-17 20:19:34 +00:00
Danny Jones
29025f1262 SQLite: Allow block comments to be terminated by end of input (#5400)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-11-12 23:40:17 +00:00
Alan Cruickshank
fd9b297be6 Update publish github action to use kebab case (#5392) 2023-11-09 01:36:01 +00:00
github-actions[bot]
04192fabd7 Prep version 3.0.0a2 (#5391)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-11-09 01:27:57 +00:00
Alan Cruickshank
58741def84 Update publish actions and Dockerfile. (#5390) 2023-11-08 22:35:40 +00:00
github-actions[bot]
4d8f7471de Prep version 3.0.0a1 (#5381)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-11-08 18:10:25 +00:00
Alan Cruickshank
4c387d1ad9 Move the rest of pytest over to pyproject.toml (#5383) 2023-11-08 16:46:38 +00:00
Alan Cruickshank
3aa12f80ec Move doc8 over to pyproject (#5385) 2023-11-07 15:19:17 +00:00
Alan Cruickshank
6741b98f34 Remove exceptions for typing stubs that now exist. (#5382) 2023-11-06 22:03:14 +00:00
Alan Cruickshank
ef7ac7ac20 Migrate to pyproject.toml for the core project. (#5373) 2023-11-06 17:24:25 +00:00
ishiis
e7715718c6 Fix the snippet from a pyproject.toml in configuration.rst (#5378) 2023-11-06 16:04:27 +00:00
Danny Jones
a76d3a5d86 Snowflake: Support AlterNetworkPolicy Statements (#5377) 2023-11-06 00:24:50 +00:00
Felix Wischke
14d0cb8625 postgres: add support for bodies of "language sql" functions (#5376)
Co-authored-by: Felix Wischke (65278) <felix@zeynix.de>
2023-11-05 17:38:00 +00:00
João Filipe Cavichiolo Storrer
dff75d2442 Add support for SET NAMES statement in MySQL (#5374) 2023-11-04 09:21:07 +00:00
João Filipe Cavichiolo Storrer
b5b5f31f06 Fix GRANT ALL PRIVILEGES statement in MySQL (#5375) 2023-11-04 09:19:25 +00:00
Alan Cruickshank
24c7ed2cee Another extraction of fixing logic. (#5365) 2023-11-02 21:26:22 +00:00
Alan Cruickshank
a36477cc91 Remove root requirements.txt (#5372) 2023-11-02 18:13:59 +00:00
Jay Chung
005a78ed3c Drop support of python 3.7 (#5288)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-11-02 17:33:59 +00:00
golergka
6e62fd789c API configuration documentation (#5369)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-11-02 14:55:29 +00:00
Willy Hardy
323f78d11f add listagg extras support in trino dialect (#5368)
Co-authored-by: Willy Hardy <whardy@redhat.com>
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-10-31 20:20:30 +00:00
Alan Cruickshank
a8f5f4501b Allow ignoring of comments from indentation entirely #3311 (#5363) 2023-10-31 16:30:54 +00:00
Danny Jones
5168f2faba Trino: Support Analyze statements (#5361) 2023-10-29 16:02:43 +00:00
Alan Cruickshank
d7455bfeff Resolve #5327 (logging to stdout) (#5362) 2023-10-29 13:54:17 +00:00
github-actions[bot]
472f9b8998 Prep version 2.3.5 (#5360)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-10-27 20:29:44 +01:00
Alan Cruickshank
ebba18a462 One (very) small typing improvements (#5355) 2023-10-25 22:47:02 +00:00
Alan Cruickshank
25edad331f Unpick dependencies between modules in sqlfluff.core (#5348) 2023-10-25 18:34:04 +00:00
Alan Cruickshank
75a40c1d0b Resolve SparkSQL re-parsing issue + test validation in test suite. (#5351) 2023-10-25 16:22:17 +00:00
Jason Schweier
8a04e90bdf Snowflake: Support ALTER MASKING POLICY (#5350) 2023-10-25 16:03:16 +00:00
Alan Cruickshank
92ceb23c99 Add a public API for nesting config strings. (#5349) 2023-10-25 09:48:53 +00:00
Alan Cruickshank
65328e6b70 Update handling of dbt compilation errors (#5345) 2023-10-24 21:32:03 +00:00
Danny Jones
2f50f68c7e Snowflake - Extend Column Default Constraint (#5343) 2023-10-23 23:46:34 +00:00
kang
a0024d556f Fix the dbt anchor link in the realworld documentation (#5341) 2023-10-23 12:42:49 +00:00
Shubham S Jagtap
77fd115ae8 Update README.md (#5340) 2023-10-22 16:44:42 +00:00
Alan Cruickshank
b3a96e56e8 Logic to render variants of Jinja templates for more coverage. (#5339) 2023-10-20 15:59:21 +00:00
Alan Cruickshank
1b6ef3773e Templater slicing refactoring of RawFileSlice (#5338) 2023-10-19 19:28:38 +00:00
abdel
358b0c2b3b BigQuery: Support multiple statements in the BEGIN..EXCEPTION..END (#5322) 2023-10-19 17:23:56 +00:00
Alan Cruickshank
9579127595 Remove codecov traces (#5337) 2023-10-18 15:05:40 +00:00
github-actions[bot]
10c38653a5 Prep version 2.3.4 (#5336)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-10-18 00:05:32 +01:00
Alan Cruickshank
5843929898 Commas fix in LT09 (#5335)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-10-17 22:37:52 +00:00
Alan Cruickshank
84a54fc827 UUID Comparisons (#5332) 2023-10-17 08:42:05 +00:00
Alan Cruickshank
7299f23a4f Two depth map performance improvements (#5333) 2023-10-17 08:26:55 +00:00
Alan Cruickshank
67d86af41a Stash parent idx with parent reference (#5331) 2023-10-17 08:26:36 +00:00
Alan Cruickshank
c694d05b02 Set to FrozenSet in segment class_types (#5334) 2023-10-16 20:57:38 +00:00
Enzo Bonnal
7dcee95f04 Add support for ANY_VALUE( _ HAVING MIN/MAX _ ) to BigQuery dialect (#5321) 2023-10-16 11:27:45 +00:00
João Filipe Cavichiolo Storrer
8bf49bc7ef Fix parsing error when using quoted slash in Oracle (#5323) 2023-10-16 11:18:46 +00:00
João Filipe Cavichiolo Storrer
294e8440b4 Add support for functions and procedures calls via database link in Oracle (#5326) 2023-10-16 11:14:15 +00:00
João Filipe Cavichiolo Storrer
7b7631da73 Fix parsing error with table name '_' in MySQL (#5324) 2023-10-16 11:12:42 +00:00
github-actions[bot]
2447559c30 Prep version 2.3.3 (#5308)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2023-10-13 20:45:51 +00:00
João Filipe Cavichiolo Storrer
3b57280f7d Oracle space between alias and column reference (#5313) 2023-10-13 19:50:25 +00:00
Alan Cruickshank
086a36ca29 Don't apply LT05 on templated rebreak locations #5096 (#5318) 2023-10-13 16:00:56 +00:00
Alan Cruickshank
8e172dc6ae Disable JJ01 unless jinja active (#5319) 2023-10-13 16:00:18 +00:00
Alan Cruickshank
dd00a49815 Cache the BaseSegment hash in reflow (#5320) 2023-10-13 15:55:31 +00:00
Alan Cruickshank
d481756a59 Better error reporting for invalid macros (#5317) 2023-10-13 09:03:05 +00:00
João Filipe Cavichiolo Storrer
b36755d2a3 Add support for begin atomic functions in Postgres (#5316) 2023-10-13 08:12:01 +00:00
João Filipe Cavichiolo Storrer
0953a15171 Fix parsing when statement uses plus_sign_join and function in Oracle (#5315) 2023-10-12 22:00:29 +00:00
Alan Cruickshank
e2fc45e9bb Update rule docs with correct config (#5314) 2023-10-12 21:57:30 +00:00
Alan Cruickshank
e616b06aa1 Resolve #5258. More robust algorithm for multiline fix. (#5309) 2023-10-12 15:44:53 +00:00
abdel
031962d67e BigQuery: Add support for BEGIN..EXCEPTION...END block (#5307) 2023-10-12 10:26:19 +00:00
Alan Cruickshank
b9ea5733b7 Refine placement of metas around templated blocks (#5294) 2023-10-11 16:18:23 +00:00
Alan Cruickshank
c117afa07e Extend ruff checking to docstring rules (#5302) 2023-10-10 20:31:16 +00:00
Alan Cruickshank
c93f42a67b Fix for strange TSQL bugs (#5306) 2023-10-10 21:20:47 +01:00
Alan Cruickshank
3d9135ba70 Staging PR for #5282 (#5305)
Co-authored-by: Romain Petit <63579439+r-petit@users.noreply.github.com>
2023-10-10 19:28:26 +01:00
Alan Cruickshank
ca155845d6 Resolve some strange whitespace indentation behaviour (#5292) 2023-10-10 16:55:48 +00:00
Alan Cruickshank
1ae18fde9c Simplify _process_lint_result (#5304)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-10-10 16:53:11 +00:00
Alan Cruickshank
8ebe8c5de4 Performance improvement on segment comparison (#5303) 2023-10-10 14:14:17 +00:00
Alan Cruickshank
faefb69ef0 Refactor LT09 (#5299) 2023-10-10 14:14:05 +00:00
João Filipe Cavichiolo Storrer
6683bb4bc8 Change drop function to allow DropBehaviourGrammar with space after function name (#5295) 2023-10-10 10:57:02 +00:00
Alan Cruickshank
56e45e2aba Resolve click import options on autocomplete (#5293) 2023-10-10 10:54:15 +00:00
freewaydev
4401ef9782 Updated docstrings with missing args/returns/etc info, added missing docstrings, minor formatting fixes. (#5278)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-10-10 08:54:31 +00:00
Jay Chung
eb6b96ba64 Use ruff rule I replace isort (#5289)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-10-09 15:20:09 +00:00
Jason Schweier
4d5af85abe Snowflake: Parse ALTER DATABASE statement (#5284) 2023-10-09 13:32:09 +00:00
Jason Schweier
8b3f320149 Snowflake: Parse ALTER ACCOUNT statements (#5283) 2023-10-09 13:31:38 +00:00
pppp56
7bc9b2e98f Snowflake: create AlterProcedureStatementSegment (#5291)
Co-authored-by: pascal.moreau <pascal.moreau@yousign.com>
2023-10-09 13:30:40 +00:00
Alan Cruickshank
106cac1c43 Rewrite of matching interface (#5230) 2023-10-08 22:29:35 +01:00
David Wales
a705248cb6 Follow noqa in block comments (#5133)
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-10-07 14:32:53 +00:00
João Filipe Cavichiolo Storrer
2de0f6438b Fix insert on conflict with function in Postgres (#5286) 2023-10-07 07:44:27 +00:00
João Filipe Cavichiolo Storrer
838b25efb4 Add support for Pivot and Unpivot clauses in Oracle (#5285) 2023-10-07 07:43:06 +00:00
bpfaust
57c4139309 Adding "create table as" for greenplum dialect (#5173)
Co-authored-by: bfaust2 <benjamin.faust@epsilon.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-10-06 17:49:21 +00:00
Alan Cruickshank
0e62388de6 Update CI to python 3.12 (#5267) 2023-10-06 17:47:03 +01:00
pppp56
eda2f03253 Snowflake: Add CreateResourceMonitorStatementSegment & AlterResourceMonitorStatementSegment (#5272)
Co-authored-by: pascal.moreau <pascal.moreau@yousign.com>
2023-10-06 13:43:04 +00:00
Romain Petit
2d62fd7df8 [TSQL] Add create fulltext index statement segment class (#5274) 2023-10-05 11:45:40 +00:00
pppp56
fd209f746e Snowflake: Add CreateSequenceStatementSegment & AlterSequenceStatementSegment (#5270)
Co-authored-by: pascal.moreau <pascal.moreau@yousign.com>
2023-10-05 11:44:13 +00:00
pppp56
3fdd67e527 Add CommaSegment to AlterWarehouseStatementSegment SET clause (#5268)
Co-authored-by: pascal.moreau <pascal.moreau@yousign.com>
2023-10-05 11:42:22 +00:00
Jason Schweier
7cf7b883ac Snowflake: Parse EXECUTE IMMEDIATE clause (#5275) 2023-10-05 11:41:42 +00:00
Romain Petit
f4c5dde372 TSQL: Add missing HISTORY_RETENTION_PERIOD sequence to the table option segment (#5273) 2023-10-04 07:19:23 +00:00
pppp56
5680394b82 Snowflake: Fix ScalingPolicy and WarehouseType Refs in WarehouseObjectProperties and use ObjectReferenceSegment in AlterWarehouseStatementSegment (#5264)
Co-authored-by: pascal.moreau <pascal.moreau@yousign.com>
2023-10-02 15:36:41 +00:00
Alan Cruickshank
72dde7ded4 Finish the removal of GreedyUntil (#5263) 2023-10-02 15:34:50 +00:00
João Filipe Cavichiolo Storrer
8e14e5ab3f Add support for date operations with intervals in Oracle (#5262) 2023-10-01 09:06:18 +00:00
Alan Cruickshank
595ad1f470 Change RawSegment type to instance_types (#5253) 2023-09-28 22:59:20 +00:00
Alan Cruickshank
ac7834621b Revise MatchableType -> Matchable (#5252) 2023-09-28 19:09:48 +00:00
Alan Cruickshank
64502c81cf Unnest fixing and re-address validation triggers (#5249) 2023-09-28 16:02:51 +00:00
andychannery
330f218514 Resolves #5174: Snowflake alter table constraint (#5247) 2023-09-27 16:59:41 +00:00
Alan Cruickshank
35d1bf5273 Bring together the generic segments (#5243) 2023-09-27 16:13:28 +00:00
Justin Bassett-Green
a36f7eace0 minor: update docs with correct link to airflow ds_filter (#5244) 2023-09-27 13:37:54 +00:00
Robin Rump
3b09e669e7 #5245 - Snowflake dialect: Adds support for variable definitions in scripting blocks (#5246) 2023-09-27 13:28:31 +00:00
Alan Cruickshank
ea3d2c7c66 Introduce "word" segment (#5234) 2023-09-26 21:12:24 +00:00
Robin Rump
ba91e8ca88 #5239 Added (basic) support for properly linted Snowflake scripting (#5242) 2023-09-26 19:16:34 +00:00
Kyle Andrews
5ea25f5681 Allow Snowflake pipe integration to be a quoted or unquoted (#5241) 2023-09-26 19:01:24 +00:00
Alan Cruickshank
efec603685 Fix LT01 alignment regression #4023 (#5238) 2023-09-26 19:00:18 +00:00
João Filipe Cavichiolo Storrer
2594d71819 Add support for oracle non ansi joins (#5231) 2023-09-26 14:17:47 +00:00
Kyle Andrews
c754a70511 add azure_storage_queue and quoted providers (#5236) 2023-09-26 12:14:51 +00:00
Alan Cruickshank
08f67bab72 Set type automatically within the lexer. (#5232) 2023-09-25 12:54:11 +00:00
andychannery
5a12ad600f Resolve #5225: Snowflake unparsable select replace (#5227) 2023-09-22 15:47:05 +00:00
Alan Cruickshank
b6c71f9499 Spark Accessor Grammars (#5226) 2023-09-22 15:43:49 +00:00
Alan Cruickshank
60bbdc73aa Test Script Timing (#5228) 2023-09-22 15:43:35 +00:00
Alan Cruickshank
fb8defaa4c Unify lexer names and types for brackets (#5229) 2023-09-22 15:43:25 +00:00
andychannery
40bb777e31 Resolve #3176: Snowflake unparsable array casting (#5224) 2023-09-21 20:43:26 +00:00
Greg Finley
81698cb5fe BigQuery system time syntax (#5220) 2023-09-21 20:34:54 +00:00
Alan Cruickshank
ede5ceedc5 Parser test nits (#5217) 2023-09-18 18:46:04 +00:00
Alan Cruickshank
6948754600 Remove parse_grammar (#5189) 2023-09-18 15:41:01 +00:00
Alan Cruickshank
16abd6b93e Revise segment whitespace validation (#5194) 2023-09-17 07:57:39 +00:00
João Filipe Cavichiolo Storrer
2e9b94f976 Add support for bpchar datatype in postgres (#5215) 2023-09-16 03:48:54 +00:00
Alan Cruickshank
3625934f16 Resolve #5203: BaseSegment.copy() isolation (#5206) 2023-09-15 18:42:14 +00:00
Dennis Hume
895e668a00 Update Materialize Syntax (#5210)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-09-14 17:58:25 +00:00
Alan Cruickshank
50848508d4 Validate fix parsing based on match_grammar (#5196) 2023-09-14 15:18:46 +00:00
Alan Cruickshank
50c4c51f1a Position assertions in BaseSegment (#5209) 2023-09-14 15:01:56 +00:00
Greg Finley
fe5585789b MySQL bracketed column constraint (#5208) 2023-09-14 07:58:53 +00:00
Alan Cruickshank
715d184bdc Dialect spacing & quoting issues (#5205) 2023-09-14 07:57:06 +00:00
Alan Cruickshank
ec514ebbdb Account for newline in commenter workflow 2023-09-13 01:54:39 +01:00
Alan Cruickshank
200504906d More updates to commenter workflow 2023-09-13 01:29:57 +01:00
Alan Cruickshank
23f3b83edb Fix issue number problem on comment job 2023-09-13 01:12:48 +01:00
Alan Cruickshank
53262b3d80 Correct filenames in commenter workflow 2023-09-13 00:57:31 +01:00
Alan Cruickshank
b6c74836b2 Update comment workflow again (#5201) 2023-09-13 00:42:22 +01:00
Alan Cruickshank
394a95a90e Stash PR Number and hydrate later (#5200) 2023-09-13 00:27:48 +01:00
Alan Cruickshank
2b40063b46 Fix API issues in github comment action (#5199) 2023-09-12 23:38:05 +01:00
Alan Cruickshank
b8e1311d99 Consistency check in root parse (#5191) 2023-09-12 16:20:23 +00:00
Alan Cruickshank
fbb7119f5d PR Comment action (#5192) 2023-09-12 16:16:49 +00:00
Alan Cruickshank
855a3094ba Cache python dependencies in GHA (#5193) 2023-09-12 16:14:54 +00:00
João Filipe Cavichiolo Storrer
5166b748d3 Add support for create server, create user mapping and import foreign schema in postgres (#5185)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-09-11 16:01:03 +00:00
Alan Cruickshank
d7a7087655 Terminators on Anything() + Strip _most_ of the other parse_grammar (#5186) 2023-09-11 15:49:23 +00:00
Alan Cruickshank
b9db9b9198 Parse modes for AnyNumberOf (#5187) 2023-09-11 14:05:51 +00:00
Alan Cruickshank
48ab0cac22 Introduce parse_mode and remove StartsWith & EphemeralSegment. (#5167) 2023-09-10 20:33:15 +00:00
github-actions[bot]
5dbc0aa71a Prep version 2.3.2 (#5184)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-09-10 12:45:42 +01:00
Shinya Yaginuma
4428162b5b Allow not specifying parameters names when using placeholder templater (#5101)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-09-10 11:12:41 +00:00
Alan Cruickshank
f6c0758ebd Update coverage job to run in the right conditions (#5183) 2023-09-09 15:53:54 +00:00
Greg Finley
78eae3a710 Duckdb: UNION BY NAME (#5176)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-09-08 21:49:23 +00:00
Alan Cruickshank
71e933f247 Output coverage report direct to PR (#5180)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-09-08 18:33:28 +00:00
Alan Cruickshank
4885d808a5 Upgrades to the parse fixture generation script (#5182) 2023-09-08 18:08:32 +00:00
Alan Cruickshank
8aaa34ed7c Refactor of Sequence match (#5177) 2023-09-08 16:05:54 +00:00
Alan Cruickshank
41b1ae28b5 Simplify Greedy Match (#5178) 2023-09-07 22:41:05 +00:00
Alan Cruickshank
7e09355713 Quality of life improvements on parse fixture script (#5179) 2023-09-07 19:10:47 +00:00
Alan Cruickshank
100aea0b28 Lift and shift matching algorithms (#5170) 2023-09-07 16:06:01 +00:00
Pierre-Loïc
9b48b61d45 Capitalise boolean values in example configs, for consistency (#5175) 2023-09-06 22:01:39 +00:00
Alan Cruickshank
d5a0ba0838 Pull terminator setting up into the base grammar (#5172) 2023-09-05 21:31:47 +00:00
Alan Cruickshank
74ff82b5ae Flip the if in sequence and un-nest (#5171) 2023-09-05 20:06:18 +00:00
reata
9fbb26b8e5 SparkSQL: Support CACHE TABLE without query (#5165) 2023-09-05 15:52:43 +00:00
Alan Cruickshank
5eca1c809a Remove configurable enforce_whitespace_preceding_terminator (#5162) 2023-09-05 15:50:29 +00:00
adilkhanekt
b2d1b45afc Adding optional sequence block for columns parsing in Snowflake external tables (#5157)
Co-authored-by: Qwerty <mail@mail.com>
2023-09-05 14:26:43 +00:00
reata
c060c36ade SparkSQL: Support ALTER TABLE SET LOCATION without partition spec (#5168) 2023-09-05 13:34:13 +00:00
Alan Cruickshank
b151329c5d Tighten terminators on Delimited (#5161) 2023-09-05 13:03:37 +00:00
Alan Cruickshank
4703717013 terminator > terminators on StartsWith (#5152) 2023-09-04 17:43:17 +00:00
reata
f7016a3960 Redshift: Support SELECT INTO (#5159) 2023-09-04 16:03:36 +00:00
Greg Finley
a2b43a4b59 Duckdb: Integer division (#5154) 2023-09-04 08:35:47 +00:00
Alan Cruickshank
2d4e5a094b terminator > terminators on Delimited grammar (#5150) 2023-09-04 04:54:56 +00:00
Alan Cruickshank
fe07a8e1d8 Tests for unparsable sections (#5149)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-09-02 23:43:51 +00:00
Alan Cruickshank
91f024e62d Un-nest the delimited match method (#5147) 2023-09-02 23:33:21 +00:00
Alan Cruickshank
635c6274a1 Grammar .copy() assert no unexpected kwargs (#5148) 2023-09-02 23:33:11 +00:00
Greg Finley
a06cdb0e75 Postgres: CLUSTER (#5146)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-09-02 18:18:54 +00:00
Christian Soto
fc471d9860 Postgres alter policy (#5138) 2023-08-31 23:29:24 +00:00
github-actions[bot]
d8a1be87c7 Prep version 2.3.1 (#5139)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-08-29 23:40:31 +01:00
Greg Finley
d5013742d9 Postgres: Update returning with alias (#5137) 2023-08-29 17:06:47 +00:00
Alan Cruickshank
b85f1ad0ef Reduce copying on _position_segments (improves fix) (#5119) 2023-08-29 14:06:57 +00:00
Alan Cruickshank
e59afee740 Import rationalisation (#5135)
Co-authored-by: Paul Wildenhain <35195136+pwildenhain@users.noreply.github.com>
2023-08-29 08:08:41 +00:00
Alan Cruickshank
39e04def14 Select Crawler Refactor: Part 3 (#5115) 2023-08-29 07:21:02 +00:00
João Filipe Cavichiolo Storrer
0a4ecf5072 Add support for comparison operators with space in Oracle (#5132)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-08-29 00:34:25 +00:00
Mayur Singal
001693179a Snowflake support for bracketed query after EXCEPT (#5126) 2023-08-28 20:45:11 +00:00
Alan Cruickshank
a66da90890 Treatment of null literals. #5099 (#5125) 2023-08-27 22:17:24 +00:00
Greg Finley
f89012d2c5 Allow double-quoted parameters in create procedure (#5131) 2023-08-27 16:21:28 +00:00
Alan Cruickshank
b67a7ae68e Fix coverage & mypy (#5134) 2023-08-27 16:04:00 +00:00
Alan Cruickshank
ba5f38c955 Ensure Unparsable can be given position. (#5117) 2023-08-23 07:04:30 +00:00
Alan Cruickshank
d4c9843315 Reduce copying in LintFix instantiation (#5118) 2023-08-22 22:47:54 +00:00
Alan Cruickshank
caf646835e Optimise crawl behaviour of JJ01 (#5116) 2023-08-22 22:40:36 +00:00
Alan Cruickshank
5840f68992 Simplify rules with improvement to SegmentSeeker (#5113) 2023-08-22 13:10:46 +00:00
Alan Cruickshank
70c4f8b058 Refactor AM07 (#5112) 2023-08-21 21:55:12 +00:00
Alan Cruickshank
8fb27a3a33 Select Crawler Refactor: Part 2 (#5110) 2023-08-21 10:23:11 +00:00
João Filipe Cavichiolo Storrer
35503ba753 Add support to Hierarchical Queries in Oracle (#5108) 2023-08-20 20:42:21 +00:00
Alan Cruickshank
9d049bcc38 Strict MyPy for sqlfluff.core.parser (#5107) 2023-08-20 20:38:20 +00:00
Alan Cruickshank
6e5c2fdc95 Free up pydocstyle again (#5109) 2023-08-20 15:05:39 +00:00
Greg Finley
ff340b84b0 Postgres: Allow CREATE TABLE INHERITS with no new columns (#5100) 2023-08-18 21:15:43 +00:00
Alan Cruickshank
44b5bc85b4 Strict mypy in parser.segments (#5094) 2023-08-18 11:05:11 +00:00
Alan Cruickshank
68ef48051d Select Crawler Refactor: Part 1 (#5104) 2023-08-18 10:23:29 +00:00
Alan Cruickshank
3b62564894 RF01 & recursive_crawl improvements (#5102) 2023-08-18 09:30:09 +00:00
Alan Cruickshank
af97c4a809 fix new more restrictive tox (#5103) 2023-08-17 17:21:01 +01:00
Mayur Singal
df4ef7d4fb Make Day as Non Reserved Keyword (#5062)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-08-14 18:01:42 +00:00
github-actions[bot]
263dc519ef Prep version 2.3.0 (#5084)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-08-14 19:58:44 +02:00
Alan Cruickshank
13280dd48c Remove IdentitySet (#5093) 2023-08-14 17:36:01 +00:00
Alan Cruickshank
97cfc311b5 Stricter typing in smaller sqlfluff.core.parser (#5088) 2023-08-13 17:27:24 +00:00
Eric Fung
7e28d59d55 Preliminary support of Trino dialect (#4913)
Co-authored-by: JeffWilcox9999 <86066409+JeffWilcox9999@users.noreply.github.com>
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
Co-authored-by: WittierDinosaur <daniel.jones@deliveroo.co.uk>
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-08-13 15:46:27 +00:00
Alan Cruickshank
376feb01a3 Rename ST09 (#5091) 2023-08-13 10:44:38 +00:00
Greg Finley
2b73b6850b TSQL: Fix Clustered Index asc/desc (#5090) 2023-08-13 10:44:29 +00:00
Alan Cruickshank
b4d53a51ec Parent references and more efficient path_to (#5076) 2023-08-12 21:47:23 +00:00
Alan Cruickshank
d7e14359c6 New Rule: AL08 - column aliases must be unique (#5079) 2023-08-12 21:47:22 +00:00
João Filipe Cavichiolo Storrer
11320a36d7 Add support for fetch first row(s) only in Oracle (#5089) 2023-08-12 15:12:45 +00:00
thibonacci
cd52dcaaf5 Fix bug around quoted identifiers for ST09 (#5087)
Co-authored-by: Thibault He <thibault.he@gmail.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-08-11 10:55:12 +00:00
Danny Jones
fdf2f68ab3 Add strict typing to the templating tracer (#5085)
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-08-10 21:07:26 +00:00
Alan Cruickshank
950c1d741e Remove recurse config (#5065) 2023-08-10 22:09:21 +01:00
Paul Wildenhain
1dc547e672 Strictly type dialect (#5067) 2023-08-10 20:35:51 +00:00
thibonacci
d67bc27d13 Add new rule ST09: Joins should list the table referenced earlier (default)/later first (#4974)
Co-authored-by: Thibault He <thibault.he@gmail.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-08-10 12:55:46 +00:00
Alan Cruickshank
a334084bb7 Remove the internal cProfiler option (#5081) 2023-08-10 12:51:00 +00:00
Alan Cruickshank
33916fc72f Optimisation on select analysis (#5082) 2023-08-10 11:30:01 +00:00
github-actions[bot]
fc91dcd94b Prep version 2.2.1 (#5080)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-08-09 21:34:39 +01:00
Alan Cruickshank
1d99f416e7 Split apart the grammar tests (#5078) 2023-08-09 15:44:56 +00:00
Alan Cruickshank
0ba4e4aba8 Resolve pickling of errors #5066 (#5074) 2023-08-09 06:52:50 +00:00
Alan Cruickshank
0b99ea642a Better context based tracking (#5064) 2023-08-09 01:04:52 +00:00
adityapat3l
7b7fd603a1 fixing limit handling for bracketed arithmathic operations (#5068)
Co-authored-by: Aditya Patel <apatel@fandm.edu>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-08-08 18:45:49 +00:00
Alan Cruickshank
8627a2e8c8 Never run in multiprocessing mode with only 1 file. (#5071) 2023-08-08 18:32:38 +00:00
Alan Cruickshank
eb4119f60c Add dbt 1.6 tests (#5073) 2023-08-08 17:41:45 +00:00
Alan Cruickshank
483734de23 Handle two kinds of dbt errors more gracefully (#5072) 2023-08-08 16:56:25 +00:00
Alan Cruickshank
6c2b4c15b3 Try to silence dbt logging #5054 (#5070) 2023-08-08 16:50:34 +00:00
Alan Cruickshank
1a72257df5 Move _prune_options within _longest_trimmed_match. (#5063) 2023-08-07 14:16:44 +00:00
adityapat3l
7d6550376e Fix issue 4998 - Add backup and auto refresh grammar to redshift materialized view (#5060)
Co-authored-by: Aditya Patel <apatel@fandm.edu>
2023-08-07 09:57:57 +00:00
Paul Wildenhain
8630b6e689 Add mypy strict typing for sqlfluff.core.rules (#5048)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-08-05 17:17:23 +00:00
Paul Wildenhain
6f9f62d9b0 ⬆️ Bump mypy version in pre-commit (#5055) 2023-08-05 11:46:25 +00:00
João Filipe Cavichiolo Storrer
e8953b81f5 Add SQL Plus bind variable support (Oracle) (#5053) 2023-08-05 06:54:44 +00:00
github-actions[bot]
b4a9a695e7 Prep version 2.2.0 (#5024)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-08-04 17:56:40 +01:00
Alan Cruickshank
1270eecea3 Mypy: Ephemeral + Tuple Return on .parse() (#5044) 2023-08-04 14:12:00 +00:00
João Filipe Cavichiolo Storrer
623d764b52 Add support to oracle's global and private temporary tables (#5039)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-08-04 13:52:29 +00:00
Josef Vondrlík
43b6d344d4 Redshift-dialect: Support GRANT USAGE ON DATASHARE (#5007) 2023-08-04 10:15:10 +00:00
Paul Wildenhain
094b05948a Add strict typing for errors module (#5047) 2023-08-04 09:57:25 +00:00
Alan Cruickshank
2e3c60f41b Less copying in the ParseContext (#5046) 2023-08-04 09:54:14 +00:00
William Felipe Welter
11f6257b24 Adding support to use ADD COLUMN IF NOT EXISTS syntax on ALTER TABLE (#5035) 2023-08-03 18:00:01 +00:00
João Filipe Cavichiolo Storrer
7141488b7d Closes #4815 (#5042)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-08-03 15:49:05 +00:00
Alan Cruickshank
b156d4d722 Fix for multiprocessing warnings. (#5032) 2023-08-03 12:35:04 +00:00
Alan Cruickshank
427bdae97f Mypy gain: Remove unnecessary tuple construction in MatchResult (#5045) 2023-08-03 11:04:34 +00:00
Paul Wildenhain
8cec5cb8a0 mypy strict in config (#5036) 2023-08-02 20:55:50 +00:00
Alan Cruickshank
201eaea28d strict mypy: match_wrapper & match_logging (#5033) 2023-08-02 14:28:13 +00:00
Alan Cruickshank
961e3c77a3 MyPy on errors, helpers, markers & context + remove ParseContext.denylist (#5030) 2023-08-01 15:56:48 +00:00
Alan Cruickshank
8b7061f585 Warn on unused noqa directives (#5029) 2023-08-01 10:32:23 +00:00
Danny Jones
f9a4352356 Even more mypy strict (#5023)
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-07-31 21:47:43 +00:00
Alan Cruickshank
a4563fa30b Handle windows paths better in config files. (#5022)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-07-31 14:39:31 +00:00
João Filipe Cavichiolo Storrer
bd336c1269 Fix for parsing of Oracle functions with named arguments (#5027) 2023-07-31 14:39:18 +00:00
Artem Glebov
1925c59a86 DOC: Fix .sqlfluff example in Getting Started (#5026) 2023-07-31 13:34:35 +00:00
Alan Cruickshank
fc535b19e2 Fix: Add exception to the warning & config for the BaseRule. (#5025) 2023-07-31 10:02:49 +00:00
Alan Cruickshank
dcbff69333 Move from make_template to render_func in jinja and dbt (#4942) 2023-07-31 08:29:00 +00:00
Alan Cruickshank
2166221a0f Streamline imports to reduce initial load times #4917 (#5020) 2023-07-30 21:09:16 +00:00
Danny Jones
fff3e1ab20 More mypy strict (#5019)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-07-30 14:46:22 +00:00
Alan Cruickshank
223f22405e Simple API config and examples (#5018) 2023-07-30 14:45:04 +00:00
Alan Cruickshank
99d044aa9f Fix some new linting issues (#5021) 2023-07-30 11:08:56 +01:00
Danny Jones
771a3a6e1d A step towards mypy strict (#5014) 2023-07-28 17:34:52 +00:00
Bobby Iliev
aadffef368 Materialize: Make RETURNING a reserved keyword (#5017) 2023-07-28 16:48:26 +00:00
Alan Cruickshank
ae8571d68b Config from string and load default_config as resource (#5012) 2023-07-28 15:31:09 +00:00
Alan Cruickshank
7252cbf38a Documentation for the test suite (#2180) (#5011) 2023-07-27 18:23:45 +00:00
João Filipe Cavichiolo Storrer
e55d6178b6 Add support to oracle's listagg function (#4999) 2023-07-27 15:18:57 +00:00
Alan Cruickshank
ffa06550e4 Assorted typehints (#5013) 2023-07-27 14:40:49 +00:00
Alan Cruickshank
22c32e72f1 Refactor: Extract noqa methods and tests. (#5010) 2023-07-27 14:06:18 +00:00
Barry Pollard
7f1ac610f8 AM06 to ignore aggregate ORDER BY clauses (#5008) 2023-07-27 13:04:16 +00:00
Danny Jones
ee363704af Bugfix: Treat Function name properly in grants (#5006) 2023-07-26 18:25:44 +00:00
Danny Jones
05ff81c408 Redshift: Add Qualify Clause (#5002) 2023-07-26 18:25:10 +00:00
Kai-Yanna Meighu
d6e9e50da4 Clickhouse Dialect - Support Dollar Quoted Literals (#5003)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-07-26 08:40:28 +00:00
github-actions[bot]
3629c3e702 Prep version 2.1.4 (#5001)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-07-25 11:26:00 +01:00
Greg Finley
6fdaaed764 Databricks set time zone (#5000) 2023-07-25 08:36:03 +00:00
Alan Cruickshank
d8305b8d55 Terminator inheritance (#4981) 2023-07-25 08:35:30 +00:00
Alan Cruickshank
bcf29d539a Reduce copying in the parse phase (#4988) 2023-07-25 08:25:52 +00:00
Alan Cruickshank
c210834471 Validate layout configs #4578 (#4997)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-07-24 20:22:40 +00:00
Paul Anzel
50bbffd467 Fix handling of keywords for roles in ALTER ROLE statement (#4994) 2023-07-24 16:47:48 +00:00
Yoichi NAKAYAMA
b90620caeb BigQuery: fixes parse error on some literals with data type and quoted (#4992) 2023-07-24 09:58:21 +00:00
Barry Pollard
9d18a256ce Correct Snowflake CROSS JOIN syntax (#4996) 2023-07-24 09:57:08 +00:00
Greg Finley
8294440e0a Remove broken 'fork me' banner from docs (#4989) 2023-07-23 21:07:41 +00:00
reata
20f317eb5b feat: support athena optional WITH ORDINALITY post UNNEST function (#4991) 2023-07-23 05:49:52 +00:00
github-actions[bot]
0730cd1e88 Prep version 2.1.3 (#4979)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-07-19 23:39:42 +01:00
pppp56
e7bee3f9c3 Add the which dbt flag to DbtConfigArgs with default as "compile" (#4982)
Co-authored-by: pascal.moreau <pascal.moreau@yousign.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-07-19 18:39:54 +00:00
reata
c319473f7c feat: support tsql COPY INTO (#4985) 2023-07-19 17:50:33 +00:00
reata
eacd20ac14 fix: sparksql lateral view parse tree for multiple column alias (#4980) 2023-07-18 22:20:07 +00:00
Greg Finley
369e7f2d21 Revert "Ignore click mypy issues" (#4967)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-07-18 23:19:58 +01:00
Greg Finley
1a97a6086c Snowflake: Parse column named cross (#4975)
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-07-18 14:23:52 +00:00
Greg Finley
a20005a664 Snowflake: Group by all (#4976) 2023-07-17 16:27:19 +00:00
Alan Cruickshank
9793de59d5 Update funding yaml to use github sponsors (#4973) 2023-07-16 09:59:28 +01:00
Duncan Fleming
f16bd6c934 Added DEL keyword (#4962)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-07-15 14:51:23 +00:00
Greg Finley
d8943f041d Remove mypy ignores (#4972) 2023-07-15 10:56:24 +00:00
Greg Finley
5aa979e26d Allow running one rule test locally (#4963) 2023-07-11 14:10:15 +00:00
Greg Finley
ba1e6c9e76 Postgres support underscore array data type syntax (#4959) 2023-07-09 10:50:39 +00:00
Greg Finley
4f6dc83c25 Bump issue-labeler (#4958) 2023-07-08 18:05:40 +00:00
Greg Finley
156af06e64 Standardize test fixture names (#4955) 2023-07-08 14:54:06 +00:00
Keith Erskine
4a9152d3ac RF05 BigQuery empty identifier bug (#4953)
Co-authored-by: Keith Erskine <keith.erskine@zoro.com>
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-07-07 21:01:10 +00:00
Greg Finley
8e1ef769f5 New GitHub issue labeler library (#4952) 2023-07-07 20:40:15 +00:00
Greg Finley
fe0a5705b3 Ignore click mypy issues (#4954) 2023-07-07 20:39:59 +00:00
Greg Finley
66e88fe976 MySQL: Rename index (#4950) 2023-07-06 16:34:12 +00:00
Júlio Rangel Ballot
1c01a19fe7 Adding support to ALTER TABLE with RENAME COLUMN on MySQL dialect (#4948) 2023-07-06 16:15:41 +00:00
github-actions[bot]
653ee67d3e Prep version 2.1.2 (#4931)
Co-authored-by: greg-finley <greg-finley@users.noreply.github.com>
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-07-03 08:26:56 +00:00
Daniel Mohns
7d45be089e docs(templater): Add documentation for SQLFLUFF_JINJA_FILTERS (#4932)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-07-03 07:39:18 +00:00
Alan Cruickshank
59f80e35e3 Re-enable dbt 1.1 & 1.2 (#4944) 2023-07-02 21:30:53 +00:00
Alan Cruickshank
49808fb5f5 Re-enable dbt 1.4 & 1.3 (#4941) 2023-07-02 15:31:31 +00:00
Alan Cruickshank
e37ea9a03a Fix compatibility with dbt 1.5.2+ (#4939) 2023-07-01 09:48:07 +01:00
Alan Cruickshank
6cdc38d76b Security option for library path (#4925)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-06-22 12:00:41 +00:00
Barry Pollard
c6e805c4d8 Remove extra code escapes from release notes docs (#4921) 2023-06-15 01:35:05 +00:00
Greg Finley
fe0c58365b Postgres frame_clause quoted interval (#4915) 2023-06-12 16:47:07 +00:00
Greg Finley
376212655f Snowflake: CREATE TAG (#4914) 2023-06-12 16:42:38 +00:00
Martin
bfbd9e8b95 TSQL: support for DROP EXTERNAL TABLE (#4919) 2023-06-12 16:41:19 +00:00
Germain Lefebvre
09d8b697b4 fix(dialect-clickhouse): Support create database (#4620) 2023-06-11 21:32:46 +00:00
pppp56
6b89815819 Snowflake: Actualize the CreateProcedureStatementSegment and CreateFunctionStatementSegment (#4908)
Co-authored-by: pascal.moreau <pascal.moreau@yousign.com>
2023-06-08 21:03:18 +00:00
Mayur Singal
1df5bfc341 Oracle: Add support for $ and # in identifier (#4903) 2023-06-08 09:29:00 +00:00
Daniel Mohns
2156c33634 docs(templater): Refactor templater configuration docs (#4835) 2023-06-08 09:25:09 +00:00
Mayur Singal
3df79fe5a9 Handle brackets in from clause with joins (#4890) 2023-06-08 09:22:19 +00:00
Mayur Singal
dbc6b9bf56 Postgres: Add support for dollar literal & mark collation as non-reserved (#4883) 2023-06-03 12:31:28 +00:00
Greg Finley
c0d5414f61 MySQL: ON UPDATE NOW (#4898) 2023-06-03 12:28:53 +00:00
Barry Pollard
d933389156 Support ROLLUP/CUBE in AM06 (#4892) 2023-05-30 15:40:08 +00:00
github-actions[bot]
7e4843427b Prep version 2.1.1 (#4888)
Co-authored-by: greg-finley <greg-finley@users.noreply.github.com>
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-05-25 16:10:58 +00:00
Jason Gluck
b38ced23b0 profiels dir env var or default (#4886) 2023-05-25 15:45:36 +00:00
Dimitris Saltaferis
7bb8ea705f Bigquery: Allow empty struct in TO_JSON (#4879)
Co-authored-by: Barry Pollard <barrypollard@google.com>
2023-05-24 15:38:39 +00:00
Barry Pollard
12fdb9b19e Set type of ARRAY function for BigQuery (#4880) 2023-05-23 19:19:45 +00:00
matt garber
b0ee8b664d Full athena SHOW coverage (#4876) 2023-05-20 23:58:23 +00:00
Peter Arwanitis
2c3a4dcf03 Sparksql add star support in multiparameter functions (#4874)
Co-authored-by: Barry Pollard <barrypollard@google.com>
2023-05-18 08:44:26 +00:00
Mayur Singal
12a07070fa Oracle create view with EDITIONING & FORCE (#4872) 2023-05-17 16:24:18 +00:00
Seth
57908b97a8 Fixes pip installation link on Getting Started (#4867) 2023-05-16 23:55:52 +00:00
Dmytro Kulyk
133510d492 Athena: add "weird" test cases for group by (#4869) 2023-05-16 23:55:07 +00:00
Dmytro Kulyk
335fd1b794 Athena: add support for CUBE ROLLUP GROUPING SETS (#4862) 2023-05-15 09:59:25 +00:00
matt garber
45421b803f Add show tables/views to athena (#4854) 2023-05-12 14:18:00 +00:00
William Felipe Welter
2cf367728a Adding support for NOCOPY and INSTANT algorithm on CREATE INDEX on MySQL dialect (#4865) 2023-05-12 14:14:51 +00:00
Dmytro Kulyk
78422a739a Add link to Trino keywords (Athena v3) (#4858) 2023-05-11 19:26:15 +00:00
Greg Finley
ee0f0e828c TSQL: Create Role Authorization (#4852) 2023-05-09 21:32:57 +00:00
Greg Finley
19206be117 TSQL: DEADLOCK_PRIORITY (#4853) 2023-05-09 21:32:08 +00:00
Germain Lefebvre
0c63cd0c3d fix(dialect-clickhouse): Support SYSTEM queries (#4625)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-05-06 12:24:36 +00:00
Alan Cruickshank
e9218e4de5 Fix #4807: LT02 & LT12 issues with empty files. (#4834) 2023-05-06 12:06:41 +00:00
Greg Finley
1777a6bfc8 Sqlite: COLLATE column constraint (#4845) 2023-05-06 12:01:53 +00:00
Greg Finley
042f8d0953 Hive: Support REGEXP and IREGEXP (#4846) 2023-05-06 12:00:04 +00:00
github-actions[bot]
e884df2d00 Prep version 2.1.0 (#4838)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-05-04 00:17:46 +01:00
Daniel Mohns
3c13975de0 Add support for Jinja filters (#4810)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-05-02 07:14:50 +00:00
Danny Jones
48e064c21a Postgres: Allow INSERT RETURNING (#4820) 2023-05-02 07:02:18 +00:00
Danny Jones
a334458f03 SQLite: Support partial index (#4833) 2023-05-02 07:02:06 +00:00
Danny Jones
3c5547915b Make SQLFluff compatible with DBT 1.5 (#4828)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2023-05-01 21:32:31 +00:00
pppp56
48d33fd9dc Snowflake dialect: Add support for comment clause in the create warehouse statement (#4823)
Co-authored-by: pascal.moreau <pascal.moreau@yousign.com>
2023-04-27 09:30:48 +00:00
Germain Lefebvre
720ab7f7f1 fix(dialect-clickhouse): Support DROP statements (#4821) 2023-04-27 07:39:02 +00:00
Greg Finley
5689ead07b Hive: INSERT INTO without TABLE keyword (#4819) 2023-04-26 20:20:25 +00:00
Javier Montón
29601b3ec2 Fix: Small typo in error message (#4814) 2023-04-26 18:17:55 +00:00
Danny Jones
fc5ddba665 Redshift: Support with no schema binding (#4813) 2023-04-26 04:17:32 +00:00
David Wales
00078cf783 Detect tsql square bracket quotes for RF06 #4724 (#4781) 2023-04-25 19:42:58 +00:00
Oliver Borchert
dd2cec7183 Apply implicit indents to WHEN blocks and introduce indented_then_contents (#4755) 2023-04-25 19:40:14 +00:00
Danny Jones
cbf06f9349 Oracle: Update Drop Behaviour (#4803) 2023-04-25 17:48:54 +00:00
Danny Jones
b884c2e66b Oracle: Update bare functions (#4804) 2023-04-25 17:48:25 +00:00
Alan Cruickshank
d19de0ecd1 Bump to version 2.0.7 (#4799)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
2023-04-20 22:04:16 +01:00
Alan Cruickshank
0a664387f6 Fix regression in implicit indents (#4798) 2023-04-20 19:31:00 +00:00
Alan Cruickshank
d2301023c2 Fix bug with brackets and implicit indents (#4797) 2023-04-20 18:29:53 +00:00
Janis Puris
37eed95517 fix: correct macos/osx config file location (#4795) 2023-04-20 18:25:56 +00:00
github-actions[bot]
23198ff9f2 Prep version 2.0.6 (#4784)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-04-20 10:26:50 +01:00
Danny Jones
a73be312e6 Snowflake: Support Temporary View (#4789) 2023-04-19 16:41:31 +00:00
Daniel Mohns
4e15ef474c Inroduce SAFE prefix segment (#4773) 2023-04-19 16:41:28 +00:00
Alan Cruickshank
7aed68a5a8 Fix #4660: Better handling of empty files. (#4780) 2023-04-19 16:29:07 +00:00
Alan Cruickshank
d125f579fb Fix #3538: (Fix files as we go) (#4777) 2023-04-19 16:00:08 +00:00
Alan Cruickshank
0243d4a1ba Fix #2855: (Tech debt: check consistency in TemplatedFile init) (#4776) 2023-04-19 14:25:15 +00:00
Alan Cruickshank
93c2f79356 Add a --quiet option for fix (#4764) 2023-04-19 08:29:29 +00:00
Fredrik Vraalsen
f60e2fc3fd Fix #4603 indent after Jinja 'do' directive (#4778)
Co-authored-by: Fredrik Vraalsen <22197+fredriv@users.noreply.github.com>
2023-04-18 20:25:34 +00:00
Thashin
73c4674f4b Snowflake Execute Task with Schema (#4771) 2023-04-18 19:31:34 +00:00
Danny Jones
e70ee8df49 SQLite: Support CreateTrigger (#4767) 2023-04-18 15:20:24 +00:00
Alan Cruickshank
e3f77d58f5 Fix #2865 (AL05 exception for Redshift Semi-structured) (#4775) 2023-04-17 17:13:10 +00:00
Alan Cruickshank
affce6d2fc Fix #4540: Untaken indents evaluation order. (#4768) 2023-04-17 16:32:28 +00:00
James Johnston
a820c139cc Use the new CollationReferenceSegment everywhere (#4770) 2023-04-17 09:14:51 +00:00
James Johnston
84735e9705 SQLite: Fix multiple parse issues in Expression_A_Grammar (#4769) 2023-04-16 21:48:24 +00:00
Danny Jones
86e571f2af SQLite: Remove refs to RESPECT and QUALIFY (#4765) 2023-04-16 19:57:39 +00:00
Danny Jones
86d5ba9ffb SQLite: Support STRICT (#4766) 2023-04-16 19:55:51 +00:00
Alan Cruickshank
c8751f5cb3 Support hive set syntax (#4763) 2023-04-16 14:35:57 +00:00
Alan Cruickshank
3b68bd0aba Fix #4582: Comments after end of line (#4760) 2023-04-16 14:26:09 +00:00
Alan Cruickshank
5c9a08daf5 Allow comment match with preceding line (#4758) 2023-04-16 11:21:56 +00:00
Danny Jones
3cdb0e8620 Remove the majority of greedy matchers (#4761) 2023-04-16 11:15:33 +00:00
Alan Cruickshank
7ec6794147 Fix #4745: (max() error in reindent) (#4752) 2023-04-15 11:39:31 +00:00
Alan Cruickshank
8ce7104a41 Fix issue with macros triggering LT01 (#4757) 2023-04-15 11:34:30 +00:00
Alan Cruickshank
ebdae040f1 end-of-file > end_of_file (#4753) 2023-04-15 11:30:34 +00:00
github-actions[bot]
24178a589c Prep version 2.0.5 (#4756)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-04-14 22:21:42 +01:00
James Johnston
34279b709d Refactor PG segments to reuse new common segments (#4726) 2023-04-14 20:44:58 +00:00
Alan Cruickshank
a905aedbf4 Don't be too eager on window functions 2023-04-14 21:35:12 +01:00
James Johnston
5053ee0278 Recognize quoted data types (#4747) 2023-04-14 19:00:01 +00:00
github-actions[bot]
322a944fc9 Prep version 2.0.4 (#4730)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-04-14 10:54:05 +01:00
Bobby Morck
abd7a85c98 SparkSQL: Improvements to lateral view, hints, sort by (#4731)
Co-authored-by: Bobby Morck <bmorck@netflix.com>
2023-04-14 08:25:41 +00:00
James Johnston
2cea9397b2 Add ExpressionSegment to CREATE TABLE ... DEFAULT / Fix multiple parse issues in Expression_A_Grammar (#4717) 2023-04-14 08:24:11 +00:00
James Johnston
a149a04cf9 Add support for the PG VACUUM statement (#4742)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-04-14 08:22:45 +00:00
James Johnston
d96d61bb36 Simplify and fix PG array accessor segment & support expressions (#4748) 2023-04-14 08:22:34 +00:00
Bobby Morck
5474a76a98 SparkSQL: Allow for any ordering of create table clauses (#4721)
Co-authored-by: Bobby Morck <bmorck@netflix.com>
2023-04-14 08:13:01 +00:00
Alan Cruickshank
a4f38de261 Suggested started config file (#4702) 2023-04-13 16:32:31 +00:00
Alan Cruickshank
ffa903b989 Indents on window functions (#4560) 2023-04-13 16:32:28 +00:00
Bobby Morck
2098eb7a79 SparkSQL: Fix Group By Clause (#4732)
Co-authored-by: Bobby Morck <bmorck@netflix.com>
2023-04-13 16:01:40 +00:00
James Johnston
f229bf34b6 Improve support for EXCLUDE table constraints in PG (#4725) 2023-04-13 13:20:43 +00:00
James Johnston
59df9a5cd6 Add support for dropping multiple indexes in PG (#4737) 2023-04-13 13:20:26 +00:00
James Johnston
d51bb6be23 Recognize "on" value and integers for PG SET statement (#4740) 2023-04-13 13:19:50 +00:00
James Johnston
f0e6f9cfa2 Improve interval expressions on MySQL (#4746) 2023-04-13 09:52:27 +00:00
James Johnston
ba283d7fac Keep out zero length keywords (#4723) 2023-04-13 09:23:52 +00:00
James Johnston
a12fe68058 Add PG support for CREATE SCHEMA AUTHORIZATION (#4735) 2023-04-13 09:16:27 +00:00
James Johnston
1d1fd6a037 Add support for dropping multiple views with PostgreSQL (#4736) 2023-04-13 09:13:59 +00:00
James Johnston
f9395654b7 Add CHAR VARYING data type for PG (#4738) 2023-04-13 09:12:11 +00:00
Tim Costa
0d131e469e fix(athena): map type matching failed, array type only contains a datatype (#4739)
Co-authored-by: Tim Costa <timcosta@amazon.com>
2023-04-13 09:11:02 +00:00
James Johnston
a18af6da1e Allow DML queries to be selectable in CTEs on PG (#4741) 2023-04-13 09:08:08 +00:00
James Johnston
7b3a25f9e7 Add the CREATE/DROP CAST statements to ANSI and PG (#4744) 2023-04-13 09:03:17 +00:00
James Johnston
02ca9a1479 Add support for PG SET ROLE / RESET ROLE (#4734) 2023-04-13 09:01:48 +00:00
Bobby Morck
792ee30e9b Support Spark Iceberg DDL (#4690)
Co-authored-by: Bobby Morck <bmorck@netflix.com>
2023-04-12 19:52:07 +00:00
Alan Cruickshank
4540d4b311 Fix #4680 (#4707) 2023-04-12 12:08:27 +00:00
Alan Cruickshank
463174d8ec Indent Aliases (#4706) 2023-04-12 08:43:02 +00:00
Bobby Morck
97d732cbd4 SparkSQL: Improve window frame bounds (#4722)
Co-authored-by: Bobby Morck <bmorck@netflix.com>
2023-04-12 08:15:20 +00:00
James Johnston
f4938ed5a8 Add support for PG CREATE/ALTER/DROP PUBLICATION stmts (#4716) 2023-04-11 20:51:32 +00:00
Bobby Morck
1595af39f7 SparkSQL: Create external table support (#4692)
Co-authored-by: Bobby Morck <bmorck@netflix.com>
2023-04-11 20:43:24 +00:00
Bobby Morck
080db82c77 SparkSQL: Fix file literal lexing (#4718)
Co-authored-by: Bobby Morck <bmorck@netflix.com>
2023-04-11 20:42:31 +00:00
James Johnston
9f432e5e6d Add PG DROP/REASSIGN OWNED statements (#4720) 2023-04-11 20:37:13 +00:00
Bobby Morck
f4bf69e20b SparkSQL: Add distinct to comparison operator (#4719)
Co-authored-by: Bobby Morck <bmorck@netflix.com>
2023-04-11 20:35:52 +00:00
Alan Cruickshank
b176e1357b Rethink Rule Docs (#4695) 2023-04-11 17:26:20 +00:00
Alan Cruickshank
700d5fcb7a Performance: Reduce calls to _prune_options (#4705) 2023-04-11 14:14:12 +00:00
Danny Jones
6f2dac697f Snowflake: Add ReferencedVariableNameSegment to sample function (#4712) 2023-04-11 09:57:07 +00:00
Yoichi NAKAYAMA
8476df315e Mark AM02 as fix compatible (#4714) 2023-04-11 09:55:51 +00:00
James Johnston
1076d2ff07 Fix LT01 spacing check in templated areas (#4698) 2023-04-10 18:40:29 +00:00
Alan Cruickshank
bc914f6052 Don't do newline conversion on write (#4703) 2023-04-10 18:39:48 +00:00
Yoichi NAKAYAMA
7af2415da6 MySQL: CREATE/ALTER VIEW may take UNION (#4713) 2023-04-10 14:38:36 +00:00
James Johnston
2460e2a6e4 Preserve zero-length template segments (#4708) 2023-04-10 09:58:53 +00:00
James Johnston
5507d0f59c CV06: don't flag files that don't have code (#4709) 2023-04-10 09:53:17 +00:00
Alan Cruickshank
bbf306162f Add a no-output option (#4704) 2023-04-09 18:37:41 +00:00
James Johnston
8dda89b7bd Jinja templater: treat "import" and "from" as templated (#4696)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-04-09 16:09:33 +00:00
James Johnston
247c0f7d39 Capitalization rules ignore templated code only if configured to (#4697) 2023-04-09 15:58:04 +00:00
Alan Cruickshank
3580214fd4 Update getting started docs (#4700) 2023-04-09 15:05:06 +00:00
Alan Cruickshank
1cf43b1ddc Add a default for config_keywords and remove noisy error. (#4701) 2023-04-09 15:05:00 +00:00
Thashin
7f53c8b8eb Snowflake Select System Functions (#4687) 2023-04-08 14:11:31 +00:00
Bobby Morck
a261f23c14 SparkSQL: Add using and options clause to create view statement (#4691)
Co-authored-by: Bobby Morck <bmorck@netflix.com>
2023-04-08 14:10:20 +00:00
Yoichi NAKAYAMA
7fb9dd076c MySQL: Add RETURN Statement (#4693) 2023-04-08 14:06:11 +00:00
Alan Cruickshank
1e08c785de Safety valve for fixes in CV03 (#4685) 2023-04-07 12:53:57 +00:00
Alan Cruickshank
8b1ab66944 Allow persist timing on fix too. (#4679) 2023-04-07 09:13:41 +00:00
Thashin
0826b41d77 fix{dialect-snowflake}:Alter Table Column Set/Unset Tag (#4682) 2023-04-06 09:31:03 +00:00
Thashin
a205c9176f fix{dialect-snowflake}:Execute Task (#4683) 2023-04-06 09:28:21 +00:00
Alan Cruickshank
402a47c4cb Make version number an argument not an option in release script. (#4677) 2023-04-05 17:56:00 +00:00
github-actions[bot]
ad5561769d Prep version 2.0.3 (#4663)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-04-05 18:23:31 +01:00
Barry Pollard
735a463c6e Better error message for missing keywords (#4676) 2023-04-05 16:52:57 +00:00
Alan Cruickshank
9770e1418f Add performance shortcuts to LT03 & LT04 (#4672) 2023-04-05 16:49:51 +00:00
Konstantin Ilchenko
6c1b18b64b Clickhouse: Add support for [LEFT] ARRAY JOIN (#4618) 2023-04-05 15:30:28 +00:00
Barry Pollard
b9204b0c5d Postgres - allow untyped OVERLAPS clauses (#4674) 2023-04-05 13:44:40 +00:00
Barry Pollard
f75229fb64 Mark is_alias_required as a private class so it doesn't appear in docs (#4673) 2023-04-05 13:06:22 +00:00
Alan Cruickshank
729efc31b3 Fix bug in templated with clauses LT07 (#4671) 2023-04-05 12:45:16 +00:00
Martin
cc6c303dd3 TSQL: OPENJSON() (#4652)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-04-05 09:55:48 +00:00
Tim Costa
aab63d5c0b fix(RF06/L059): allows configuring prefer_quoted_keywords to deconflict with L029 (#4396)
Co-authored-by: Tim Costa <timcosta@amazon.com>
2023-04-05 09:32:40 +00:00
Alan Ly
1b8ba7f578 TSQL: Create External Table (#4642)
Co-authored-by: Alan Ly <Alan.Ly@alintaenergy.com.au>
2023-04-05 09:24:12 +00:00
Daniel Mohns
ff868aa5d5 Consistent indentation in MERGE INSERT clause (#4666) 2023-04-05 09:10:59 +00:00
Greg Finley
15f1d97df6 BigQuery: Fix null assignment in options segment (#4669) 2023-04-05 09:07:43 +00:00
Greg Finley
aec9156334 BigQuery: Delete table reference (#4668) 2023-04-05 09:06:41 +00:00
Martin
a836a89c36 TSQL: CREATE EXTERNAL FILE FORMAT (#4647) 2023-04-04 10:41:31 +00:00
Bobby Morck
7ac4064962 Remove TIME as reserved keyword in SparkSQL (#4662)
Co-authored-by: Bobby Morck <bmorck@netflix.com>
2023-04-04 08:57:53 +00:00
Jack Wolverson
32095f823e Start of the Greenplum dialect implementation (#4661)
Co-authored-by: JWolverson <jwolverson@sidetarde.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2023-04-03 17:40:31 +00:00
Fredrik Vraalsen
11c2a995d4 Enable configuring whether to require indent before THEN (#4598)
Co-authored-by: Fredrik Vraalsen <22197+fredriv@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-04-03 17:06:10 +00:00
Alan Cruickshank
2be88d7563 Sequence Meta Handling (#4622) 2023-04-03 16:35:46 +00:00
Bobby Morck
327583bfe6 Add support for non-quoted file paths in SparkSQL (#4650)
Co-authored-by: Bobby Morck <bmorck@netflix.com>
2023-04-03 15:05:09 +00:00
Alan Cruickshank
1495aeeb5b Remove three RegexParsers (#4658) 2023-04-03 12:34:32 +00:00
Alan Cruickshank
e089229be3 Make parse test readout more helpful (#4657) 2023-04-03 12:32:03 +00:00
Martin
964dcd18d1 TSQL: support for sqlcmd commands :r and :setvar (#4653) 2023-04-03 10:57:39 +00:00
Liam Perritt
1b6caaeaf2 Update README with Databricks note (#4632) 2023-04-01 20:04:03 +00:00
Maiara Reinaldo
2469d678a7 Athena: Fix parsing error with aliases starting with underscore (#4636) 2023-04-01 20:03:26 +00:00
roman-ef
73414c3970 Snowflake: Stop ever-increasing indent in CREATE USER (#4638) 2023-04-01 20:01:59 +00:00
Martin
68aa104eda TSQL: PERIOD FOR SYSTEM_TIME (temporal tables) (#4654) 2023-04-01 19:42:57 +00:00
Yoichi NAKAYAMA
a44bea7ae9 MySQL: SelectStatementSegment in CREATE/ALTER VIEW may be bracketed (#4655) 2023-04-01 19:41:48 +00:00
Martin
2206a30802 TSQL: CREATE EXTERNAL DATA SOURCE (#4634) 2023-03-30 20:58:58 +00:00
Alan Cruickshank
fb841e91c0 Safety valve on source fixes (#4640) 2023-03-30 18:24:02 +00:00
Bobby Morck
39f84450e8 Add SparkSQL support for LONG primitive type (#4639)
Co-authored-by: Bobby Morck <bmorck@netflix.com>
2023-03-30 17:07:15 +00:00
Barry Pollard
8eb303cf0e Fix PIVOT clauses for BigQuery and SparkSQL (#4630) 2023-03-28 11:22:02 +00:00
Barry Pollard
35335e885b Correct BigQuery WINDOW parsing (#4629) 2023-03-28 09:35:42 +00:00
Liam Perritt
5c988d5e18 Add Databricks dialect support for Unity Catalog (#4568) 2023-03-28 08:33:32 +00:00
Alan Cruickshank
532a2347fd .simple() matching for TypedMatcher (#4612) 2023-03-27 14:00:35 +00:00
Alan Cruickshank
0c7cd6ffce --bench output with rule timings (#4601) 2023-03-27 14:00:20 +00:00
Greg Finley
1b30ffb5f2 MySQL: Unnamed constraints (#4616) 2023-03-26 21:52:15 +00:00
Greg Finley
2f495a2894 TSQL: Create database scoped credential (#4615) 2023-03-26 14:37:52 +00:00
Germain Lefebvre
56973a6727 fix(dialect-clickhouse): Add materialized view statement (#4605) 2023-03-24 19:21:12 +00:00
Alan Cruickshank
c09304a836 Nicer formatted dbt errors (#4606) 2023-03-24 17:01:28 +00:00
Konstantin Smirnov
5b8d4bc75d add parse lambda function Clickhouse (#4611) 2023-03-24 16:57:48 +00:00
Barry Pollard
442495d719 Support WITH ORDINALITY clauses in Postgres (#4599) 2023-03-23 18:02:50 +00:00
github-actions[bot]
e0251db13d Prep version 2.0.2 (#4597)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2023-03-23 16:41:34 +00:00
Alan Cruickshank
cd5d50bcbb Parse Caching (#4576) 2023-03-23 10:53:55 +00:00
Alan Cruickshank
74539b2647 Data type spacing (#4592) 2023-03-22 22:25:55 +00:00
Yoichi NAKAYAMA
76f208bece MySQL: allow quoted literal in alias name (#4591) 2023-03-22 16:10:44 +00:00
Alan Cruickshank
795e3b3555 Make implicit indents visible in the parse tree (#4584) 2023-03-21 22:41:09 +00:00
Alan Cruickshank
d9665ec285 Fix #4559: TSQL implicit indents on WHERE (#4583) 2023-03-21 22:40:58 +00:00
Rasmus Nyberg
d1e7662a96 Added keywords to DB2 dialect from IBM docs (#4575) 2023-03-21 16:13:24 +00:00
Alan Cruickshank
601155bc25 Remove matches_target_tuples (#3873) (#4561)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2023-03-21 14:02:43 +00:00
Alan Cruickshank
9e8caba8d0 Use terminators in BaseExpression (#4577) 2023-03-21 12:56:13 +00:00
Alan Cruickshank
c69ff2bb2e Address #1630: Optionally move comments after long line (#4558) 2023-03-21 12:55:48 +00:00
Jack Wolverson
7a4d6baf68 added schema to set statement (#4580)
Co-authored-by: JWolverson <jwolverson@sidetarde.com>
2023-03-21 12:55:26 +00:00
Alan Cruickshank
e645712d39 Refactor lint_line_length and fix comma bug (#4564) 2023-03-21 08:03:51 +00:00
Alan Cruickshank
9d6172c7fe Fix untaken indent bug (#4562) 2023-03-20 23:05:39 +00:00
Greg Finley
18e1578090 SQLite: Fix SELECT LIMIT (#4566) 2023-03-20 15:50:13 +00:00
Alan Cruickshank
bbfb4b0ce8 Fix #4453: Snowflake semi-stuctured casts in CV11 (#4571) 2023-03-20 15:40:43 +00:00
Alan Cruickshank
c41ba81ce8 name of LT07 (#4557) 2023-03-20 08:11:07 +00:00
mikaeltw
f13a81f4b0 Patch fetch and over (#4555) 2023-03-18 15:07:23 +00:00
github-actions[bot]
1d7d57a617 Prep version 2.0.1 (#4550)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-03-18 09:15:06 +00:00
Alan Cruickshank
504c224e3c Repair Coveralls (#4553) 2023-03-17 17:09:06 +00:00
AidanHarveyNelson
4e8defb93e Add support for arrays in TOML configuration (#4387)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-03-17 13:48:28 +00:00
Alan Cruickshank
d104d44e87 Rethink test segregation in CI (#4547) 2023-03-17 13:19:24 +00:00
Alan Cruickshank
ae3e30fdf5 Fix #4515 and add more test cases (#4525) 2023-03-17 12:51:38 +00:00
Oliver Borchert
2981fb6dd4 Add additional flags to sqlfluff invocations in pre-commit hooks (#4546) 2023-03-16 22:29:20 +00:00
Alan Cruickshank
92f1ee6080 Resolve #4484 (issues with indented_joins indents) (#4544) 2023-03-16 21:06:00 +00:00
Laura Richter
982494fe8f Per file dialect selection fix (#4518)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-03-16 18:01:20 +00:00
Yoichi NAKAYAMA
56d3027743 MySQL: Add CREATE INDEX (#4538) 2023-03-16 16:30:36 +00:00
Alan Cruickshank
27003671d1 Resolve implicit indent issues when catching negative indents (#4543) 2023-03-16 15:58:22 +00:00
Alan Cruickshank
9d80142f44 Github Action Deprecations (#4545) 2023-03-16 15:57:26 +00:00
Alan Cruickshank
65153db224 LT09 and multiline select targets (#4529) 2023-03-16 15:56:58 +00:00
Alan Cruickshank
114f5a8bd8 Remove Codecov from CI (#4535) 2023-03-15 23:43:03 +00:00
Alan Cruickshank
f936b35851 Bigquery hyphentated identifiers (#4530) 2023-03-15 23:35:31 +00:00
Alan Cruickshank
20942ec96a Attempt in-house coverage (#4532) 2023-03-15 23:05:33 +00:00
Alan Cruickshank
97fa4dd5b0 Postgres datatype spacing issues (#4528) 2023-03-15 18:46:44 +00:00
Alan Cruickshank
3fcd0c00f9 Support new rules config in toml files. (#4526) 2023-03-15 16:10:26 +00:00
Alan Cruickshank
989a770213 Resolve #1146 (log propagation) (#4513) 2023-03-15 10:03:57 +00:00
Javier Montón
2478692eda Snowflake: Optional quotes for create user statement (#4514) 2023-03-14 18:10:41 +00:00
github-actions[bot]
7d9e5c2a1a Prep version 2.0.0 (#4507)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-03-14 09:22:29 +00:00
Alan Cruickshank
5323039254 Revise templating and lexing of calls. (#4506) 2023-03-14 00:23:03 +00:00
Alan Cruickshank
3e30a206bd Struct Access Spacing (#4512) 2023-03-13 23:55:08 +00:00
Alan Cruickshank
936aabb9e2 Array and Struct Spacing (#4511)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2023-03-13 22:53:39 +00:00
Alan Cruickshank
95e6c47032 Add a deprecation warning for removed config option. (#4509) 2023-03-13 21:02:57 +00:00
Alan Cruickshank
d429b1d6ad Bigquery spacing (#4508) 2023-03-13 19:14:22 +00:00
Alan Cruickshank
e5745ab999 Fix #4433 (more untaken positive indents) (#4499) 2023-03-13 13:51:33 +00:00
Yoichi NAKAYAMA
e47c310515 Fix parse error on double parentheses (#4504) 2023-03-13 13:08:05 +00:00
Alan Cruickshank
4ba9f6a81b 2.0.0 Migration Guide (#4498) 2023-03-13 12:45:02 +00:00
Alan Cruickshank
62b3edb9ac Handle missing aliases and align constraints better (#4493) 2023-03-13 12:28:47 +00:00
AidanHarveyNelson
c101fcf4ed TSQL: Add support For Clause (#4501) 2023-03-13 12:24:14 +00:00
Alan Cruickshank
83aee18412 Allow Jinja rule to loop safely (#4495) 2023-03-13 12:23:59 +00:00
Alan Cruickshank
1bf1a16cf2 Trigger CI tests for merge groups (#4503) 2023-03-13 12:22:45 +00:00
Alan Cruickshank
032814847c Update Readme and Contributing (#4502) 2023-03-13 12:07:08 +00:00
Alan Cruickshank
0b9ffbeda8 Update layout docs (#4500) 2023-03-13 10:59:50 +00:00
Alan Cruickshank
d4c10c6e7e Bug in operator precedence (#4497) 2023-03-12 16:08:52 +00:00
Gergely Imreh
757069821c BigQuery: correct query syntax for single column UNPIVOT clauses (#4494) 2023-03-12 05:35:37 +00:00
Alan Cruickshank
58990f384c Fix #4485 (#4491) 2023-03-11 13:50:03 +00:00
ValentinCrr
b48a6d8bce Update reserved keywords in Athena language (#4490) 2023-03-10 18:53:12 +00:00
konnectr
39d86f5942 Clickhouse support all join types (#4488)
Co-authored-by: Barry Pollard <barrypollard@google.com>
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-03-10 09:02:24 +00:00
Alan Cruickshank
34c682db2f Snowflake semi-structured spacing (#4487) 2023-03-09 16:35:58 +00:00
github-actions[bot]
33e4b121ef Prep version 2.0.0a6 (#4476)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-03-07 23:29:37 +00:00
Alan Cruickshank
47db1a62b8 Fix #4367 (#4479) 2023-03-07 23:27:02 +00:00
Duncan Fleming
91b631c46f Teradata: Improve COLLECT STATS parsing (#4478) 2023-03-07 15:44:15 +00:00
Alan Cruickshank
70e2d4569a Add a sqlfluff format CLI command (#4473) 2023-03-07 14:29:15 +00:00
Alan Cruickshank
9c2ce9e935 Recode and disable L031 -> AL07 (#4471)
Co-authored-by: Paul Wildenhain <35195136+pwildenhain@users.noreply.github.com>
2023-03-06 20:49:31 +00:00
Alan Cruickshank
5bb3fc1c34 Named Config (part 2) (#4470) 2023-03-06 17:07:58 +00:00
Alan Cruickshank
a954adb42a Rule config lookup improvements & config warnings (#4465) 2023-03-06 16:25:18 +00:00
Alan Cruickshank
0eded766b0 Recode L050 (#4468) 2023-03-06 15:21:26 +00:00
Alan Cruickshank
4881669416 Implicit indent fixes #4467 (#4469) 2023-03-06 14:31:06 +00:00
Danny Jones
7d32651baf ANSI: Add IfExistsGrammar to DropTrigger (#4466) 2023-03-05 23:30:28 +00:00
Alan Cruickshank
eea8e46111 Rules Reorg Mopup (#4462) 2023-03-05 22:28:10 +00:00
Alan Cruickshank
ce57b75111 Layout Rules Recode (part 2) (#4456) 2023-03-05 16:37:19 +00:00
Tim Costa
befc52d367 fix(athena): resolve errors parsing around maps, structs, and arrays (#4391)
Co-authored-by: Tim Costa <timcosta@amazon.com>
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-03-04 15:26:33 +00:00
Alan Cruickshank
4b644e030c Layout Rules Recode (part 1) (#4432) 2023-03-04 13:34:14 +00:00
jpers36
19e2682fc7 TSQL: EXEC string literal (#4458) 2023-03-04 05:18:35 +00:00
Duncan Fleming
a45f65d3f3 Teradata: Added SET QUERY_BAND statement (#4459) 2023-03-04 04:57:02 +00:00
Duncan Fleming
b669b14e88 Teradata: Added TOP select clause modifier (#4461) 2023-03-03 20:36:13 -08:00
Duncan Fleming
66f1cae98f Teradata: Addition of comparison operator extensions (#4451) 2023-03-03 17:35:25 +00:00
Jared Rimmer
a90c68350b Add extensions and plugin section to the README.md (#4454) 2023-03-02 11:56:51 +00:00
Alan Cruickshank
6a4d24c959 Convention rules bundle (#4448) 2023-03-01 23:19:47 +00:00
Alan Cruickshank
021e79035e References rule bundle (#4446) 2023-03-01 21:09:35 +00:00
Alan Cruickshank
8a82572a88 Structure and Ambiguous rule bundles (#4444) 2023-03-01 17:21:24 +00:00
jpers36
b6842247f9 TSQL: Bare functions (#4439)
Co-authored-by: Josh Persons <joshua.persons@quisitive.com>
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-02-28 17:24:59 +00:00
Danny Jones
6b4a0c81ff Pull dbt CI tests forward to 1.1 and 1.4 (#4442) 2023-02-28 17:00:00 +00:00
dflem97
9c9bb32a16 Teradata: Added "AND STATS" options when creating table (#4440) 2023-02-28 07:56:56 +00:00
Danny Jones
009725c1f3 Add Databricks as a distinct dialect (#4438)
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-02-27 21:42:48 +00:00
Alan Cruickshank
b600627e55 Remove importlib deprecated methods (#4437) 2023-02-27 18:14:18 +00:00
Danny Jones
fa498f2d02 SQLite: Support PRAGMA statements (#4431)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-02-26 20:55:52 +00:00
Alan Cruickshank
668bcde485 Proposed graceful handling of noqa by L016 (#4248) (#4424) 2023-02-26 18:59:05 +00:00
Danny Jones
0a6b1d3c1d DuckDb: Allow quoted literals as identifiers (#4410)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2023-02-26 14:31:36 +00:00
Danny Jones
8d00ba29f7 SQLite Refactor to reduce statement and keyword scope (#4409) 2023-02-26 14:13:01 +00:00
Alan Cruickshank
a33859bbc1 L046 and L056 recode (#4430) 2023-02-26 13:46:31 +00:00
Alan Cruickshank
c8f9894c85 Recode Aliasing Rules (#4427) 2023-02-26 13:12:53 +00:00
Fabian Scheidt
820093d228 MySQL: datetime columns (#4426) 2023-02-26 04:01:41 +00:00
Alan Cruickshank
7cf31cf978 Revert some changes to tox (#4428) 2023-02-25 23:46:41 +00:00
Alan Cruickshank
9a56265f94 Migrate capitalisation rules to plugin and recode (#4413) 2023-02-25 09:10:32 +00:00
github-actions[bot]
ab442305b3 Prep version 2.0.0a5 (#4419)
Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-02-25 08:47:44 +00:00
Alan Cruickshank
1192e55072 Handle long lines without trailing newlines gracefully (#4386) (#4423) 2023-02-24 08:45:07 +00:00
Alan Cruickshank
53cd2af77d Resolve #4184 (index error in L007) (#4422) 2023-02-24 00:01:56 +00:00
Alan Cruickshank
49541e3617 Handle untaken positive indents with taken negative pair. (#4420)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2023-02-23 23:39:33 +00:00
Hervé Saint-Amand
20fa4aeb53 Postgres: AS MATERIALIZED support (#4417)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-02-23 18:26:38 +00:00
briankravec
50fe9a522b Align warnings config with example shown (#4421)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-02-23 16:52:41 +00:00
Yoichi NAKAYAMA
b6e1e44df6 BigQuery: parse "AS description" part of assert expressions (#4418)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-02-23 16:21:21 +00:00
Alan Cruickshank
ff1dc10a4d Deprecate doc decorators (replace with metaclass) (#4415) 2023-02-21 16:53:17 +00:00
Alan Cruickshank
de0732234b Enable noqa using aliases and groups (#4414) 2023-02-21 07:58:04 +00:00
Alan Cruickshank
19305b78dd Add rule names to CLI outputs (#4400) 2023-02-20 10:26:03 +00:00
Danny Jones
cae95d8fa7 Postgres: Remove execution keyword inherited from ANSI (#4411)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-02-19 21:06:53 +00:00
Alan Cruickshank
531ebebb10 Rule names, aliases and more complicated selection. (#4399) 2023-02-19 20:12:28 +00:00
Danny Jones
a0849608f9 Postgres: Support Recursive View (#4412) 2023-02-19 19:16:28 +00:00
Oliver Borchert
fa9edd9f6e T-SQL: Implement BULK INSERT statement (#4381)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-02-19 16:25:26 +00:00
vesatoivonen
01ae8b6ad5 L062: Add match_source (#4172) (#4335)
Co-authored-by: Vesa Loimu <vesa.loimu@verkkokauppa.com>
2023-02-19 15:25:24 +00:00
Jared Rimmer
7556f269d0 TSQL: Add SET to ALTER TABLE (#4407) 2023-02-19 13:27:49 +00:00
Jared Rimmer
b0b87c0bc4 Snowflake: ALTER STORAGE INTEGRATION segment (#4406) 2023-02-19 13:01:01 +00:00
Peter Debelak
41e09a4abe Fix incorrect link to pre-commit docs (#4405) 2023-02-18 21:58:38 -08:00
Jared Rimmer
eb2e069fbf Snowflake: ALTER ROLE segment (#4403) 2023-02-18 05:08:41 +00:00
Dan Ilan
684a30e45f Postgres: Improve create index statement (#4356) 2023-02-11 22:44:12 +00:00
Alan Cruickshank
2bd1bca192 Resolve #4291: Comments forcing unexpected indents. (#4384) 2023-02-11 21:21:08 +00:00
Alan Cruickshank
af566a43be Resolve #4294: Comments affecting indentation (#4337)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-02-11 21:00:03 +00:00
Alan Cruickshank
5acfa723c1 Window function long line fixes (#4383) 2023-02-10 17:09:52 +00:00
AidanHarveyNelson
09fea29179 TSQL: ALTER INDEX (#4364)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-02-10 16:00:19 +00:00
AidanHarveyNelson
7c3ea5d116 TSQL: Added Varying Keyword to allowed data type segments (#4375) 2023-02-09 18:39:46 +00:00
Greg Finley
78943d5615 Add ruff linter (#4372) 2023-02-09 18:06:06 +00:00
Peter Debelak
d7703c9d8f Postgres: column constraint default syntax (#4379) 2023-02-09 17:38:42 +00:00
gavin-tsang
b20e09a6ff Allow function names to have a leading underscore (#4377) 2023-02-09 13:41:51 +00:00
AidanHarveyNelson
366b9f4323 TSQL: Merge Hints (#4354) 2023-02-08 14:31:48 -08:00
AidanHarveyNelson
89b878eceb TSQL: Temporal Table (#4358)
* First Commit with Table Options included in Create Table statement to allow for temporal tables

* Added Temporal Table Queries

* Updated code based on feedback and provided greater test coverage

---------

Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-02-08 13:33:48 +00:00
AidanHarveyNelson
ed46f5dfc2 TSQL: ALTER TABLE (#4369)
* Added support for multiple columns on add statement

* Slight change

---------

Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-02-08 11:52:53 +00:00
Danny Jones
9c46173959 Duckdb: SELECT * bugfix (#4365) 2023-02-07 10:57:44 -08:00
Greg Finley
945b466470 Postgres: TABLESAMPLE query (#4357) 2023-02-07 10:31:13 -08:00
Alan Cruickshank
1edbe63405 reindent refactor (#4338)
* Refinements to elements

* Modularity work without logic change

* black

* resolve has_newline issue

* coverage

* preemptive linting
2023-02-07 18:02:02 +00:00
AidanHarveyNelson
f320eb83a1 Snowflake: INSERT INTO test case (#4363) 2023-02-06 14:43:19 -08:00
Gergely Imreh
2e6a4906ef Docs: correct toml syntax of pyproject.toml file config example (#4361) 2023-02-06 11:23:55 -08:00
AidanHarveyNelson
87e0006503 Postgres: Storage Allowed Naked Identifiers (#4359) 2023-02-06 11:01:59 -08:00
AidanHarveyNelson
9171c8d57e TSQL: TABLESAMPLE (#4353) 2023-02-04 22:41:22 -08:00
AidanHarveyNelson
0ba09c6e27 Tsql: Function Parameters (#4352) 2023-02-04 19:54:11 -08:00
AidanHarveyNelson
873b6f89dc Postgres: Storage parameters (#4350) 2023-02-04 18:07:08 -08:00
AidanHarveyNelson
a678413a81 TSQL: Bare Function Set (#4351) 2023-02-04 17:28:22 -08:00
AidanHarveyNelson
5b1e0467ad Postgres: View options (#4340) 2023-02-03 13:53:36 -08:00
Joar Wandborg
cd01b5c0ee BigQuery: SELECT DISTINCT AS STRUCT (#4341) 2023-02-03 09:14:41 -08:00
AidanHarveyNelson
909bb30279 Snowflake: Fix Alter Warehouse (#4344) 2023-02-02 21:18:51 -08:00
Danny Jones
b9e9824d28 Parser: Optimise lookahead_match (#4327)
* Parser: Optimise lookahead_match

* Linting

* Optimise anyof

* Revert "Optimise anyof"

This reverts commit b84bdb7459.

* black

* Optimise trim_elem

---------

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-02-02 23:01:11 +00:00
Peter Debelak
5baf6fd7ac Add support for dbt test macros (#4319) 2023-01-30 10:23:11 -08:00
Peter Debelak
4619000549 Bracket complex expressions before applying :: operator in Rule L067 (#4326)
This surrounds complex expressions with `()` before fixing a cast or
convert to a shorthand cast using the `::` operator. Without this
change, the cast would be applied to only part of the appropriate
expression.

fixes #4301
2023-01-28 17:49:10 +00:00
github-actions[bot]
c6e87f4071 Prep version 2.0.0a4 (#4322) 2023-01-27 09:56:42 -08:00
Greg Finley
fba8e13832 BigQuery: Alter table alter column (#4316) 2023-01-26 08:19:56 -08:00
Greg Finley
c867275940 Handle renamed dbt exceptions (#4317) 2023-01-25 15:18:20 -08:00
Danny Jones
640888ab08 Parser: Fix early exit for simple matchers (#4305)
* Parser: Fix early exit for simple matchers

* black
2023-01-25 12:52:39 +00:00
Yoichi NAKAYAMA
7fd6602253 MySQL: Add CREATE DATABASE and ALTER DATABASE (#4307)
* MySQL: Add CREATE DATABASE and ALTER DATABASE

* handle CREATE SCHEMA in CreateDatabaseStatementSegment
2023-01-24 11:17:31 +00:00
Yoichi NAKAYAMA
fa9e99d042 BigQuery: Add ALTER VIEW (#4306) 2023-01-22 11:42:02 +00:00
Kevin Marsh
b5ca7eb24d toml: only install toml dependency if < Python 3.11 (otherwise use builtin tomllib) (#4303) 2023-01-20 10:54:06 -08:00
Matthieu Caneill
8f5ad0a928 Fix example plugin unit tests import (#4302) 2023-01-19 12:00:12 -08:00
github-actions[bot]
6b633233c6 Prep version 2.0.0a3 (#4290)
* Bump to version 2.0.0a3

* update changelog and roll set stable release label

* update changelog

* Update notes on dbt templater

* Line length

* bump to trigger build

Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2023-01-16 22:16:26 +00:00
KaoutherElhamdi
5023721ea4 Move ISSUE from Snwoflake reserved keywords to unreserved ones (#4279)
* Move ISSUE from Snwoflake reserved keywords to unreserved ones

* Add select statement to snowflake parsing test

* move test case to snowflake_select fixture
2023-01-16 12:48:36 +00:00
Barry Hart
fcddf0f5c8 Due to performance and other issues, revert the osmosis implementation of the templater for now (#4273)
* Revert osmosis dbt templater for now

* Revert the osmosis implementation of the templater for now

* Fix broken test

* Fix coverage gaps

* More coverage fixes

* PR review

* PR review

Co-authored-by: Barry Hart <barry.hart@zoro.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-01-16 11:59:37 +00:00
Alan Cruickshank
92c2391728 Simplify lexing (#4289) 2023-01-16 10:59:36 +00:00
Alan Cruickshank
70654101da Fix #4255 (#4288) 2023-01-16 10:03:03 +00:00
Alan Cruickshank
c24a636fcd Fix #4253 (#4287)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2023-01-16 09:27:47 +00:00
Alan Cruickshank
6f7f454be5 Fix #4249 (TSQL block comment indents) (#4286)
* Resolve #4249

* Add test case
2023-01-15 23:39:38 +00:00
Alan Cruickshank
cf2d35c572 Fix #4252 (Resolve multiple sensible indents) (#4285)
* Fix #4252

* Correct the test case
2023-01-15 23:02:04 +00:00
Danny Jones
f462e996a5 Parser Performance: Cache segment string repr to reduce function calls (#4278)
* Cache segment string repr to reduce function calls

* Cache segment string repr to reduce function calls

* Add helpful comment

* linting

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-01-15 22:37:40 +00:00
Danny Jones
6071b70ef6 Snowflake: GRANT SUPPORT CASES (#4283)
* Snowflake: GRANT SUPPORT CASES

* black

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2023-01-15 20:30:50 +00:00
Danny Jones
b543b0084d Dialect: duckdb (#4284)
* Dialect: duckdb

* Github labels: duckdb

* black

* Update autocomplete test

* Update autocomplete test
2023-01-15 20:05:34 +00:00
Danny Jones
30cfe0a504 Snowflake: Add variable pattern to CopyIntoTable (#4275)
* Snowflake: Add variable pattern to CopyIntoTable

* black
2023-01-15 16:33:49 +00:00
Danny Jones
7151c74748 Postgres: Non-reserved keyword bugfix (#4277)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2023-01-15 16:10:02 +00:00
Danny Jones
b300c10be5 Hive: Add Table constraints DISABLE VALIDATE (#4281)
* Hive: Add Table constraints DISABLE VALIDATE

* black

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2023-01-15 15:45:44 +00:00
Danny Jones
c8b90ae9c2 Snowflake: Add Python and Java UDF support (#4280)
* Snowflake: Add Python and Java UDF support

* Use AnySetOf
2023-01-15 15:25:25 +00:00
Danny Jones
16ee06e01c SparkSQL: Support DIV binary operator (#4282)
* SparkSQL: Support DIV binary operator

* black

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2023-01-15 15:04:41 +00:00
Yoichi NAKAYAMA
5a740d54d4 BigQuery: Add ALTER TABLE (#4272)
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2023-01-15 12:01:11 +00:00
Danny Jones
1c14418e92 Snowflake: Update bare functions (#4276) 2023-01-14 22:53:52 +00:00
Thomas Durieux
26f7f2518a Reduce Dockerfile image size (#4262) 2023-01-11 10:02:24 -08:00
github-actions[bot]
bc64d2df71 Prep version 2.0.0a2 (#4247)
* Bump to version 2.0.0a2

* Update changelog and don't upgrade stable version

Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2023-01-07 15:05:17 +00:00
Alan Cruickshank
1f027c14bb Push indents to after comments (#4239)
* Push indents to after comments

* linting

* update tests

* add CASE test case

* some more coverage changes

* test case to get better coverage
2023-01-07 09:43:36 +00:00
Alan Cruickshank
665e2a202f Templated fix improvements and indentation (#4245)
* Allow empty string.

* Handle leading templated placeholder whitespace.

* add the test case

* edit the source string too

* combine multiple source fixes if given

* Fix test case

* lint and mypy

* yaml lint

* coverage

* Update src/sqlfluff/utils/reflow/reindent.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2023-01-06 23:36:38 +00:00
Alan Cruickshank
3944f97cde Fix block comment indent fixes #4224 (#4240)
* Fix block comment indent fixes #4224

* better test case

* PR Feedback
2023-01-06 11:19:22 +00:00
Alan Cruickshank
3405f256a0 Fix for #4222 (#4236)
* Fix #4222

* fix typo

* go back - it was better before. Problem is #4226

* Resolve #4226

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2023-01-05 16:19:11 +00:00
Greg Finley
9eaf89b298 Snowflake: Allow multiple unpivot (#4242) 2023-01-05 10:27:02 +00:00
Yiwen Gao
e69326cf6a postgres: add row-level locks to SELECT statements (#4209)
* WIP

* Fix test

* Update comment

Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-01-04 17:17:41 -08:00
Nelson Torres
ddc9841936 Add more parsing logic for db2 (#4206)
* fix: db2 unparsed section for case statement

* fix: db2 unparsed section for fetch statement

* fix: db2 unparsed section for function within group

* feat: add days to ansi keywo

* fix: move db2 syntax away from ansi dialect

* refactor: lint code

* feat: Add missing test yml files

Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2023-01-04 16:40:53 -08:00
Alan Cruickshank
e251fd84bf Include the filename in critical exceptions (#4225)
* Include the filename in critical exceptions

* tweek docstrings to appease flake8

* Revert "tweek docstrings to appease flake8"

This reverts commit 7a231b7ff8.

* pin pydocstyle to pre 6.2.0
2023-01-03 13:50:57 +00:00
Alan Cruickshank
e8a6b26ea5 update readme badges (#4219) 2022-12-29 18:05:04 +00:00
Barry Hart
f1752f9b62 diff-quality: Handle the case where there are no files to check (#4220)
* diff-quality: Handle the case where there are no files to check

* Add test case with no files

* Remove "pragma: no cover"
2022-12-29 08:02:20 -05:00
github-actions[bot]
942cb34df8 Prep version 2.0.0a1 (#4203)
* Bump to version 2.0.0a1

* revert stable docs version

* Changelog with description.

* Update changelog

* Update CHANGELOG with additional PR merges, also the release date

* One more PR

Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-12-28 22:31:30 +00:00
William Ayd
318c7c9808 Fixed False Positive for L037 (#4198)
* fixed l037

* better impl for codecov

* make mypy happy

* first attempt at dbt test

* make flake8 happy

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-12-28 16:00:43 -05:00
Alan Cruickshank
a8f2e59c95 Fix #4215 (#4217)
* Fix #4215

* Revert original change

* Bypass safeties for L003 and L016
2022-12-28 20:18:17 +00:00
Alan Cruickshank
0b1f2aab2a don't consider templated whitespace (#4213)
* don't consider templated whitespace

* add test case

* linting and resolve test case
2022-12-28 16:21:54 +00:00
Alan Cruickshank
91ec935579 show fatal errors regardless (#4214) 2022-12-28 14:28:29 +00:00
Alan Cruickshank
ed5406ee56 don't pickle the templater (#4208)
* don't pickle the templater

* PR feedback
2022-12-27 18:21:01 +00:00
Yoichi NAKAYAMA
83636f2435 MySQL: Support column character set and collation (#4204)
https://dev.mysql.com/doc/refman/8.0/en/charset-column.html

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-12-25 12:32:39 -05:00
Barry Hart
4247206e50 Fix some issues with Docker Compose environment (#4201)
* Fix some issues with Docker Compose environment

* Oops, wasn't setting the flag correctly?

* Set pip_pre = false

* Black

* Skip coverage checks for ruleslinting and doctests

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-12-24 21:00:36 -05:00
Alan Cruickshank
375a740744 Implicit Indents (#4054)
* Implicit Indents Rebase

* add configuration for implicit

* mypy, linting and consistency

* linting

* Coverage and long line treatment of implicits.

* add docs

* doc linting

* coverage

* Update src/sqlfluff/utils/reflow/reindent.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* make sure that tests are the same

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-12-24 22:11:54 +00:00
Barry Hart
e62e2782b7 Tweak Coveralls settings (#4199)
* Add .gitpod.yml

* Remove .gitpod.yml

* Tweak Coveralls

* Tweak base-path

* Trigger build

* Specify "--cov=" appropriate to each build

* Tweaks

* Tweaks

* Change .tox paths to src/sqlfluff paths

* Run patch_lcov.py from tox, not from ci-tests.yml

* Fail-safe the script

* Add debug message

* Do nothing if coverage file not found

* Only try and patch lines where path begins with ".tox"

* Move Coveralls coverage builds first so we get results sooner

* Revert "Move Coveralls coverage builds first so we get results sooner"

This reverts commit b5df02bf8f.

* PR review: more detailed docstring
2022-12-23 14:22:16 -05:00
Barry Hart
df09b33888 In addition to Codecov, also upload to Coveralls (#4197)
* Add .gitpod.yml

* Try using Coveralls rather than Codecov

* Remove .gitpod.yml

* Remove .gitpod.yml

* Trigger build

* Can't use Coverlls container action on Windows

* Update to use documented approach with Coveralls

* Install coveralls "on demand" before running

* Add GitHub token to Coveralls command

* Add "--service=github"

* Switch to official GitHub action, re-enable 2-way parallelism for some test runs

* Convert coverage file to lcov format for Coveralls upload

* Output pytest coverage in lcov format

* Specify path-to-lcov: coverage.lcov

* Add back codecov upload
2022-12-22 16:54:52 +00:00
Nelson Torres
056ce08aee Fix: default cast at create table returns unparsable section (#4192)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-12-22 06:31:30 +00:00
Barry Hart
1b0dc8226d Fix JSON parsing issue with diff-quality plugin (#4190)
* Fix JSON parsing issue with diff-quality plugin

* Fix issue on Windows: Need to close file so SQLFluff can write to it

* Remove unneeded "mode" parameter

* Trigger build

* Trigger build

* Fix possible cause of intermittent build issue

* Disable parallel test runs for jobs that upload to codecov

* Undo coverage-related changes

* Trigger build

Co-authored-by: Barry Hart <barry.hart@zoro.com>
2022-12-21 21:39:48 -05:00
Alan Cruickshank
ce6a6ccc45 Codecov migration (#4195)
* Use the V3 codecov uploader

* remove verbose flag

* add token to flow

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-12-21 19:52:01 -05:00
baa-ableton
bee3d9ed64 Stop adding trailing os.sep if ignore file is on the root of the file… (#4182)
* Stop adding trailing os.sep if ignore file is on the root of the file system

* Replaced single quotes with doubles to pass linting test

* Replaced hard-coded Linux FS root with OS agnostic expression

* Made linting changes suggested by Black

* Included paretheses to isolate logic

* Trigger build

Co-authored-by: Babur Ayanlar <baa@client3873.office.ableton.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Barry Hart <barry.hart@zoro.com>
2022-12-21 21:06:48 +00:00
Barry Hart
edb79809d2 Port dbt-osmosis templater changes to SQLFluff (#3976)
* Port dbt-osmosis templater changes to SQLFluff

* Ran Black on the file

* Get some tests working

* Remove some likely obsolete tests

* Pass CLI vars to dbt-osmosis

* Add osmosis.py to SQLFluff

* Fix CI issues

* flake8

* Only run doctests for SQLFluff core, not sqlfluff-templater-dbt

* Skip sqlfluff-templater-dbt when running doctests

* Move osmosis.py to sqlfluff-templater-dbt package

* Misspelled package name

* Remove support for dbt < 1.0

* Removing bits of dbt < 1.0

* Add missing package

* Get more tests working

* Fix issues with ephemeral model compilation

* Remove osmosis.py; was moved to osmosis/__init__.py

* Add back functions that shouldn't have been removed

* Fix project_dir issue

* Fix some broken tests

* Try a different way of resetting between tests

* Try and get tests working

* Try to fix broken tests

* Remove unneeded compile() function; use compile_node().node

* PR review

* Add Apache license note

* Update plugins/sqlfluff-templater-dbt/sqlfluff_templater_dbt/templater.py

* Add back code for handling db connection errors, also if project_dir not set

* Add missing dependencies

* Fix broken test

* Remove the fake db connection error; causes other tests to fail somehow

* Add Sponsors section with Datacoves

* PR review

* Add back the test__templater_dbt_handle_database_connection_failure test

* Fixes, tweaks to the CI checks (dbt Windows tests were failing intermittently with dbt 1.0)

* Tweak Python versions: 3.9 -> 3.10

* Run Black

* Fix some issues with dbt 1.4.0b1

* Trigger build

* Run Black

* Black

* Create missing constraints file

* Tweak version

* Tweaks due to dbt test weirdness

Co-authored-by: Barry Hart <barry.hart@zoro.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-12-19 16:20:24 +00:00
Alan Cruickshank
c3da538201 Reflow 4: Long Lines (#4067)
* map reindent lines

* Test empty line behaviour

* The meat of reindent + tests

* templated test

* cleaner fix

* another buggy test case

* Set up intended tests

* Add block uuids

* template tag cases and logic

* drive indent unit from config

* Sever link between L003 and L016

* First pass at L003 kinda running

* Fix broken test

* untaken indents tracking

* Alternative indentation algorithm

* associated indent dialect tweeks

* handle comment lines and join indents better

* make to ignoring certain types works

* first pass at new approach to hanging indents

* Check that the fixes work too.

* Refactor single indent and add hanging test cases

* more robust hanging indent treatment

* New reindent algorithm mostly works.

* WIP: test cases for new method

* Consolidate and tests

* WIP: It's not pretty but we're getting there.

* Revise comment lines

* update hanger tests

* progress

* whoop indent on maths works

* more maths tweeking

* Revise Templated Lines

not pretty but mostly working

* Untaken indents rigour and testing

* Skip lines and linting

* dialect and test tweeks

* Handle templated newlines and templated indents

* Remove remaining references to old config

* mypy linting and references

* more test updates

* handle other placeholders better

* handle is_templated better

* bugfix to indents near templated lines

* Tests for whitespace consuming tags

* Not tidy - but most of the way to lexer rebuild

* linting and begin refactor

* block uuids and tidying

* clearup and handle unrendered templates

* Tidy up

* mypy

* yaml lint

* handle zero length slices better

* remove too many warnings

* Handle source only fixes more gracefully

* typo

* Comment revision logic tweeks

* mypy

* stretching test cases for tags which consume whitespace.

* Reindent logging (ironically)

* Test case working (before consuming whitespace)

* Crawl test works for consumed whitespace

* closer - but not quite

* slice helpers and more detailed mid point patches

* Refine source and template slicing more.

* fix reflow tests

* Better fix patches for literals.

* Fix coercion of placeholder newlines.

* Fix starting pos marker issue

* Fix newline bug

* Edge case handling for semicolons

* Rework indents in exasol

* Add a note to future self

* tsql indentation test cases

* mypy

* Update tests

* Remove specific L003 tests

* fix positioning checks of L003

* fix one part of standard testing

* Better fix deduplication

* Tweek to missing line detection

* Another edge case

* fix edge case in dbt tests

* Squash another bug.

* ANOTHER edge case

* Nice error messages for reindent

* mypy

* docstring issues

* Rethink indents slightly

* prevent odd unused indent pairs

* fix last config test

* Coverage edits

* linting

* use more slice helpers

* a little more helper usage

* coverage

* Coverage and deduplication

* qualify the assertion

* More coverage

* remove unnecessary code path

* linting

* Remove unused section & more coverage

* Revert removal of whitespace slicing code

* Remove unused section

* Remove unused code path

* linting

* Remove some TODO notes and add better docstrings and tests

* Better fix for #3836

* mypy

* Add fix for #3988

* Apply suggestions from code review

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* skip multi-line templated elements

* Revise comment

* Update comment on anchor shuffle.

* another clearer comment

* Better newline comments.

* Add helper function for consumed whitespace

* linting

* Reindent refactor

* Linting.

* Remove SPOILERS

* Update src/sqlfluff/utils/reflow/elements.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* better comment

* First tidy prototype

* Move configurable line lengths.

* fix broken reference

* core tests pass

* better logging and first line detection

* Rip out old L016 logic

* add error and fail tests to pytest summary

* better logging in dbt tests

* Switch reflow buffer from LintFix to LintResult

* mypy

* fix reflow tests

* fix duplication

* fix test cases

* fix missing results

* fix L006 positioning tests

* sort out assignment operators

* mypy

* Correct more test cases

* Fix some merge issues

* More fixes > results

* revert changes to LintFix with description

* fix reindent test

* fix a merge bug

* more bad merge fixes

* Handle long comment lines

* attempt ignore comment clauses

* Fix the easy errors. Still got hard ones left.

* solve the key error problem

* Fix two tests and add more logging for others.

* Fix templated newline detection

* linting and mypy

* Fix config issues

* Deal with source character lengths.

* fix rules test

* don't indent more than we need to for now.

* linting

* result source and line length fixes

* Indexing and more bug fixes

* fix assertion error

* More fixes

* better comment clause handing

* deeper comment ignores

* Better templated comment handling

* Fix more erroneous test cases

* more line length changes

* linting

* linting

* even more position marker fiddling

* off by one error

* skip indents in calculating lengths

* block comment handling

* operator precedence

* More stretching test cases

* yamllint

* Tidy up comments and logging

* break apart some of the bigger functions

* mypy tweeks

* Solution and test for the multiline jinja bug.

* A diversion into breaking around clauses

* Coverage improvements

* remove test dupe

* coverage fix

* Apply suggestions from code review

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* More PR feedback.

* Apply suggestions from code review

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Formulate range expression properly

* reword config docs

* simpler looping

* move max line length

* Correct config spec for moved values

* Isolate and better test balance increment logic

* mypy fix

* Apply suggestions from code review

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* clarify comment

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-12-19 13:27:16 +00:00
Alan Cruickshank
7db24b03b0 Fix comment bug on reindent (#4179)
* map reindent lines

* Test empty line behaviour

* The meat of reindent + tests

* templated test

* cleaner fix

* another buggy test case

* Set up intended tests

* Add block uuids

* template tag cases and logic

* drive indent unit from config

* Sever link between L003 and L016

* First pass at L003 kinda running

* Fix broken test

* untaken indents tracking

* Alternative indentation algorithm

* associated indent dialect tweeks

* handle comment lines and join indents better

* make to ignoring certain types works

* first pass at new approach to hanging indents

* Check that the fixes work too.

* Refactor single indent and add hanging test cases

* more robust hanging indent treatment

* New reindent algorithm mostly works.

* WIP: test cases for new method

* Consolidate and tests

* WIP: It's not pretty but we're getting there.

* Revise comment lines

* update hanger tests

* progress

* whoop indent on maths works

* more maths tweeking

* Revise Templated Lines

not pretty but mostly working

* Untaken indents rigour and testing

* Skip lines and linting

* dialect and test tweeks

* Handle templated newlines and templated indents

* Remove remaining references to old config

* mypy linting and references

* more test updates

* handle other placeholders better

* handle is_templated better

* bugfix to indents near templated lines

* Tests for whitespace consuming tags

* Not tidy - but most of the way to lexer rebuild

* linting and begin refactor

* block uuids and tidying

* clearup and handle unrendered templates

* Tidy up

* mypy

* yaml lint

* handle zero length slices better

* remove too many warnings

* Handle source only fixes more gracefully

* typo

* Comment revision logic tweeks

* mypy

* stretching test cases for tags which consume whitespace.

* Reindent logging (ironically)

* Test case working (before consuming whitespace)

* Crawl test works for consumed whitespace

* closer - but not quite

* slice helpers and more detailed mid point patches

* Refine source and template slicing more.

* fix reflow tests

* Better fix patches for literals.

* Fix coercion of placeholder newlines.

* Fix starting pos marker issue

* Fix newline bug

* Edge case handling for semicolons

* Rework indents in exasol

* Add a note to future self

* tsql indentation test cases

* mypy

* Update tests

* Remove specific L003 tests

* fix positioning checks of L003

* fix one part of standard testing

* Better fix deduplication

* Tweek to missing line detection

* Another edge case

* fix edge case in dbt tests

* Squash another bug.

* ANOTHER edge case

* Nice error messages for reindent

* mypy

* docstring issues

* Rethink indents slightly

* prevent odd unused indent pairs

* fix last config test

* Coverage edits

* linting

* use more slice helpers

* a little more helper usage

* coverage

* Coverage and deduplication

* qualify the assertion

* More coverage

* remove unnecessary code path

* linting

* Remove unused section & more coverage

* Revert removal of whitespace slicing code

* Remove unused section

* Remove unused code path

* linting

* Remove some TODO notes and add better docstrings and tests

* Better fix for #3836

* mypy

* Add fix for #3988

* Apply suggestions from code review

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* skip multi-line templated elements

* Revise comment

* Update comment on anchor shuffle.

* another clearer comment

* Better newline comments.

* Add helper function for consumed whitespace

* linting

* Reindent refactor

* Linting.

* Remove SPOILERS

* Update src/sqlfluff/utils/reflow/elements.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* better comment

* Switch reflow buffer from LintFix to LintResult

* mypy

* fix reflow tests

* fix duplication

* fix test cases

* fix missing results

* fix L006 positioning tests

* sort out assignment operators

* mypy

* Correct more test cases

* Fix some merge issues

* More fixes > results

* revert changes to LintFix with description

* fix reindent test

* fix a merge bug

* more bad merge fixes

* Fix comment bug on reindent

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-12-19 11:38:55 +00:00
Alan Cruickshank
2b32cb2294 Reflow 3: Reindent (#3942)
* map reindent lines

* Test empty line behaviour

* The meat of reindent + tests

* templated test

* cleaner fix

* another buggy test case

* Set up intended tests

* Add block uuids

* template tag cases and logic

* drive indent unit from config

* Sever link between L003 and L016

* First pass at L003 kinda running

* Fix broken test

* untaken indents tracking

* Alternative indentation algorithm

* associated indent dialect tweeks

* handle comment lines and join indents better

* make to ignoring certain types works

* first pass at new approach to hanging indents

* Check that the fixes work too.

* Refactor single indent and add hanging test cases

* more robust hanging indent treatment

* New reindent algorithm mostly works.

* WIP: test cases for new method

* Consolidate and tests

* WIP: It's not pretty but we're getting there.

* Revise comment lines

* update hanger tests

* progress

* whoop indent on maths works

* more maths tweeking

* Revise Templated Lines

not pretty but mostly working

* Untaken indents rigour and testing

* Skip lines and linting

* dialect and test tweeks

* Handle templated newlines and templated indents

* Remove remaining references to old config

* mypy linting and references

* more test updates

* handle other placeholders better

* handle is_templated better

* bugfix to indents near templated lines

* Tests for whitespace consuming tags

* Not tidy - but most of the way to lexer rebuild

* linting and begin refactor

* block uuids and tidying

* clearup and handle unrendered templates

* Tidy up

* mypy

* yaml lint

* handle zero length slices better

* remove too many warnings

* Handle source only fixes more gracefully

* typo

* Comment revision logic tweeks

* mypy

* stretching test cases for tags which consume whitespace.

* Reindent logging (ironically)

* Test case working (before consuming whitespace)

* Crawl test works for consumed whitespace

* closer - but not quite

* slice helpers and more detailed mid point patches

* Refine source and template slicing more.

* fix reflow tests

* Better fix patches for literals.

* Fix coercion of placeholder newlines.

* Fix starting pos marker issue

* Fix newline bug

* Edge case handling for semicolons

* Rework indents in exasol

* Add a note to future self

* tsql indentation test cases

* mypy

* Update tests

* Remove specific L003 tests

* fix positioning checks of L003

* fix one part of standard testing

* Better fix deduplication

* Tweek to missing line detection

* Another edge case

* fix edge case in dbt tests

* Squash another bug.

* ANOTHER edge case

* Nice error messages for reindent

* mypy

* docstring issues

* Rethink indents slightly

* prevent odd unused indent pairs

* fix last config test

* Coverage edits

* linting

* use more slice helpers

* a little more helper usage

* coverage

* Coverage and deduplication

* qualify the assertion

* More coverage

* remove unnecessary code path

* linting

* Remove unused section & more coverage

* Revert removal of whitespace slicing code

* Remove unused section

* Remove unused code path

* linting

* Remove some TODO notes and add better docstrings and tests

* Better fix for #3836

* mypy

* Add fix for #3988

* Apply suggestions from code review

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* skip multi-line templated elements

* Revise comment

* Update comment on anchor shuffle.

* another clearer comment

* Better newline comments.

* Add helper function for consumed whitespace

* linting

* Reindent refactor

* Linting.

* Remove SPOILERS

* Update src/sqlfluff/utils/reflow/elements.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* better comment

* Switch reflow buffer from LintFix to LintResult

* mypy

* fix reflow tests

* fix duplication

* fix test cases

* fix missing results

* fix L006 positioning tests

* sort out assignment operators

* mypy

* Correct more test cases

* Fix some merge issues

* More fixes > results

* revert changes to LintFix with description

* fix reindent test

* fix a merge bug

* more bad merge fixes

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-12-19 10:54:12 +00:00
github-actions[bot]
f3762975a6 Prep version 1.4.5 (#4180)
* Bump to version 1.4.5

* update changelog

* Update changelog with note about 2.x.x

* black doesn't like some blank lines

Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2022-12-19 09:51:19 +00:00
Nelson Torres
c329bb0b28 Add rule for space around parenthesis (#4131)
* feat: Add rule for space around parenthesis

* lint L071

* lint L071

* fix broken test ignoring rules

* fix broken test index out of range

* fix return type syntax

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-12-18 09:29:01 +00:00
Barry Hart
2fa1046060 diff-quality plugin: Print invalid JSON on parse failure (#4176) 2022-12-16 09:05:32 -08:00
Barry Hart
09866c3138 Ensure diff-quality runs the correct SQLFluff (#4175) 2022-12-16 09:41:46 -05:00
github-actions[bot]
94f69fea6d Prep version 1.4.4 (#4170)
* Bump to version 1.4.4

* Remove New Contributors Section

* Update CHANGELOG.md

Co-authored-by: tunetheweb <tunetheweb@users.noreply.github.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-12-14 22:34:07 +00:00
Barry Pollard
21e8de558e Recognise || as an operator to avoid rule L006 flagging it (#4168)
* Recognie || as an operator to avoid rule L006 flagging it

* Better fix

* Better order
2022-12-14 20:27:42 +00:00
Paul Wildenhain
0fb5f083c1 🐛 Check verbosity level of pytest run before running certain tests (#4167)
This test failed when I just ran `pytest`, but succeeded when I ran `pytest -vv`. This is because "select" only appeared in the output when the verbosity level was at least two. Felt like the simplest change to just double check the verbosity level of the test run before deciding to check for this regex match
2022-12-14 14:57:24 -05:00
mp56
e62a747137 Snowflake: Add support for select exclude and replace syntax (#4160) 2022-12-13 16:30:42 -08:00
github-actions[bot]
f0c92d584b Prep version 1.4.3 (#4158)
* Bump to version 1.4.3

* Update CHANGELOG.md

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Remove duplicate text in CHANGELOG.md

* Renumber new rules 69,70 -> 67,68; add rule 68 to CHANGELOG.md

* Linkify release notes

* Rename rule classes for the new rules

* Rename rule in default_config.cfg

* Rename rules in test .yml files

Co-authored-by: barrywhart <barrywhart@users.noreply.github.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry Hart <barry.hart@zoro.com>
2022-12-13 18:58:51 -05:00
Yoichi NAKAYAMA
170e2e6e95 L037: insert ASC just after column_reference (#4149) 2022-12-12 18:37:31 -08:00
Barry Hart
b88c8edd8c Implement diff_quality_plugin using command-line rather than Python (#4148)
* Implement diff_quality_plugin using command-line rather than Python

* Linting

* Update diff-quality plugin tests

* Port dbt templater connection management changes from the other PR for this issue

* Fix Windows test failure

* Add support for "--options" (however, will require diff-quality changes to work)

* Add support for passing in pregenerated reports

* Tweak code to fix coverage gap

* Cache dbt adapters by project, not by adapter type, fix deprecation warning

* Trigger build

* Trigger build

* Avoid using subprocess in plugin tests -- does this avoid coverage checks hanging?

Co-authored-by: Barry Hart <barry.hart@zoro.com>
2022-12-12 21:03:37 -05:00
Peter Debelak
ada7967cd2 Allow deprecated --disable_progress_bar flag for fix command (#4151)
Resolves #4140
2022-12-12 20:15:12 -05:00
Barry Pollard
dc59c2a567 Fix passenv to work with tox 4 (#4154) 2022-12-12 15:23:59 +00:00
Mayur Singal
9cd847eb67 SparkSQL: Mark AS as optional keyword for CTE & CTS (#4127) 2022-12-10 11:00:39 -08:00
Greg Finley
1e23072592 SparkSQL: ILIKE (#4138) 2022-12-10 09:12:45 -08:00
Barry Hart
42db36b8ee Only upload 3 sets of test results to codecov (possible workaround for hanging builds) (#4147) 2022-12-09 13:12:40 -08:00
Yoichi NAKAYAMA
71d6cdb6c3 BigQuery: Allow double quoted literal in export_option_list (#4126) 2022-12-09 10:13:29 -08:00
Oliver Borchert
1c50eec697 [DB2] Fix parsing of string identifiers (#4134) 2022-12-09 09:46:38 -08:00
Greg Finley
5364c7e55a Fix tox arguments (#4144) 2022-12-09 09:02:46 -08:00
Noodles
11709caba4 [Snowflake] format type options extensions for copy_into_location (#4129)
* local change

* fic typo

* add partition by clause for copy into location method

* support most of feactures for copy into location

* local change

* fic typo

* format with black

* generate yml files

* change format of sql files

* change format

* name change

* generate yml files

Co-authored-by: Charles He <charleshe@Charless-MBP.attlocal.net>
2022-12-01 20:56:51 +00:00
Barry Hart
2a51497d8b L015: Handle COUNT(DISTINCT(col)) (#4110) 2022-11-29 15:19:44 -08:00
Bobby Iliev
ac512e557e Add initial Materialize dialect (#4112) 2022-11-29 07:14:06 -08:00
Barry Hart
645bfa3d9a Bug fix: dbt templater ignores .sqlfluff file encoding on Windows (#4109)
* Fix file encoding issue with the dbt templater on Windows

* Maybe fix encoding issue by using in_str rather than reading file ourselves

* Fix Windows line ending issue with new test
2022-11-26 08:53:42 -05:00
Greg Finley
16c34a26da Postgres: Alter type rename value (#4100) 2022-11-25 15:09:26 -08:00
Barry Hart
75573985e9 Fix bug where L034 should ignore INSERT or "CREATE TABLE AS SELECT" with CTE (#4108)
* Fix bug where L034 should ignore INSERT or "CREATE TABLE AS SELECT" with CTE

* Add test case for merge statement
2022-11-25 11:49:23 -05:00
Barry Hart
0b37a73b5a Fix bug in example rule plugin (#4103)
* Fix bug in example rule plugin

* Trigger build

* Remove now unnecessary # type: ignore
2022-11-25 11:04:56 -05:00
Barry Hart
1872909c5c Fix flake8 issue (#4101) 2022-11-23 13:09:43 -08:00
gavin-tsang
e25b494c88 Enable variable reference names to have leading underscore for snowflake dialect (#4098)
* Included underscore as valid initial character for ReferencedVariableNameSegment.

* Add test case for underscore variable

Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2022-11-23 13:35:07 -05:00
Barry Hart
4c38ebb694 Fix mypy issue with regex (#4097) 2022-11-23 10:09:10 -08:00
Barry Hart
d9355f8ab8 Remove "mystery" binary file added in PR #2923 (#4088)
* Remove "mystery" binary file added in PR #2923

* Trigger build
2022-11-21 18:37:19 -05:00
Peter Balsdon
6a982765b1 Fix syntax in indentation sample code (#4087) 2022-11-21 10:20:26 -05:00
erevear
bd26ce42bc Rule: check number of columns in set operations match (#4028)
* add rule 70 and tests

* add parent crawlers

* add parent crawlers

* run black on python

* remove commented lines

* fix flake8 issues

* fix doc string

* fix docbuild

* fix ymllint

* dict update fixes

* fix py errors

* fix linting

* add test

* fix linting

* add test

* add child cte case test

* add comment

* add final wildcard check test

* edit previous commit message

* Update src/sqlfluff/rules/L070.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/rules/L070.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* add parent query parsing

* add test cases for parent crawler ; update statement

* fix rule yml

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-11-20 09:41:54 -05:00
Barry Hart
f5d726a897 Support parallel linting when many individual files specified (#4084)
* Support parallel linting when many individual files specified

* Add LintedDir to LintingResult

* Fix more tests

* Fix broken test

* Linter.lint_path() forward to Linter.lint_paths()

* Fix Windows tests (path separator)

* Fix issues with Windows tests

* Fix broken test

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-11-19 19:37:09 +00:00
Alan Cruickshank
181918e9c2 Switch reflow buffer from LintFix to LintResult (#4083)
* Switch reflow buffer from LintFix to LintResult

* mypy

* fix reflow tests

* fix duplication

* fix test cases

* fix missing results

* fix L006 positioning tests

* sort out assignment operators

* mypy

* Correct more test cases

* coverage and linting

* Apply suggestions from code review

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-11-19 18:26:58 +00:00
Dave Tapley
7f04ace505 Postgres: Views and named notations (#4073) 2022-11-17 14:32:35 -08:00
Bolaji Wahab
fe771937e7 New rule L069: Consistent syntax for sql type casting (#3747)
* enforce consistent syntax for SQL type casting

* fixed casting in case statements

* regenerated fixtures

* removed unused modules, reformatted and added better comments

* added fixes for multicast

* adjusted new_segment

* added test cases, renamed rule to 69

* added crawl_behaviour and updated functional

* fixed linting errors

* fixed crawl_behaviour

* added config for rule L069

* added support for functional cast_expression in L013

* skip L048 for cast_expression

* allow non standard type casting in L034 fixtures

* added allow_non_standard_type_casting config for rule L069, updated the documentations

* regenerated fixture for jinja templater

* added more test cases for rule L069

* config type hints

* skip teradata, updated documentation

* added test coverage for skipping teradata

* discarded config override in L034 tests

* added cast_expression to L034

* added support for different type casting style

* added tests

* Update src/sqlfluff/rules/L069.py

Adjusted case

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* added more tests for comments, fixed comments raised by @
barrywhart

* added more tests for comments, fixed comments raised by @
barrywhart

* fixing linting errors

* fixing linting errors

* regenerated test yaml files

* added more tests

* Update src/sqlfluff/dialects/dialect_ansi.py

Co-authored-by: Barry Pollard <barrypollard@google.com>

* Update src/sqlfluff/dialects/dialect_ansi.py

Co-authored-by: Barry Pollard <barrypollard@google.com>

* Update src/sqlfluff/dialects/dialect_ansi.py

Co-authored-by: Barry Pollard <barrypollard@google.com>

Co-authored-by: Bolaji Wahab <bolaji.wahab@adjust.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Barry Pollard <barrypollard@google.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-11-17 16:27:26 -05:00
Noodles
f4b51b627c Storage reference segment (#4057)
* local change

* fic typo

* add storage reference segment

* make snowflake copy_options supports both copy_into_location and copy_into_table

* local change

* fic typo

* change typo LiteralNumeric to NumericLiteralSegment

* generate yml files

* format with black

* fix the sql file format

* add copy_into_location_statement_segment

* partially support the format_type_options

* support distinguish between copy_into_location and copy_into_table

* local change

* fic typo

* fix format and generate yml files

* support storage_integration and encryption parameters

* fix parsing error

* generate yml files

* add comment

* local change

* fic typo

* reformat and generate yml

Co-authored-by: Charles He <charleshe@Charless-MBP.attlocal.net>
Co-authored-by: Charles He <charleshe@Charless-MacBook-Pro.local>
2022-11-17 20:56:59 +00:00
Alan Cruickshank
194bd977fd add error and fail tests to pytest summary (#4076) 2022-11-17 14:12:09 +00:00
Marcin Szymański
a006378af8 Fix Spark comparison parsing (#4066) 2022-11-15 15:33:46 -08:00
Sreejith Madhavan
4d2a83c556 Add flyway variables support via placeholder templater (#4026)
* adding new style for supporting flyway placeholder variables in sql

* add fixture for flyway style placeholder templating

* adding placeholder test for flyway_var style

* mandate flyway_var pattern be enclosed in curly brakcets always

* adding test__config__load_placeholder_cfg

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-11-13 10:41:25 -05:00
github-actions[bot]
29faf040f0 Prep version 1.4.2 (#4056)
* Bump to version 1.4.2

* Update changelog

* update changelog

* Update changelog

Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2022-11-13 14:17:14 +00:00
Samyak Sarnayak
d08ff7c2b3 Fix type error in get_rules hook of plugin example (#4060)
The `get_rules` function in the plugin example template had a type
error. The function returns all the rule classes that are defined in
the plugin. The return type was incorrectly annotated as
`List[BaseRule]` which means a list of *instances* of `BaseRule` and not
classes derived from `BaseRule`. Making it `List[Type[BaseRule]]`
instead fixes the error.

For reference, the type error shown by pyright was:
```
Expression of type "list[Type[Rule_Example_L001]]" cannot be assigned to return type "List[BaseRule]"
...
  "Type[type]" is incompatible with "Type[BaseRule]"
```
2022-11-11 08:09:15 -05:00
Barry Hart
b209ac361f L003: Add missing "pragma: no cover" (#4058)
* Add "no cover"

* More "no cover"
2022-11-10 19:09:16 -05:00
anna-azizian
3e45be5ee3 Fix bug in sparksql SELECT statement termination at UNION #4050 (#4052)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-11-10 18:26:28 -05:00
Alan Cruickshank
f3ef68ea35 Deduplicate violations in the source space (#4041)
* Deduplicate violations in the source space

* Make sure we have a source signature even for non-linting errors.

* Update tests

* Add comments
2022-11-10 22:42:50 +00:00
Barry Hart
66fd602d08 Use "docker compose", not "docker-compose" (#4055) 2022-11-10 11:54:53 -08:00
Alan Cruickshank
2f6452b6bf Allow warnings for specific rules (#4053)
* Allow warnings for specific rules

* Update docs

* update config value in test file
2022-11-10 15:02:15 +00:00
Alan Cruickshank
5e2688762a Better file not found error #1023 (#4051)
* Better file not found error #1023

* update tests
2022-11-10 09:10:21 +00:00
Alan Cruickshank
c3defb095b Filter out issues in unparsable sections (#4032)
* Filter out issues in unparsable sections

* coverage

* Test the unparsable code.

* better comment

* Log more when skipping fixes

* linting
2022-11-09 10:53:06 +00:00
Greg Finley
f79ee0f225 Snowflake: ADD and DROP without COLUMN (#4049) 2022-11-08 16:29:05 -08:00
Alan Cruickshank
9dca4dca92 Update architecture links #4047 2022-11-09 00:00:18 +00:00
Alan Cruickshank
391a65c055 Make render command (#4043)
* Make render command

* fix copy pasta

* add a test for stdin

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-11-08 22:18:19 +00:00
Greg Finley
5f639444dd Bump after_n_builds to 10 (#4046) 2022-11-08 11:55:38 -08:00
Adam Tokarski
90c9193409 Redshift: allows for parenthesis around FROM content (#3962)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2022-11-08 09:35:51 -08:00
Greg Finley
f08215061f Update CI to use Python 3.11 (#4038)
* Update CI to use Python 3.11

* Appease mypy

* Appease mypy on older python

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2022-11-08 13:57:05 +00:00
Alan Cruickshank
8161a9a16b Classify self contained set statements as templated (#4034)
* Classify self contained set statements as templated #3750

* Update unblocked tests
2022-11-08 13:12:31 +00:00
Alan Cruickshank
a74c4b3273 SOQL: Date and Datetime literals (#4037) 2022-11-07 14:40:55 -08:00
Alan Cruickshank
89cf0ce762 mypy edits for 0.990 (#4035) 2022-11-07 21:03:03 +00:00
Mikhail Kulakov
3782e1fef2 sparksql: support for create/remove widget clause (#4021) 2022-11-03 08:03:35 -07:00
rpr-ableton
bcb21a5ba7 Redshift: CREATE EXTERNAL FUNCTION statement (#4011) 2022-11-02 07:18:12 -07:00
rpr-ableton
5808423469 Update Redshift bare functions (#4012) 2022-11-01 09:56:40 -07:00
github-actions[bot]
da6f201e59 Prep version 1.4.1 (#4006)
* Bump to version 1.4.1

* Update changelog

* Update changelog

Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2022-10-31 19:19:25 +00:00
Alan Cruickshank
25f2de2c45 Config precedence (#4007)
* Config precedence

* Revert changes in config

* Apply suggestions from code review

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2022-10-31 18:43:52 +00:00
rpr-ableton
c72a82dfc6 Redshift CREATE/ATTACH/DETACH/DROP RLS POLICY statements (#4004) 2022-10-31 09:50:27 -07:00
rpr-ableton
80e8d6e572 Redshift: Add support for APPROXIMATE functions (#3997) 2022-10-31 09:23:21 -07:00
Alan Cruickshank
4ca48eabe7 hotfix to config migration (#4005) 2022-10-31 13:54:37 +00:00
github-actions[bot]
0e89f68dbe Prep version 1.4.0 (#3983)
* Bump to version 1.4.0

* Add summary to changelog

* Update changelog

* update changelog

* Update changelog

* Update changelog

Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-10-31 09:36:05 +00:00
Noodles
0b432571c3 Snowflake: Partition nonreserved keyword (#3972) 2022-10-27 17:22:25 -07:00
Nahuel
556359333c Hive: Add support for EXCHANGE PARTITION in ALTER TABLE (#3991) 2022-10-27 09:23:43 -07:00
Yoichi NAKAYAMA
cad4473bfe Resolve parse error on multiple bracketed statements (#3994) 2022-10-26 15:29:14 -07:00
realLyans
f805878806 BigQuery: Enable parsing of CLONE keyword (#3984) 2022-10-26 15:04:51 -07:00
Yoichi NAKAYAMA
f15cc38ed0 BigQuery: allow nesting of SetExpressionSegment (#3990) 2022-10-26 12:49:58 -07:00
Tomás Farías Santana
6e8756dc16 Clickhouse: Support non-standard CREATE TABLE statement (#3986) 2022-10-26 12:25:51 -07:00
Greg Finley
2ecf297dfa Fix Windows CI check (#3992) 2022-10-26 12:04:57 -07:00
Danny Jones
17a9311fb5 Snowflake tag reference segment (#3985) 2022-10-24 16:48:03 -07:00
Barry Hart
60bff11c7a Fix Jinja templater issue where undefined callable threw an exception (#3982)
* Fix Jinja templater issue where undefined callable threw an exception

* Fix (and test) similar issue when ignore=templating
2022-10-23 11:40:11 +01:00
Alan Cruickshank
10e23f93c0 Reflow Documentation V1 (#3970)
* Start docs reorg

* Spacing docs

* Line Break docs

* rst fixes

* Reflow docs V1

* Autodoc the internals and flesh out docstrings.

* doc linting

* black

* Apply suggestions from code review

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* more docs changes

* rename align scope and add example

* add note on block comments

* more PR feedback

* doclinting

* Update docs/source/configuration.rst

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* PR Feedback

* Update docs/source/layout.rst

Co-authored-by: Niall Woodward <niall@niallrees.com>

* Clarify the point on hanging indents alone.

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Niall Woodward <niall@niallrees.com>
2022-10-22 19:31:07 +01:00
olagjo
12b8f2ef28 Allow lambda argument columns to be unqualified (#3971)
Fixes https://github.com/sqlfluff/sqlfluff/issues/3961

This adds code to identify column references that are part of a lambda
expression, and mark them as "standalone aliases" that are exempt from rule
L027. (I.e. they are allowed to be unqualified, because there is no further
way to qualify them.)
2022-10-22 12:28:06 -04:00
Alan Cruickshank
19601ba546 document inline configuration (#3981)
* document inline configuration

* doclinting
2022-10-22 10:20:29 +01:00
Barry Hart
172dafea12 [BUGFIX] Changing cwd temporarily on manifest load as dbt is not using project_dir to read/write target folder (#3979)
* Changing cwd temporarily on dbt manifest load

Co-authored-by: ssassi@sophilabs.com

* Add a test

* Try to fix broken test

* Fix test interaction

* Adjust dirs to try and pass on GitHub CI

* Profile full path to project and profiles dir

* Try again

* Skip test on Windows
2022-10-20 18:01:18 -04:00
Samyak Sarnayak
e233d8a317 Fix type annotation of user_rules in Linter (#3977)
Fixes #3973
2022-10-20 17:18:59 -04:00
Judah Rand
121d6dd415 Unpin markupsafe (#3967) 2022-10-18 10:33:41 -07:00
Danny Jones
55e68b4ca9 Snowflake frame clause variables (#3969) 2022-10-18 10:09:16 -07:00
Karabulut, Emre
cd1aee84b5 SparkSQL: added support for : (colon sign) operator (Databricks SQL) (#3956) 2022-10-17 15:12:49 -07:00
Hector Castro
159b47afd1 Athena: Add support for using underscore aliases (#3965) 2022-10-15 09:46:38 -07:00
erevear
652ecb63fb Snowflake: ALTER TABLE constraint actions (#3959) 2022-10-14 16:09:30 -07:00
Yoichi NAKAYAMA
cc0052e5a8 MySQL: Support REPLACE statement (#3964)
Also fixes usage of SelectPartitionClauseSegment in LoadDataSegment
2022-10-14 15:05:45 -07:00
Hector Castro
682807656a TSQL: Add support for UPDATE STATISTICS option FULLSCAN (#3950) 2022-10-11 22:10:30 -07:00
Karabulut, Emre
3a13073679 fixed typos in docstrings and comments (#3953) 2022-10-11 21:54:14 -07:00
Emil Sundin
c5038c6dd7 Postgres: ALTER PROCEDURE (#3949) 2022-10-11 09:33:41 -07:00
Oliver Borchert
7e197a5d6e T-SQL: Allow arbitrary expressions in PARTITION BY clause (#3939) 2022-10-09 16:14:19 -07:00
Alan Cruickshank
0b21edbc80 Enable dumping of performance information to csv. (#3937)
* Persist timing information

* beta messaging

* fail nicely for files which don't parse

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-10-09 14:35:33 -04:00
Alan Cruickshank
f691f033ac Consolidate comma style configs (#3945)
* Remove comma style config

* Migrate L022 to new config

* choose a different config field

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-10-09 18:49:07 +01:00
CommonCrisis
6d827b2406 Adding missing KeywordSegments for different file types in Athena dialect (#3898)
* fix/adding-missing-keyword-segments

These types are missing --> therefore the linter is failing with:
RuntimeError: Grammar refers to 'OrcKeywordSegment' which was not found in the athena dialect. Perhaps specify the keyword? https://github.com/sqlfluff/sqlfluff/wiki/Contributing-Dialect-Changes#keywords

* add test for athena orc file

* create yaml file

* test input format

Co-authored-by: CommonCrisis <samuel@Brudi.localdomain>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-10-09 13:25:08 -04:00
Alan Cruickshank
1ef7d86e88 Add templated block uuids (#3936)
* Add block uuids

* Update src/sqlfluff/core/parser/lexer.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-10-09 13:04:22 -04:00
Davi Ajmaya
f015e54912 Load the full dbt manifest (#3926)
* load the full manifest

* add access dbt graph test

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-10-09 09:23:26 -04:00
Yoichi NAKAYAMA
ff08532b23 MySQL: Support optional "IF NOT EXISTS" with CREATE TRIGGER (#3943) 2022-10-09 08:49:24 -04:00
Oliver Borchert
52307754a0 T-SQL: Allow to parse SYNONYM statements (#3941) 2022-10-08 17:02:05 -07:00
Hector Castro
72fed80482 Hive: Add support for LATERAL VIEW clause (#3935)
Add support for `LATERAL VIEW` clause by following the approach put
forth in the SparkQL dialect.

See: https://cwiki.apache.org/confluence/display/hive/languagemanual+lateralview
2022-10-08 21:41:47 +01:00
Barry Hart
5a88ee2302 Fix crash in L042 on "UNION" or other "set" queries (#3931)
* Fix crash in L042 on "UNION" or other "set" queries

* Working version (just needs tidying)

* Undo some unnecessary changes

* Remove more unnecessary changes

* Check for and fix missing whitespace after the CORRECT "FROM"

* Tidying

* DRY things up

* Tweak comments

* Break up compose_select() function, which was doing 2 unrelated things

* Revert "Break up compose_select() function, which was doing 2 unrelated things"

This reverts commit c9c81fc0ca.

* Break up compose_select() again, more carefully

* Comments, docstrings

* Interim commit of refactoring

* Finish splitting up compose_select(), hopefully correctly this time

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-10-08 16:02:54 +01:00
Alan Cruickshank
712fd10552 Refactor Lexer: Split apart elements_to_segments and refine placement of meta segments. (#3925)
* Add indents and dedents around template loop

* mark indents as templated if inserted around templated sections

* docstring and linting

* Split apart elements_to_segments and rework placement of indents

* mypy and linting

* another test case and bug fix

* Apply suggestions from code review

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* condense position markers

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-10-08 15:20:58 +01:00
Oliver Borchert
636aea6713 Add INSERT INTO <> DEFAULT VALUES to ANSI SQL and T-SQL (#3934)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-10-08 09:01:40 -04:00
Alan Cruickshank
ac2fc58eb3 Break apart reflow classes and extract methods (#3919)
* Break apart bigger classes and extract methods

* Simplify structure.

* no cover

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-10-08 07:55:55 -04:00
Oliver Borchert
cdcf58210b T-SQL: Fix indendentation of OUTER APPLY (#3932) 2022-10-08 07:33:38 -04:00
Adam Tokarski
1d29daaa2f MySQL: Fix create trigger (#3928) 2022-10-07 11:35:59 -07:00
Karabulut, Emre
f4ecac63a7 SparkSQL: Fixed bug with QUALIFY usage without WHERE clause (applies also for Databricks dialect) (#3930)
* added `QUALIFY` as terminator

* added a test query without `WHERE` clause for
2022-10-07 19:11:27 +01:00
Oliver Borchert
1863863285 T-SQL: Allow specifying join hints (#3921)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-10-06 17:34:16 +01:00
Hector Castro
07d117a75f SQLite: Add support for table-level CHECK constraint (#3923)
Add support for table-level `CHECK` constraint by following the approach
put forth in the PostgreSQL dialect.

See: https://www.sqlite.org/syntax/table-constraint.html

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-10-06 14:38:42 +01:00
Adam Tokarski
55b7dd0351 [issue_3687] sparksql: added * EXCEPT for SELECT clause (#3922) 2022-10-06 11:13:44 +01:00
Alan Cruickshank
7de21ac05f Map old configs to new configs (#3915)
* Map old configs to new configs

* more explicit logging

* linting

* more explicit test log config

* scrap testing logging output - too hard

* linting

* Update src/sqlfluff/core/config.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-10-05 10:05:51 +01:00
Adam Tokarski
e27dc0b24e [issue_3794] allow to use 'usage' as identifier for postgres (#3914) 2022-10-04 21:55:41 +01:00
Lorin Dawson
263d69cd9e DATABRICKS: Add Support for Delta Live Tables (DLT) Syntax (#3899)
* updates to Spark SQL dialect for Delta Live Tables syntax

* final changes and test cases to sparksql dialect for adding DLT support

* update dialects rst doc file

clarify that Delta Lake expressions are implemented in SparkSQL

add reasoning why Databricks dialect is an alias instead of implemented outside of spark sql

* doclinting

* adding notes based on PR feedback to increase clarity

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-10-04 09:33:37 +01:00
Greg Finley
1da9489632 Postgres Revoke fix (#3912) 2022-10-04 08:59:04 +01:00
Michael
bc787c94af feat: Output to stderr using click (#3902)
- Output to stderr using click
- Use unused color var
- Pass color flag to click
fixes #3892
+ref: https://github.com/sqlfluff/sqlfluff/issues/3892

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-10-03 20:36:30 +01:00
Adam Tokarski
63219a4c26 [issue_3897] fix issue with empty enum for postgres (#3910)
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-10-03 17:15:07 +01:00
Michael
8ccd108c88 feat: Handle postgres ranges (#3903)
- Handle either single int, both numbers, or either
  numbers when accessing postgres array

+ref: https://github.com/sqlfluff/sqlfluff/issues/3842

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-10-03 16:46:36 +01:00
Tomás Farías Santana
4601a8965e fix(test): Return ParseExample namedtuple in get_parse_fixtures (#3911)
* fix(test): Return ParseExample namedtuple in get_parse_fixtures

This allows the usage of dot notation in
test/generate_parse_fixture_yml.py::_is_matching_criteria.

* fix(lint): Add docstring to ParseExample
2022-10-03 15:41:55 +01:00
Kian-Meng Ang
d0e661c618 Fix typos (#3901)
Found via `codespell -S ./test/fixtures,./.mypy_cache,./.tox -L
inout,crate,fo,nd,falsy,get\'s`

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-10-03 14:16:52 +01:00
Adam Tokarski
56ebcd4eb9 provide custom DeprecatedOption (#3904)
* [issue_3644] provide custom DeprecatedOption

This is used for --disable_progress_bar. It's not covered with any tests yet, because not sure if this approach will defend itself.

* [issue_3644] provide some tests for DeprecatedOption

* [issue_3644] fix mypy warnings

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-10-03 11:56:30 +01:00
Tomás Farías Santana
2ac8e12560 fix(redshift): Allow keywords in qualified references (#3905)
* fix(redshift): Allow keywords in qualified references

* fix(redshift): Use ColumnReferenceSegment inherited from Postgres

A previous commit overrode ColumnReferenceSegment to allow keywords to
be used as qualified column references. However, this was a double
override and by deleting the existing override we achieve the same result.
2022-10-03 10:20:44 +01:00
Alan Cruickshank
5385299508 Reflow centralisation 2: Rebreak (operators & commas) (#3847)
* Rebreak for L007 & L019

* Validate configs, deprecate old ones and update tests

* Edge cases, logging, streamlining and bugs

- Correct test and typo in L052
- Remove error case.
- Resolve merge conflicts
- Fix doctest
- Remove reference to old config
- Fix doctest again
- Revert "Remove unused code"
- This reverts commit 4198e559e7.
- Refine treatment of end-of-file
- Test cases and nits
- Two more stretching test cases

* Reclassify end_of_file to be blocky

* introduce strict and alone

* deduce indents and migrate L065

* Address better description in L019

* Apply suggestions from code review

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* anonymous tuple to frozen dataclass.

* reflow element segments to tuple

* Make end of loop more explicit

* while loops to for loops

* max to a for loop

* Clearer newline logic

* correction to while > for

* linting

* linting

* Partition fixes and solve issues

* More tests

* Apply suggestions from code review

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* mypy class typing

* Simplify _RebreakLocation

* validate no double whitespace

* Revert double whitespace check

* more explicit logging

* template loop bug fix

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-10-02 20:15:13 +01:00
Alan Cruickshank
67cbaecd10 Bring L008 into reflow work (#3908)
* Bring L008 into reflow work

* test coverage
2022-10-02 15:28:45 +01:00
Greg Finley
89941aefae Snowflake: Create network policy ip lists (#3888)
* Snowflake: CREATE NETWORK POLICY

* Use create_statement instead
2022-09-30 18:09:38 -04:00
Yoichi NAKAYAMA
bf9af209a4 MySQL: Implement (key_part, ...) in index definitions (#3887) 2022-09-29 09:09:38 -07:00
Alan Cruickshank
c94e47c9bc Reflow centralisation 1: Scope + Respace (#3824)
* Write up intent

* Logging and Config in context

* Reflow + tests

* PR Feedback

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* split apart respace_point

* Resolve merge conflicts on path_to

* Tests for respace

* Tests from #3762.

Co-authored-by: @mtsadler <michaeltsadler1@gmail.com>

* Handle alignment of aliases

* typo and more stretching test

* more test cases and fixes

* split out alignment logic into method

* Resolve single line line bug

* Remove unused code

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: @mtsadler <michaeltsadler1@gmail.com>
2022-09-28 12:15:53 +01:00
Alan Cruickshank
a42258b036 Update github badge and add docker badge (#3884) 2022-09-27 16:02:24 +01:00
github-actions[bot]
9c43c06a12 Prep version 1.3.2 (#3883)
* Bump to version 1.3.2

* Add highlights

Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2022-09-27 15:44:13 +01:00
Gal40n04ek
7c82b65146 Add CreateUserSegment for Snowflake dialect (#3880)
Co-authored-by: Halyna Tsekhmistro <halyna.tsekhmistro@health-union.com>
2022-09-26 11:22:31 -07:00
Alan Cruickshank
388dd01e05 raw_segments_with_ancestors (#3878)
* raw_segments_with_ancestors

* Use PathStep in raw_segments_with_ancestors

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-09-25 18:43:52 +01:00
Alan Cruickshank
14033f7a49 Adjust TSQL Operators (#3877) 2022-09-25 13:09:41 -04:00
Alan Cruickshank
b92b5aeb3c Refactor path_to (#3875)
* Refactor path_to

* Update src/sqlfluff/core/parser/segments/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/core/parser/segments/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Better docstring on path to

* docstrings and tests

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-09-25 16:55:15 +01:00
Alan Cruickshank
d96f23e5f9 Support Removed warning on configs (#3874)
* Support Deprecation on configs

* Rename Deprecated to Removed/Outdated
2022-09-25 15:01:11 +01:00
Yoichi NAKAYAMA
f68159d7b1 MySQL: Support column-path operator for JSON type (#3864) 2022-09-24 16:50:15 -07:00
Differ Group
59c6bce6bb Added T-SQL ALTER FUNCTION/PROCEDURE/VIEW parsing (#3867)
Co-authored-by: AIRAKSINEN Janne <janne.airaksinen@hexagon.com>
2022-09-24 16:31:19 -07:00
Yoichi NAKAYAMA
4313db20b1 MySQL: Support hexadecimal literals and bit value literals (#3869)
https://dev.mysql.com/doc/refman/8.0/en/hexadecimal-literals.html
https://dev.mysql.com/doc/refman/8.0/en/bit-value-literals.html
2022-09-24 15:54:48 -07:00
Yoichi NAKAYAMA
313d586d25 MySQL: Treat double quotes the same as single quotes (#3871)
To support concatenation of double quoted string literals
2022-09-24 14:14:07 -04:00
ragul balaji ravichandran
ecd404ba8d Snowflake: COMMIT WORK (#3862) 2022-09-22 11:38:16 -07:00
mp56
011644c94f Snowflake: AlterShareStatementSegment and CreateDatabaseFromShareStatementSegment (#3858) 2022-09-22 11:22:17 -07:00
William Felipe Welter
768e6f564a MySQL: Add CREATE/ALTER VIEW (#3859) 2022-09-22 10:58:11 -07:00
Greg Finley
264c4a6ec4 Redshift: CREATE TABLE LIKE enhancements (#3853) 2022-09-19 05:41:27 -04:00
j-svensmark
4010778ad1 L014 leading underscore capitalization inference fix (#3841)
* Added failing test

* Added loop to check if each character is capitalizable (i.e. is a letter)

* Move test to fixture

* Apply suggestions from code review

Fix linter warnings

* Update src/sqlfluff/rules/L010.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-09-13 19:11:56 -04:00
Yoichi NAKAYAMA
bcf8a76d6b MySQL: Add extended DROP TRIGGER functionality (#3846)
Fixes #3722

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-09-13 18:51:24 -04:00
olagjo
da66e36d27 Allow standalone aliases in L027 (#3848)
This is related to #356.
The previous fix of this issue (https://github.com/sqlfluff/sqlfluff/pull/722/files) ended up passing a parameter
to rule L027 for `value_table_function_aliases`, but not actually exempting these aliases from the rule.

It seems to me that the test case then passes because the result of the `unnest` function call is not counted as a table
reference, rather than passing because it is ok to use "unqualified" references for value tables (they are impossible
to qualify).

As such, I have added a new testcase `test_ignore_value_table_functions_when_counting_unqualified_aliases` which fails
on main, but passes with this fix.

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-09-13 16:58:54 -04:00
Barry Hart
bca4bfc1ab L042: Enable autofix for some tricky cases (#3700)
* L042: Enable autofix for some tricky cases

* Fixes "SELECT a" query!

* Update the two "avoid looping" tests now that they get fixed

* Preserve brackets, whitespace around extracted CTE

* Add automated test for SelectCrawler, fix an old bug I just discovered

* Don't try and create a CTE from an existing CTE

* Fix broken test

* Fix some tests, issues involving aliased subselects in JOIN clauses

* Implement 'forbid_subquery_in' config

* Update test case: Seems fixable now?

* Look in existing CTEs

* Detect and ignore correlated subqueries

* Move variable definition (potentially undefined variable)

* Add violations_after_fix

* Add fix_str and violations_after_fix

* Move test file to appropriate directory

* Fix SelectCrawler inconsistency ignoring from_expression_segment

* Fix another test, now 3 failing

Failures:
FAILED
test/rules/yaml_test_cases_test.py::test__rule_test_case[L042_with_fail]
FAILED
test/rules/yaml_test_cases_test.py::test__rule_test_case[L042_issue_3572_correlated_subquery_3]
FAILED
test/rules/yaml_test_cases_test.py::test__rule_test_case[L042_issue_3598_avoid_looping_2]
- AssertionError: assert 'WITH prep_1 ...* FROM cte1\n' == 'WITH temp
AS...* FROM cte1\n'

* Fix SelectCrawler bug handling nested CTEs

* Fix "Rules critical errors" failure

* Fix broken test

* Fix broken test

* Tidying

* Tidying

* Tidying

* Fix L028 issue introduced by SelectCrawler changes

* Tidying

* Remove type annotation that was triggering other mypy errors

* Fix infinite recursion issue

* PR review
2022-09-13 16:30:16 -04:00
Greg Finley
1000cf1bea Snowflake: CREATE FUNCTION IF NOT EXISTS (#3845) 2022-09-13 08:07:01 -04:00
Felix Möller
afec099966 ignore functions with more than one element ... (#3792)
* ignore functions with more than one element ...

* push

* fix space

* limit this to just functions

* fix linitng

* fix lint

* fix linting and adjust two test cases

* really fix now

* improve the comment

* Update src/sqlfluff/rules/L010.py

Co-authored-by: Barry Pollard <barrypollard@google.com>

* Update test/fixtures/rules/std_rule_cases/L030.yml

Co-authored-by: Barry Pollard <barrypollard@google.com>

* Update test/fixtures/rules/std_rule_cases/L030.yml

Co-authored-by: Barry Pollard <barrypollard@google.com>

Co-authored-by: Felix Moeller <felix.moeller@noventum.de>
Co-authored-by: Barry Pollard <barrypollard@google.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-09-12 18:13:19 -04:00
Yoichi NAKAYAMA
1ed4d84692 MySQL: support remaining constraint parts of CREATE/ALTER TABLE (#3827)
* MySQL: Implements remaining constraint parts of CREATE/ALTER TABLE

* add fixtures with check constraint

* Add more alter table queries

* Add queries with index_option in ALTER TABLE statements

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-09-10 09:13:46 -04:00
github-actions[bot]
69785ed983 Prep version 1.3.1 (#3839)
* Bump to version 1.3.1

* Add highlights to change log, fix a broken link in CONTRIBUTING.md

Co-authored-by: barrywhart <barrywhart@users.noreply.github.com>
Co-authored-by: Barry Hart <barry.hart@zoro.com>
2022-09-09 17:30:35 -04:00
James Taylor
b3dc494c8e Snowflake: Fix syntax errors in tests (#3834)
* Fix syntax errors in Snowflake tests

* Update yaml files based on syntax fixes

* Update hash for modified yaml files

* Update yaml file based on syntax fixes

* Update hash in yaml based on syntax fixes

* Update yaml based on syntax changes

* Update hash of yaml

* Fix hash again

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-09-09 15:31:34 +01:00
Barry Hart
a9c247bdf2 Add support for additional magic methods on DummyUndefined (#3835)
* Add .gitpod.yml

* Remove added file

* Add support for additional magic methods on DummyUndefined

Co-authored-by: Barry Hart <barry.hart@zoro.com>
2022-09-08 14:49:54 -04:00
Yoichi NAKAYAMA
2b2f58289d MySQL: support variable assignments by assignment operator := (#3829)
* MySQL: Support variable assignments

treat assignment operator as L006 target (also affects exasol, tsql)

* MySQL: support assignment in expression

* MySQL: the := assignment operator is also permitted in SET syntax

https://dev.mysql.com/doc/refman/8.0/en/set-variable.html

* MySQL: add fixture for variable assignments

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-09-06 08:30:46 -04:00
Matthew Dahlman
cf507e9242 improve lexing for single-quoted strings (#3831) 2022-09-06 08:13:06 -04:00
Yoichi NAKAYAMA
44b9a8990b MySQL: More support for index definition in CREATE TABLE (#3826)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-09-03 18:05:12 -04:00
Alan Cruickshank
dcfad3f9d2 Typed matching and ripping out the rest of .name (#3819)
* Fix L061

* unfix some of my fix

* Typed matchers and ansi dialect

* Athena dialect

* Bigquery, Mysql & linting

* Exasol

* Postgres, Snowflake and Linting

* hive

* SparkSQL and TSQL

* rip name out of core.parser

* Rip out most of the remaining name references

* Fix test fails

* Tests for unparsable expectations

* PR Feedback

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-09-03 11:28:24 +01:00
Juho Autio
01f31189ac sparksql dialect to support lambda expressions (#3821)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-09-02 16:05:29 -04:00
Alan Cruickshank
52008497bb Fixed broken main branch (#3825)
* PR feedback

* Oh now I understand
2022-09-02 19:11:32 +01:00
Alan Cruickshank
88ff21afe4 linting 2022-09-02 10:24:39 +01:00
Alan Cruickshank
1c9fb4d5b5 PR feedback 2022-09-02 10:20:36 +01:00
Calvin Hopkins
fda509a8e6 Merge branch 'main' into main 2022-08-31 09:23:39 -07:00
Calvin Hopkins
01f10c7cfc Fix windows error pathing for test 2022-08-31 09:18:35 -07:00
Niall Woodward
d74252c4c5 Take database and schema out of reserved keywords list (#3818) 2022-08-31 13:45:17 +01:00
Alan Cruickshank
3f1ec6e5cf Remove a chunk of name references (#3814)
* Remove a chunk of name references

* Fix L061

* unfix some of my fix

* Update src/sqlfluff/core/parser/segments/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-31 09:05:20 +01:00
Barry Hart
2b5296d1c0 Merge branch 'main' into main 2022-08-30 18:23:53 -04:00
Gal40n04ek
cd7506bad5 Fix typo in Snowflake dialect (#3813)
* fix typo

* add tests

Co-authored-by: Halyna Tsekhmistro <halyna.tsekhmistro@health-union.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-08-30 18:07:46 +01:00
Calvin Hopkins
38c9119843 Fix black errors 2022-08-30 08:22:03 -07:00
Calvin Hopkins
ef56c072e8 fix linting 2022-08-30 08:22:03 -07:00
Calvin Hopkins
7adf4115c7 fix test 2022-08-30 08:22:03 -07:00
Calvin Hopkins
d1bf2c5e11 Sort filenames 2022-08-30 08:22:03 -07:00
Calvin Hopkins
aa69d37206 Fix combine_dict call and updated test 2022-08-30 08:22:03 -07:00
Calvin Hopkins
be59793d76 Enable file name logging for multi-files for --show-lint-violations flag 2022-08-30 08:22:03 -07:00
Bas Beelen
6cfb2158e5 Allow the use of libraries in macro definitions (#3803)
* Allow the use of libraries in macro definitions

* Move library usage in macro test to separate test case
2022-08-30 09:24:08 -04:00
Alan Cruickshank
6687f9b685 Indentation fixes and rule logging improvements (#3808)
* Indentation fixes and rule logging improvements

* Update src/sqlfluff/core/rules/base.py

* coverage

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-30 08:00:40 +01:00
Barry Hart
dcc788d5aa Fixes a recursion error in JinjaTemplater handling of undefined values (#3809)
* Add .gitpod.yml

* Remove added file

* Fixes a recursion error in  JinjaTemplater handling of undefined values

Co-authored-by: Barry Hart <barry.hart@zoro.com>
2022-08-29 18:37:46 -04:00
Gal40n04ek
7feedcc201 Snowflake: extend GRANT syntax (#3807)
* extend grant syntax

* Empty-Commit

* move Grant Syntax for SF to SF dialect

* fix lint error

* remove redundant code

Co-authored-by: Halyna Tsekhmistro <halyna.tsekhmistro@health-union.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-08-29 23:16:07 +01:00
Gal40n04ek
36ad4e7a2b add warehouse_type (#3805)
Co-authored-by: Halyna Tsekhmistro <halyna.tsekhmistro@health-union.com>
2022-08-29 11:01:13 -04:00
Gal40n04ek
08baec5454 add Create Notification Integration syntax (#3801)
Co-authored-by: Halyna Tsekhmistro <halyna.tsekhmistro@health-union.com>
2022-08-28 18:23:05 -04:00
Felix Möller
c60d75a49c T-SQL: fix parsing partion by NULL (#3790)
Co-authored-by: Felix Moeller <felix.moeller@noventum.de>
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2022-08-27 21:42:32 -07:00
Lorin Dawson
d94724055c SparkSQL: Update L014 rule to not flag Delta Change Data Feed Session & Table Property (#3689)
* changes for enableChangeDataFeed Delta Tbl Property

* update yml files

* update typing

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-27 20:38:48 -04:00
James Taylor
275e78461e Snowflake: OVER (ORDER BY) clause required for first_value (fixes #3797) (#3798)
* Snowflake: OVER (ORDER BY) clause required for first_value (fixes #3797)

* Update corresponding YAML file

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-27 19:16:01 -04:00
Gal40n04ek
d45fcc66d2 add Alter Pipe syntax for snowflake dialect (#3796)
* add Alter Pipe syntax for snowflake dialect

* close code review comments

* close code review comment for Prefix

* regenerate alter pipe fixture

Co-authored-by: Halyna Tsekhmistro <halyna.tsekhmistro@health-union.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-27 18:58:11 -04:00
Yoichi NAKAYAMA
4d05e0caa8 BigQuery: Parse WEEK(<WEEKDAY>) in date_part (#3787)
* BigQuery: Parse WEEK(<WEEKDAY>) in date_part

* Fixed the test by replacing invalid queries with valid queries

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-27 08:45:15 -04:00
Christopher Eck
441c3ee764 Postgres: Support setting user properties using intrinsic ON & OFF values 2022-08-26 21:06:00 -07:00
Gal40n04ek
4673753239 extend SF dialect for File Format statements (#3774)
* extend SF dialect for File Format statements

* close code review comments

* refactoring

* fix lint error and refactoring code

Co-authored-by: Halyna Tsekhmistro <halyna.tsekhmistro@health-union.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-26 09:38:02 -04:00
Thijs
32fd552733 Add QUALIFY to SparkSQL dialect (#3778)
* add qualify segment to sparksql dialect

* run black

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-26 08:19:40 -04:00
Gal40n04ek
cb6d7b96d4 fix regex for S3Path (#3782)
Co-authored-by: Halyna Tsekhmistro <halyna.tsekhmistro@health-union.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-26 06:54:10 -04:00
Gal40n04ek
e60a2a45e5 add Optional parameter ERROR INTEGRATION for PIPE (#3785)
Co-authored-by: Halyna Tsekhmistro <halyna.tsekhmistro@health-union.com>
2022-08-25 20:18:18 -04:00
Alan Cruickshank
568e698cdc Add a file size check in bytes (#3770)
* Add a file size check in bytes

* extend the test to get better coverage

* Update src/sqlfluff/core/templaters/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/core/templaters/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-23 13:40:22 +01:00
Alan Cruickshank
4f3ceb9087 Require importlib_metadata >=1.0.0 (#3769) 2022-08-22 09:48:10 -04:00
github-actions[bot]
e3cc251a68 Prep version 1.3.0 (#3768)
* Bump to version 1.3.0

* Update changelog

* typo

* add additional highlights

* typo

* Update Changelog

Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan Cruickshank <alan@designingoverload.com>
2022-08-21 14:33:54 -04:00
Greg Finley
6e22a91c61 T-SQL: ALTER TABLE DROP COLUMN (#3749)
* T-SQL: ALTER TABLE DROP COLUMN

* if exists

* Just 'column'

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-21 11:50:36 -04:00
Barry Hart
4928dc1321 Add "# pragma: no cover" to work around sporadic, spurious coverage failure (#3767)
* Add .gitpod.yml

* Add "# pragma: no cover" to work around sporadic, spurious coverage failure

* Remove added file

Co-authored-by: Barry Hart <barry.hart@zoro.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-08-21 15:35:30 +01:00
Alan Cruickshank
3033d9baf8 Add end_of_file and template_loop markers (#3766)
* End of File and Loop markers

* better logging

* linting

* Fix failing L003 tests

* linting

* LoopJump - TemplateLoop

* more explanation

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-21 15:34:42 +01:00
sirlark
a0eacabe8e Provide usage examples for new users (#3765)
Adds usage examples to the main -h output covering the use and placement
of the `--dialect`, `--rules`, and `--templater` options.

Also amends the error output when a required `--dialect` option is
absent to explain how to specify a dialect on the command line.

Co-authored-by: James Dominy <james.dominy@wpengine.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-21 09:31:22 -04:00
Ross
ef573f94fa SQLite: deferrable in create table statement (#3757)
* add deferrable to create statement

* change to use ColumnConstraintSegment

* add TableConstraintSegment

* use copy/insert solution

Co-authored-by: Raira Okuno <rairaokuno@RairanoMacBook-Pro.local>
2022-08-21 09:07:10 -04:00
Barry Hart
8352979d73 When ignore=templating and fix_even_unparsable=True, provide defaults for missing vars (#3753)
* Add .gitpod.yml

* When ignore=templating and fix_even_unparsable=True, provide defaults for missing vars

* Remove accidentally added file

* PR review, add magic methods

* Tweak

* Comments

* Add comment

* Handle missing macro files

* Handle UndefinedError, add logging

* Fix broken tests

* Tweak

* Tweaks

* Fix broken tests by splitting Undefined into two distinct classes

* Fix broken test

* Address missing coverage, remove some code that reports undefined vars when ignore=templating

* Remove unused function, avoid infinite recursion

* Add "no cover" to some unrelated code

* Move & improve comment

* Unary plus and minus

* Fix some issues, correctly handle use of Jinja default() filter

* Treat missing or undefined templates as their names

* Update src/sqlfluff/core/config.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Add documentation on the new behavior

* Fix some doc markdown / punctuation issues

Co-authored-by: Barry Hart <barry.hart@zoro.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-08-20 08:39:27 -04:00
Yoichi NAKAYAMA
eade007be1 BigQuery: Support Materialized Views (#3759)
https://cloud.google.com/bigquery/docs/materialized-views-intro
2022-08-18 14:10:10 +01:00
Barry Pollard
f67509b775 Enhance L062 to ignore blocked words in comments (#3754) 2022-08-17 18:00:19 +01:00
Barry Hart
b720f9816e Fix bug where undefined Jinja variable in macro file crashes linter (#3751)
Co-authored-by: Barry Hart <barry.hart@zoro.com>
2022-08-16 15:56:50 -04:00
Alan Cruickshank
d43e6c997d Migrate analysis, functional and testing to utils (#3743)
* Migrate testing module to utils

* Migrate analysis

* Move the functional utils

* linting and mypy

* use explicit function for issuperset

* linting
2022-08-15 17:29:35 +01:00
Alan Cruickshank
0feb87043c Build out rule crawling mechanisms (#3717)
* Add child type set property

* Seperate rule context out into new module

* Basic crawlers and simple RootCrawler case

* Seeker Crawler

* Implement crawlers in 65 & 66

* 61, 61 & 64 to new crawlers

* Add pass filter to Segment Crawler

* Implement raw stack and some of the rules which use it.

* fix issue with L004

...and linting

* coverage

* Update src/sqlfluff/rules/L060.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/core/parser/segments/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/core/rules/crawlers.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/core/rules/crawlers.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* switch to abstract base class

* Add crawl behaviour for a bunch of easier rules

* More rule fixes

* Big simplification of L039

+ Don't duplicate the work of L001

* Bring in L006 and dependents

* Bring in L010 and dependents [except L063]

* increase logging level for failing test

* Don't set crawl behaviour for L063 - not ready yet

* migrate L026

* mypy

* bring in rule L007

* Refactor L010 and L063 to allow new structure.

* fix L063

* metaclass goodness

* linting, coverage and test fixes.

* migrate rule L052

* PR feedback

* Migrate L053

* Move trigger segment of L052

* Migrate L046

* Migrate L008

* Migrate L019

* coverage

* Migrate the last rules

* Strip out old CrawlBehaviour

* remove raw_segment_pre

* update example & test rules

* PR edits

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Update src/sqlfluff/core/parser/segments/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Update test/core/parser/segments_base_test.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Update src/sqlfluff/rules/L053.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Update src/sqlfluff/core/rules/context.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Update src/sqlfluff/core/rules/context.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Update src/sqlfluff/core/rules/crawlers.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Update src/sqlfluff/rules/L010.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* PR Feedback

* linting

* nope - revent change to L052

* Update src/sqlfluff/rules/L039.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-15 09:09:42 +01:00
Ross
40f3d81e6b Add current_timestamp to Redshift as a bare function (#3741)
* redshift: add current_timestamp to bare function

* change test query order

Co-authored-by: Raira Okuno <rairaokuno@RairanoMacBook-Pro.local>
2022-08-15 07:25:23 +01:00
Yoichi NAKAYAMA
bc147334a8 BigQuery: Fix parsing parameterized data types (#3735)
* BigQuery: Fix parsing parameterized data types

* Replace the type in a comment with a supported one

* Make the param[, ...] part more specific

* Extend DatatypeSegment to support parameterized data types

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-14 10:02:00 -04:00
keyem4251
39dc2d8981 Change MySQL Create Statement Equals Segment to Optional (#3730)
* Change MySQL Create EqualsSegment to Optional (#3664)

* Add test sql and yaml file (#3664)

* Generat yaml file (#3664)
2022-08-12 22:21:26 +01:00
Gergely Imreh
6faf5f7f11 SQLite: add parsing of INSERT statement (#3734)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-12 10:07:08 -04:00
Lorin Dawson
abb4f75fcb SPARKSQL: Support Delta Lake Drop Column Clause in ALTER TABLE (#3727)
* Updates to support dropping column metadata

* update yaml

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-12 09:42:14 -04:00
Alan Cruickshank
2a691a7d7c Add short options for several cli commands. (#3732) 2022-08-11 16:42:37 +01:00
Alan Cruickshank
ca3f509d2e Build out type hints in Grammars (#3718)
* Switch to matchable types

* more type hints

* Tighten type hints

* unquote matchable type

* clarify comment

* PR feedback improvements

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-09 14:38:38 -04:00
Edgar R. M
38dd4b9c69 dbt 1.3.0 compatibility (#3708)
* Test against dbt-core 1.3

* Add check for dbt>=1.3

* Use the correct dbt_utils fixture

* Install dbt-postgres 1.3.0 prereleases

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-08-09 07:20:18 -04:00
Alan Cruickshank
b4c56d7acd Revise no cover direction and remove unused code. (#3723)
* Remove unnecessary exception clause and test no cover removal.

* better coverage signaling
2022-08-08 20:23:06 +01:00
Alan Cruickshank
e1cfb472ea update flattr link (#3720) 2022-08-08 13:28:51 +01:00
Sabri Karagonen
49b4ac4d05 BigQuery: remove key from unreserved keywords list (#3719)
* bigquery reset primary and foreign keys

* bq remove key from unreserved keywords

* bq remove key from unreserved keywords

Co-authored-by: Sabri Karagonen <sabri.karagonen@trendyol.com>
2022-08-07 23:54:36 +01:00
Sabri Karagonen
f687e82b1d bigquery reset primary and foreign keys (#3714)
Co-authored-by: Sabri Karagonen <sabri.karagonen@trendyol.com>
2022-08-07 12:45:36 +01:00
Alan Cruickshank
6c8d2ab0c5 Name Deprecation (Part 1) (#3701)
* Remove name from bracket matching

... and adjust L053

* Remove some symbol names

* Adjust failing rules

* Generalise a few more segments

* Update dialect fixtures

* fix the api example

* Handle some more dialects

* More dialect changes

* more rule and dialect fixes

* update dialect yamls

* More dialect literals and identifiers

* linting

* fix L054

* update yamls

* Fix a bunch of rules

* Fix L034 and L049

* Fixes for L026

* More rule fixes

* Fix Merge

* Strip out name kwargs and fix test fixtures.

strip out some more names

Strip a LOT more names

linting

* Fix typo

* Fix yaml

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-08-05 10:01:49 +01:00
Greg Finley
282e675c7b Teradata: Add two TdTableConstraints (#3690) 2022-08-04 14:55:49 -04:00
Gordon Ball
2035e9c7f9 Redshift: support expressions in array accessors (#3706)
* dialects: redshift: support expressions in array accessors, remove unsupported postgres array syntax

* tests: redshift: test expressions in array accessors
2022-08-02 09:27:44 -07:00
Alan Cruickshank
e5457ddb78 Attempt to handle logging issues at teardown (#3703)
* Add logging teardown fixture

* Apply fixture using autouse
2022-08-01 22:01:33 +01:00
Barry Hart
213dd62198 L028, L032: Fix bug where fixes were copying templated table names (#3699)
* L028, L032: Fix bug where fixes were copying templated table names

* Fix unrelated Black formatting issue

* Fix crash when source is None

* PR review: add new test case
2022-07-31 14:10:41 -04:00
Barry Hart
7f0180e300 L042: Autofix sometimes results in "fix looping", hitting the linter "loop limit" (#3697)
* L042: Do not flag or fix correlated subqueries

* Add "# pragma: no cover" for missed coverage

* Remove unnecessary old code

* Fix issue 3598, where L042 can "fix loop" forever

* Fix unrelated Python linting error

* Add missing rule config for new test cases

* For issue 3598, flag but do not attempt to fix
2022-07-31 12:02:11 -04:00
Barry Hart
3a165f5c96 L042: Address corner cases where fix corrupts the SQL (#3694)
* L042: Handle when there's no space between "FROM" and the subquery

* Fix issue 3617: Parentheses around CTAS SELECT

* Remove blank line
2022-07-30 08:06:08 -04:00
Oliver Borchert
1a7a5620c1 T-SQL: Properly parse collation names (#3686)
* Properly parse collations

* Remove database_default as keyword
2022-07-28 20:38:36 -07:00
Peter Debelak
7cd64c755a Allow escaping single quotes in single-quoted literal with '' (#3682) 2022-07-27 22:11:37 +01:00
Oliver Borchert
5249e3f45d T-SQL: Fix indentation after JOIN/APPLY clauses with no ON statement (#3684)
* Add changes

* Add tests

* Remove yml file

* Apply suggestions from code review

Co-authored-by: Barry Pollard <barrypollard@google.com>

Co-authored-by: Barry Pollard <barrypollard@google.com>
2022-07-27 21:34:31 +01:00
Oliver Borchert
3030af725c T-SQL: Parse DATEPART date type as date type instead of column name (#3681)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-27 09:19:45 -07:00
Oliver Borchert
7a40bf6e4d Allow COLLATE clause in JOIN conditions for T-SQL dialect (#3680)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2022-07-27 14:56:59 +01:00
Oliver Borchert
ae4c1bd9fc T-SQL: Fix parsing of CREATE VIEW statements with column name syntax (#3669)
* Apply suggested changes

* Add test case
2022-07-26 21:04:30 -07:00
Alan Cruickshank
f9d76a15f9 Fix typo in github issue template (#3674)
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2022-07-26 09:07:25 -07:00
Greg Finley
803dc09204 Add Athena issue label (#3676) 2022-07-26 08:45:13 -07:00
Greg Finley
2292816bfb Set issue dialect labels via Github Actions (#3666) 2022-07-25 20:57:08 +01:00
Alan Cruickshank
39c3fe6205 Allow configuration of processes from config (#3662)
* Allow configuration of processes from config

* linting

* mypy update

* Allow zero to mean all cpus

* Update doc notes.

* test coverage for proces logic

* test the 1 cpu case

* linting

* no cover for process formatting
2022-07-25 12:20:36 +01:00
Alan Cruickshank
f9a3fe8f63 Reposition before recursion in fixes to avoid internal error (#3658)
* Add intermediate reposition and test

* mypy fix

* tidy up the failing dbt test

* Use UUIDs for matching

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-25 10:08:03 +01:00
Alan Cruickshank
1977bc938b Use UUIDs for matching (#3661)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-25 09:02:52 +01:00
Danny Jones
764c1f1540 Postgres: Add dialect-specific bare functions (#3660) 2022-07-24 22:12:21 +01:00
Danny Jones
ed53c4ebb9 Postgres: Add CALL Support (#3659)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-24 17:32:38 +01:00
Danny Jones
badb1d40f6 ANSI - Add support for INTERSECT ALL and EXCEPT ALL (#3657)
* ANSI - Add support for INTERSECT ALL and EXCEPT ALL

* Linting

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-24 09:03:19 -04:00
Chaim Turkel
eb713343dd Option to show errors on fix (#3610)
* option to show errors on fix

* option to show errors on fix

* Update src/sqlfluff/cli/commands.py

* Update test/cli/commands_test.py

* fix flake issues

* change _ to -

* fix tests

* fix tests

* Fix line length lint error

* Fix Black errors

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-23 16:32:55 -04:00
Barry Hart
2af56f8c95 L042: Fix internal error "Attempted to make a parent marker from multiple files" (#3655) 2022-07-23 13:59:34 -04:00
Barry Hart
9986aaf120 L026: Add support for merge_statement (#3654)
* L026: Add support for merge_statement

* Alphabetical order

* Improve comment

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-23 11:23:06 -04:00
Peter Debelak
db168f5900 Add handling for redshift convert function data type argument (#3653)
Fixes issue #3651.

Previously, the first argument to the `convert` redshift function was
interpreted as a column reference rather than a data type. This could
cause rule L027 to fail since the data type wasn't qualified with a
table name even though that doesn't make sense. This adds explicit
handling for `convert` to eliminate that issue.
2022-07-23 15:49:29 +01:00
Alan Cruickshank
8e4f29e956 Deduplicate files before and during templating (#3629)
* Deduplicate in linter

* Deduplicate in templater

* Linting

* add more logging

* linting

* coverage

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-23 11:41:42 +01:00
Alan Cruickshank
011e195b19 Rationalise Rule Imports (#3631)
* Move rule docs generation

* Simplify imports from .base

* fix missing import

* actually fix import

* linting duplicate imports from merge

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-22 17:33:28 +01:00
Barry Hart
6e45836c15 Handle Jinja {% call ... %} blocks (#3648)
* Handle Jinja {% call ... %} blocks

* Update docstring

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-07-22 07:01:51 -04:00
Lorin Dawson
e56fc6002d SPARKSQL: Add Delta Lake Constraints syntax to ALTER TABLE (#3643)
* fix  in AlterTableStatementSegment

* add delta contraints to AlterTableStatementSegment

* black & yml files

* add link to Delta docs

* replace Anything with ExpressionSegment
2022-07-21 17:51:15 +01:00
Gordon Ball
620aa572b2 Redshift: syntax for array unnesting with index (#3646)
* dialects: redshift: support array unnesting with index

* tests: redshift: add array unnesting with index
2022-07-21 13:02:46 +01:00
Chris Alexeev
26749821b7 Snowflake - ALTER TABLE IF EXISTS and WHEN SYSTEM$STREAM_HAS_DATA() (#3641)
* alter table tests

* added some atler table alter column stuff

* more explicit regex
2022-07-21 08:57:20 +01:00
Barry Hart
ac852a202e L057: In BigQuery, allow hyphens by default (#3645)
* L057: In BigQuery, allow hyphens by default

* Allow hyphens in BigQuery

* Add test case as suggested in PR review

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-07-20 19:02:38 -04:00
Peter Debelak
2c59a9367b Better messages for partial indentation in L003 (#3634)
* Better messages for partial indentation in L003

* Calculate has_partial_indent in L003 once

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-20 16:37:15 -04:00
ciwassano
e4d237378d Add "INTEGER" to PrimitiveTypeSegment for Sparksql (#3624)
* Add "INTEGER" to PrimitiveTypeSegment for Sparksql

Issue: #3554

* add sql test

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-20 21:03:48 +01:00
Greg Finley
d18a92dee9 Bump version in gettingstarted.rst via the release script (#3642)
* change the script

* Run script

* consistent whitespace
2022-07-20 20:26:20 +01:00
Barry Hart
4f11ca4b1b Improve handling of BigQuery hyphenated table names (#3638)
* BigQuery: Better support hyphened projects

* Improve handling of BigQuery hyphenated table names

* Rework iter_raw_references()

* Add missing .yml file

* Remove redundant .sql and .yml files

* Add a test for BigQuery iter_raw_references()

* Revert "Remove redundant .sql and .yml files"

This reverts commit 1252d41f09.

* Remove my test files, since we have the ones from the original PR

* Refactor/simplify iter_raw_references()

Co-authored-by: Greg Finley <gregory.finley@gmail.com>
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-07-20 13:31:46 -04:00
keyem4251
c25b7cf05f update sqlfluff version in gettingstareted.rst (#3639) 2022-07-20 13:07:02 -04:00
Barry Hart
645c63b5b5 L016: Ignore jinja comments if ignore_comment_clauses=True (#3637)
* L016: Ignore jinja comments if ignore_comment_clauses=True

* More specific "type: ignore"

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-07-19 19:37:56 -04:00
Alan Cruickshank
655cc7f146 Add errors for redundant definitions. (#3626)
* Add errors for redundant definitions.

* appease mypy
2022-07-18 12:41:49 +01:00
Alan Cruickshank
6b31de49eb Object Literals (#3620)
* Modify .simple() to track loops in grammars

* sort dependencies of BaseExpressionElementGrammar

* rationalise literals in ansi

* knockon changes in athena

* bigquery implications

* hive knockon

* postgres knockon

* simplify tsql dependency

* odd change to teradata?

* make the object literal segment less flat.

* mypy

* re-add datatypes in Expression D

* readjust expression

* Dialect Crumbs

* More mypy

* Revert one of the changes with better comment

* update yamls

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-17 11:09:53 +01:00
Alan Cruickshank
d83ab36bbb Dialect Crumbs (#3625)
* Dialect Crumbs

* More mypy

* Update src/sqlfluff/core/parser/grammar/base.py

* Update src/sqlfluff/core/parser/grammar/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-17 00:05:09 +01:00
Alan Cruickshank
86b0b446b5 Consistent return codes (#3608)
* Consistent return codes

* linting

* adjust roundtrip testing

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-16 09:12:09 +01:00
github-actions[bot]
d783e421b7 Prep version 1.2.1 (#3621)
* Bump to version 1.2.1

* get tox to work right

* Update highlights

Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan <alanmcruickshank@gmail.com>
2022-07-16 00:35:58 +01:00
Greg Finley
182ff0fe64 Pin sqlfluff-templater-dbt via release script (#3613)
* Change to ==

* update the script

* Run the script

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-07-15 15:18:42 +01:00
Alan Cruickshank
d09ac71a78 Specifying comma delimited is unnecessary (#3616)
* Specifying comma delimited is unnecessary

* black
2022-07-15 13:14:01 +01:00
Peter Debelak
1de718913b Handle redshift temporary tables with # at the beginning of name (#3615)
See [redshift
docs](https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html)
about these temporary table names. This adds the ability to parse them
and makes sure that rule L057 doesn't complain about them.
2022-07-15 10:25:11 +01:00
github-actions[bot]
d376f23d72 Prep version 1.2.0 (#3605)
* Bump to version 1.2.0

* Add highlights

* Update CHANGELOG.md

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update CHANGELOG.md

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update CHANGELOG.md

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan <alanmcruickshank@gmail.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-13 22:37:11 +01:00
Aditya
b64724115a Improve documentation for custom implemented rules (#3604)
* Updated developingplugins.rst Added plugin support

Added support for custom implemented rules

* Update developingplugins.rst

-added comma
-added line space

* Update docs/source/developingplugins.rst

* Linting fixes

Co-authored-by: Barry Pollard <barrypollard@google.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-13 19:24:02 +01:00
Alan Cruickshank
cfded298d8 Add a skip and better logging for fatal dbt issues (#3603)
* Add a skip and better logging for fatal dbt issues

* Even more logging

* black
2022-07-13 17:29:52 +01:00
Alan Cruickshank
32687ca720 Add large file check (#3600)
* Add large file check

* Change to decorator

* Fix test cases
2022-07-13 11:15:15 +01:00
David Fuhr
4c9ea0f99a Oracle: extend support for ALTER TABLE (#3596)
* Add RENAME COLUMN syntax for oracle

Fixes #3594

* Add ADD CONSTRAINT syntax for oracle

Fixes #3593

* Add DROP COLUMN syntax for oracle

* Add DROP CONSTRAINT syntax for oracle

* Add ADD/MODIFY COLUMN syntax for oracle

* Linting fixes

* Update src/sqlfluff/dialects/dialect_oracle.py

* Update src/sqlfluff/dialects/dialect_oracle.py

* Lint damn you lint!

Co-authored-by: Barry Pollard <barrypollard@google.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-12 10:20:27 +01:00
Alan Cruickshank
88aeb109af Immutability fixes (#3428)
* Grammar to Segment

* Copy the original segment in Bracketed and position segments

* Update src/sqlfluff/dialects/dialect_ansi.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/core/parser/segments/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Fix the things which broke on merge

* revert more changes

* unparsable cte test

* add parsed case from clickhouse

* try removing other workarounds 1

* simplify grammars

* remove more workarounds

* Remove more workarounds

* linting

* appease mypy

* Update yaml cases

* Update test/fixtures/dialects/clickhouse/cte_columns.sql

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/core/parser/segments/base.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* remove unnecessary comment

* coverage

* typing for _position_segments

* add warning on nested ephemerals

* demonstrate cte bug fixed

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-12 09:26:01 +01:00
Alan Cruickshank
cab754edbb Struct type should be a segment (#3591)
* Struct type should be a segment

* linting
2022-07-11 14:51:00 +01:00
Alan Cruickshank
f49122d26d Fix Bracketed Struct issue (#3590)
* Fix Bracketed Struct issue

* Handle knock-on effects in dialects

* appease mypy
2022-07-11 13:23:00 +01:00
Barry Pollard
dabb95a66e Allow spaces and multiple signs for numeric literals (#3581)
* Allow spaces and multiple signs for numeric literals

* Review feedback

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-11 12:00:15 +01:00
Alan Cruickshank
763d23e70e Add source fixing capability and fix routines for L046 (#3578)
* Simplify lint fixing (prep for source fixes)

* Split apart fix_string into smaller functions

* linting

* Bring back in some checks which *are*used

* linting

* Add some no cover elements

* linting

* fix incorrect references

* linting

* Fixing test harness

* More complicated tests

* Mechanics and tests for source fixes

* Add test cases and get most to pass.

* Source fixes - working for rule test cases

* linting

* coverage

* mypy fixes

* Update src/sqlfluff/core/parser/segments/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/core/parser/segments/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/core/parser/segments/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/core/parser/segments/raw.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* More comments and test an empty tag fix

* Linting

* test fixes

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-11 09:42:20 +01:00
Ian Robertson
c2f530ccab Small tweaks to grammar in team rollout doc (#3584)
Co-authored-by: Ian Robertson <ian@Ians-MacBook-Pro.local>
2022-07-10 19:12:44 -04:00
Greg Finley
e365dcc1b0 Postgres: CREATE COLLATION (#3571)
* collate in table column

* Create collation

* delimited implies optional I guess

* Add note

* remove more optionals

* better tests

* Smush into a single test using UNIQUE instead of PK

* More tests

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-10 21:06:19 +01:00
Peter Debelak
ec9af41c4f Add TOP to select clause modifiers for redshift dialect (#3582)
Fixes #3531
2022-07-10 15:01:30 +01:00
Greg Finley
dc22a21c01 Postgres: Small fixes to COMMENT ON (#3566)
* Postgres: Small fixes to COMMENT ON

* Update src/sqlfluff/dialects/dialect_postgres.py

* Update src/sqlfluff/dialects/dialect_postgres.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-10 09:16:27 +01:00
Quentin Gallet
faa1c83941 Support MySQL system variables (#3576)
* Modify at_sign lexer and add parser to handle MyQL system variables + provide fixtures for validation.

* Improve at_sign lexer.
$ sign is now supported, and a `.` cannot be at the start/end of a variable name.

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-09 20:50:18 -04:00
Peter Debelak
50f0638fa9 Allow no alias for selects in CTEs with a column list (#3580)
In cases where the CTE has a column list, we don't need an alias for
columns. This checks if the select has a `common_table_expression`
parent and if that parent has a `cte_column_list` child. In that case,
it doesn't complain about a missing alias.

Fixes #3558
2022-07-09 16:57:15 -04:00
cmotta
ac8dd5f45c New dialect AWS Athena (#3551)
* Athena: Add new dialect

* addressed issues pointed by barrywhart

* removed comments

* ending all queries with semicolon

* sorted keyword lists ascending

* added athena to supported dialects

* updated yaml files after adding missing semicolon
2022-07-08 19:22:41 +02:00
Alan Cruickshank
2551fc0c53 Split apart fix_string(). (#3568)
* Simplify lint fixing (prep for source fixes)

* Split apart fix_string into smaller functions

* linting

* Bring back in some checks which *are*used

* linting

* Add some no cover elements

* linting

* fix incorrect references

* linting
2022-07-08 09:53:41 +01:00
Peter Debelak
528bc0b520 Fix incorrect L022 with postgres dialect with CTE argument list (#3570)
This fixes #3569 where rule L022 wants to put a new line after the
closing parenthesis of the CTE argument list. It seems like the
postgres dialect needed to be updated to match the ansi one as part of
2022-07-07 17:00:53 -04:00
Alan Cruickshank
f6b65825f4 Simplify lint fixing (prep for source fixes) (#3567)
* Simplify lint fixing (prep for source fixes)

* linting

* Bring back in some checks which *are*used

* Add some no cover elements

* linting
2022-07-07 16:20:46 +01:00
zidder
bbdf12ceb0 Exclude .coverage.py from linting (#3564) 2022-07-06 19:59:45 -04:00
Barry Hart
b1a13a5d58 L016: ignore_comment_clauses not working for postgres dialect (#3549)
* L016: ignore_comment_clauses not working for postgres dialect

* Regenerate Postgres YAML files after dialect change

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-07-06 15:21:15 -04:00
Alan Cruickshank
a540ca1e63 Groundwork for a fix routine for L046 (#3552)
* Rework L046 ready for the fix routines

* linting

* shorten long lines

* mypy fixes

* Revert many changes (I now understand)

* correct the type selectors for L046

* revert memory changes

* Add doctests and CI

* linting
2022-07-04 17:47:25 +01:00
Alan Cruickshank
e9d439ac3b Add better handling for SQLFluffUserError when running core cli commands (#3431)
* Add better handling for SQLFluffUserError when running core cli commands

* Update to context manager

* revert kwargs back to args where args were before

* Add tests
2022-07-03 20:58:01 +01:00
github-actions[bot]
f6492fe8aa Prep version 1.1.0 (#3541)
* Bump to version 1.1.0

* Add Highlights

* Update CHANGELOG.md

Added notes for PRs #3536 and #3540

* Update CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: tunetheweb <tunetheweb@users.noreply.github.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-03 13:19:29 -04:00
Barry Hart
b66071c9ff L025: Derived query requires alias -- also handle UNION, etc. (#3548)
* L025: Derived query requires alias -- also handle UNION, etc.

* Handle WITH statements

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-07-03 13:01:24 -04:00
Barry Hart
fe8b93e9eb L025 should not remove aliases from derived queries (#3546)
* L025 should not remove aliases from derived queries

* Add back removed test case, now as pass rather than fail

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-07-02 20:46:49 -04:00
Barry Pollard
565c3e6964 T-SQL keyword functions should be treated as keywords (#3540)
* T-sql keyword functions should be treated as keywords

* Fix CONVERT function

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-07-02 14:46:21 +01:00
Barry Hart
29f1657ad0 Fix issue where "--nocolor" is ignored (#3536)
* Fix issue where "--nocolor" is ignored

* Fix broken tests

* Fix broken tests

* Fix coverage issue by reusing (not copying) code

* Add a test for the specific issue reported by the user

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-07-02 09:29:39 -04:00
Thomas
e42f60cda1 Clickhouse: allow FINAL modifier (#3534)
* allow final modifier in clickhouse dialect

* Update src/sqlfluff/dialects/dialect_clickhouse.py

Co-authored-by: Barry Pollard <barrypollard@google.com>

* Update test/fixtures/dialects/clickhouse/final.sql

Co-authored-by: Barry Pollard <barrypollard@google.com>

Co-authored-by: Barry Pollard <barrypollard@google.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-01 23:12:07 +01:00
zidder
153c438e5a Add a new configuration for L018 to ignore indentations (#3499)
* Add a new configuration for L018 to ignore indentations

* Fix lint error

* Fix mypy problem

* Change the meaning of L018 to check only newline, not indentation

* Add combo tests

* Fix tests according to comments
2022-07-01 22:35:32 +01:00
Lorin Dawson
f447a604df SparkSQL: Update terminator grammar for HAVING, WHERE, GROUP BY (#3526)
* update terminator grammar for preceding clauses

* test case for 3484

* updates for adding GroupByClauseTerminatorGrammar

* update terminator for match_grammar in ansi

* updates for adding HavingClauseTerminatorGrammar
2022-07-01 21:46:39 +01:00
Barry Hart
81f75dc28e Fix L025 false positive for tsql VALUES clause (#3533)
* Fix L025 false positive for tsql VALUES clause

* Tidying

* Rename variable -- old name was wrong

* Add "no cover"

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-07-01 14:45:28 -04:00
Ryan Kelly
3d278bce7a New rule L066 for enforcing table alias lengths (#3384)
* create rule for enforcing table alias lengths

* Apply suggestions from code review

* Linting fixes

* Linting fixes

* Linting

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry <barry@tunetheweb.com>
Co-authored-by: Barry Pollard <barrypollard@google.com>
2022-07-01 08:05:26 +01:00
Greg Finley
f5b05bd19d Redshift: CALL statement (#3529)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-01 00:45:55 +01:00
Judah Rand
8f65c3082d Compile regexes at init time to avoid overhead (#3511)
This means that the regexes are only compiled once rather than everytime
a `RegexParser` is evaluated.

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-07-01 00:17:39 +01:00
Barry Pollard
f4f230dbb0 Disable L059 by default for Postgres (#3528)
* Disable L059 by default for Postgres

* Update src/sqlfluff/rules/L059.py

Co-authored-by: Greg Finley <gregory.finley@gmail.com>

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Greg Finley <gregory.finley@gmail.com>
2022-06-30 23:59:37 +01:00
Judah Rand
911774d809 Core: Add MultiStringParser to match a collection of strings (#3510)
* Add `MultiStringParser` to match a set of strings

This parser takes a collection of strings and returns a match if any of
them are found. This is more performant than implementing this through
the `RegexParser` as a hash matching route can be taken.

* Perform `.upper()` in `__init__`

* Check `is_code` first for performance

* Use `super` to initialize object

* Add `MultiStringParser` simple test

* Implement `BaseParser` abstract class

* Avoid calling `.upper()` when matching

* Avoid `list` creation at every `simple` call

* Remove more `RegexParser`s

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-30 18:27:44 -04:00
Greg Finley
ba6050845d SQLite: PRIMARY KEY AUTOINCREMENT (#3527) 2022-06-30 22:09:49 +01:00
Greg Finley
e81993fa9a MySQL: Support LOAD DATA (#3518)
* MySQL: Support LOAD DATA

* code golf

* Revert "code golf"

This reverts commit 2c39e4256d.
You could have both things

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-29 19:15:31 -04:00
Greg Finley
9eb3e29121 Redshift: GRANT EXECUTE ON PROCEDURES (#3516)
* Redshift: GRANT EXECUTE ON PROCEDURES

* replace

* Make a proper override

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-29 23:12:30 +01:00
Matt Menzenski
70dcc424d4 Allow DEFAULT expression in Redshift ALTER TABLE ADD COLUMN statements (#3513)
* add alter table add column statements

* Allow default expression in a redshift alter table add column statement
2022-06-29 22:18:55 +01:00
Judah Rand
147f4b41ac BigQuery: Fix parsing of Array creation from full subquery (#3502)
* Add segment to handle Bigquery Arrays creation

Add the `TypelessArraySegment` to handle BigQuery array creation from a
full subquery as specified here:
https://cloud.google.com/bigquery/docs/reference/standard-sql/array_functions#array

This differs from normal functions as it accepts a full subquery.

* Fix linting errors
2022-06-28 21:26:36 +01:00
Lorin Dawson
7d9717dbec SparkSQL: Allow dateparts as table aliases (#3500)
* remvoe DateTimeUnitSegment ref from AliasExpressionSegment

* sqlfluff fix literals.sql and refresh yml
2022-06-27 19:56:36 +01:00
Emiliano Mancuso
f823a9cee8 Fix load_macros_from_path to actually support multiple paths (#3488)
* Move dictionary definition outside the `for`

The definition of `macro_ctx` inside the `for` loop basically kills the feature of "comma-separated list of `.sql` or folders" (see [docs](https://docs.sqlfluff.com/en/stable/configuration.html))

If a folder has multiple entries, only the last one will prevail because the `macro_ctx = {}` is being executed.

Also, the `return` value of the function is a variable defined in an inner scope, which is not a good practice.

* Add missing tests

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-06-25 09:17:49 -04:00
Barry Hart
cfa562b0ef Allow linter to apply fixes spanning more than 2 slices (#3492)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-06-24 17:42:06 -04:00
Barry Hart
6e908c82a0 Fix L022 false positive when the CTE definition has a column list (#3490)
* Fix L022 false positive when the CTE definition has a column list

* Regenerate YML files

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-06-24 11:42:26 -04:00
Lorin Dawson
9a1246a83c support for restore statement (#3486) 2022-06-23 20:51:07 +01:00
hgranthorner
b24779b1ce add values function (#3483) 2022-06-23 00:40:23 +01:00
Lorin Dawson
2b71b6fe7c SparkSQL: Support for CONVERT TO DELTA command (#3482)
* convert to delta command support

* Update src/sqlfluff/dialects/dialect_sparksql.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-22 18:51:49 +01:00
Barry Pollard
9ec9acd1e5 BigQuery: Remaining procedural statements (#3473) 2022-06-22 00:06:28 +01:00
Barry Pollard
b347033e08 Postgres: support grouping sets (#3477) 2022-06-21 23:48:39 +01:00
Lorin Dawson
5f0c2060e4 SparkSQL: Support for Delta syntax to create manifest files through the GENERATE command (#3478)
* support for syntax to create manifest files

* pr feedback

* Update src/sqlfluff/dialects/dialect_sparksql.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_sparksql_keywords.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* formatting and refresh YMLs

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-21 23:29:49 +01:00
PeterBalsdon
17813abdfd Add config for optionally indenting contents of ON blocks (#3471)
* initial commit

* bugfix

* add documentation

* add more tests

* Add trailing comma

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Clean up docs

Co-authored-by: Peter Balsdon <peter.balsdon@graze.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry <barry@tunetheweb.com>
2022-06-20 21:27:22 +01:00
Barry Pollard
fea28685af L026: check standalone aliases as well as table aliases (#3470) 2022-06-20 09:33:48 -04:00
Barry Hart
22de3dc5c8 L045: Add handling for nested queries and CTEs (#3468)
* L045: Add handling for nested CTEs

* Also handle nested queries

* Add another nested query test case

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-06-19 11:30:02 +01:00
Barry Pollard
389c0142bb L062: add blocked_regex support (#3467) 2022-06-18 13:48:47 +01:00
Lorin Dawson
0f5d8db9dc support for describe detail (#3465)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-17 21:31:48 +01:00
Alan
abc311aef7 typos 2022-06-17 17:06:42 +01:00
github-actions[bot]
9faf106d55 Prep version 1.0.0 (#3454)
* Bump to version 1.0.0

* Update to stable

* Fix util script

* Update changelog

* fix util script and update changelog

* Add a bit of prose to announce the release

* update util script to add spaces in version headings

* More docs update for stable release

* update changelog with more recent changes

* Update changelog with last PR

Co-authored-by: alanmcruickshank <alanmcruickshank@users.noreply.github.com>
Co-authored-by: Alan <alanmcruickshank@gmail.com>
2022-06-17 16:22:38 +01:00
Alan Cruickshank
dfad1dd9b3 Swap to skip file if not found (#3464) 2022-06-17 16:00:08 +01:00
Barry Pollard
8aa74a41ba Postgres: treat GENERATE_SERIES as a value table function (#3463) 2022-06-16 15:58:40 -04:00
Barry Pollard
6e8ce43a49 Postgres: Support multiple CONSTRAINTS in CREATE DOMAIN (#3460) 2022-06-16 15:28:03 -04:00
Barry Pollard
dea92b26f3 Redshift: Add ANYELEMENT support (#3458) 2022-06-15 18:31:33 -04:00
Barry Pollard
42d380d924 Postgres: Optional select clause elements and better ON CONFLICT support (#3452)
* Postgres: Optional select clause elements and better `ON CONFLICT` support

* Review feedback

* Fix typo
2022-06-14 19:38:23 +01:00
Barry Pollard
f317df572f Add ClickHouse as a dialect (#3448)
* Add ClickHouse as a dialect

* Add .sqlfluff file

* Update comment

* Review feedback

Co-authored-by: Greg Finley <gregory.finley@gmail.com>

* Update src/sqlfluff/dialects/dialect_clickhouse.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

Co-authored-by: Greg Finley <gregory.finley@gmail.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-06-14 19:17:31 +01:00
Barry Pollard
0cde90dcd3 Postgres: allow keywords in qualified column references (#3450)
* Postgres: allow keywords in qualified column references

* Finish comment

* Fix Arrays

* Fix references

* One more fix

* Remove unnecessary code
2022-06-14 18:57:24 +01:00
Barry Pollard
b2f37c773a Remove Baron Schwatz Dead Link (#3453) 2022-06-14 18:39:29 +01:00
Greg Finley
50eea8e0c1 Postgres: Finish ALTER TYPE (#3451)
* Postgres: Finish `ALTER TYPE`

* More attribute
2022-06-13 22:11:26 +01:00
Lorin Dawson
d10907210e working changes (#3447) 2022-06-13 19:13:12 +01:00
Barry Pollard
1ee51be499 Snowflake: Support Stage data file parameters in FROM clauses (#3446)
* Snowflake: Support Stage data file parameters in `FROM` clauses

* Add more test cases
2022-06-11 15:12:25 +01:00
Barry Pollard
eed3443cc8 Redshift: Support Object unpivoting (#3441)
* Reshift: Support Object unpivoting

* Review feedback
2022-06-11 09:48:27 -04:00
Greg Finley
4e6326076e Python script to automate release (#3403)
* Migrate release script to Python

* progress

* regex

* Rewrite existing what's changed

* Find potential new contributors

* Start new contributors

* Get owner from env variable

* Note about safe to rerun

* Get correct new contribs for net new

* WIP

* Fix new contributors when rerunning

* add as dev requirement

* Reword doc

* Abort GHA if branch already exists

* Instructions on running locally

* Update CONTRIBUTING.md

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-10 18:47:56 +01:00
Lorin Dawson
95d80c8f03 Remove Delta Lake Reference in README.md (#3444)
* remove delta lake reference

* Update README.md

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-10 18:15:29 +01:00
Lorin Dawson
072ebc7387 Add databricks dialect as an alias for sparksql dialect (#3440)
* add databricks dialect

* fix mypy error

* move aliasing to init file

* updates to autocomplete to handle dialect aliasing

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-10 15:46:17 +01:00
Barry Pollard
e2f140060e make postgres parameters quotable (#3442)
Postgres allows any identifier (called "parameter" here) to be quoted.
https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

Co-authored-by: Benji York <benji@benjiyork.com>
2022-06-10 14:04:50 +01:00
Barry Hart
20f065c846 Update JinjaAnalyzer and JinjaTracer to handle {% block %} (#3436)
* Update JinjaAnalyzer and JinjaTracer to handle {% block %}

* Add test case

* Comments

* PR review

* Add a more complex test case

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-09 22:21:31 -04:00
Lorin Dawson
23cd31e77a SparkSQL: Add support for Delta VACUUM statement (#3439)
* working updates

* black formating

* support vacuum & test cases

* black formatting

* move keywords out of dialect file and into keyword file
2022-06-09 23:13:17 +01:00
Matthew Dahlman
830b9c8628 Warning for parsing errors extended to all dialects (#3411)
* Update warning for parsing errors

* add test

* test implicit dialect as well

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-06-08 16:59:51 +01:00
Alan Cruickshank
e60272a859 Handle templater validation errors more gracefully (#3433)
* Handle templater validation errors more gracefully

* linting

* no cover

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-08 10:31:03 +01:00
Matthew Dahlman
80aebad038 MYSQL: allow for escaped single quotes (#3424)
* MYSQL: allow for escaped single quotes

* add test case and comments

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-08 09:58:42 +01:00
Barry Hart
64936963e1 L027: Fix false positives by reverting the PR for issue #2992: Check table aliases exist (#3435)
* L027: Fix false positives by reverting PR #2998 (Check table aliases exist), issue #2992

* Add test cases from user issues

* Add another test case from another user issue

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-06-08 09:26:07 +01:00
Matt Menzenski
8e724ef890 Allow numeric_dollar templater to have curly braces, update dollar + numeric_dollar templater examples in docs (#3432)
* Allow numeric_dollar templater to have braces

* add another test case with a quoted string use
2022-06-07 17:45:48 +01:00
Matt Menzenski
8cc234260b Allow Redshift IDENTITY column (seed, step) to be optional (#3430)
* Allow Redshift IDENTITY column (seed, step) to be optional.

Fixes https://github.com/sqlfluff/sqlfluff/issues/3429

* generate the yml test fixture file correctly
2022-06-06 21:11:10 +01:00
Barry Hart
cb6357c540 L036: Make wildcard behavior configurable (#3426)
* L036: Make wildcard behavior configurable

* Revert these changes now that the default behavior is "single"

* PR review, undo irrelevant change

* Add "@document_configuration" decorator to L036

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-06-04 15:52:31 -04:00
Barry Hart
1aafa5eb79 L034: Don't autofix if numeric column references (#3423)
* L034: Don't autofix if numeric column references

* Undo unnecessary changes

* Revert comment change

* Fix the bug, add tests

* Tweak to avoid coverage issue

* Add test case per PR review

* Ignore merge statements

* Update src/sqlfluff/rules/L034.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-04 14:24:13 -04:00
Barry Hart
d51761a2f2 L036: Treat wildcard as multiple select targets (i.e. separate line) (#3422)
* L036: Treat wildcard as multiple select targets (i.e. separate line)

* Remove unused code

* Fix broken tests

* Fix broken dbt tests

* Fix another broken dbt test

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-06-04 13:40:57 -04:00
Matthew Dahlman
6a4695585f Snowflake: IDENTIFIER pseudo-function (#3409)
* snowflake identifier issue 3404

* implement tunetheweb requests

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* keep unreserved words list simple

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-06-01 11:35:14 +01:00
Matthew Dahlman
d96eacfdba Fully referenced object names for snowflake clone syntax (#3414) 2022-05-31 17:44:09 +01:00
Barry Pollard
f15bf0b33d Unpin coverage now issue 6.3 has been resolved (#3393)
* Unpin coverage now issue with 6.2 and 6.3 has been resolved

* Just exclude 6.3

* Update requirements_dev.txt

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-05-30 07:41:18 +01:00
Barry Pollard
589b27e9ca L045: handle UPDATE statements with CTEs (#3397)
* L045: handle `UPDATE` statements with CTEs

* Add no cover for code that's not longer tested

* Review feedback

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-05-29 21:52:51 -04:00
Daniel Mohns
58569adf9f L027: Add support for ignore_words (#3398)
* L027: Add support for `ignore_words`

* Update test/fixtures/rules/std_rule_cases/L027.yml

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-05-29 21:10:37 -04:00
Barry Pollard
3ee42dd1b4 Postgres: Allow CREATE FUNCTION to use Expressions in DEFAULT values (#3408) 2022-05-29 19:51:33 -04:00
Barry Hart
3bb687addc Fix bug in apply_fixes() with leading/trailing whitespace (#3407)
* Fix bug in apply_fixes() with leading/trailng whitespace

* PR review

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-29 21:09:41 +01:00
Barry Pollard
6c56e3104b Redshift: Correct ALTER TABLE syntax (#3395)
* Redshift: Correct `ALTER TABLE` syntax

* Add more syntax support and examples
2022-05-29 20:43:39 +01:00
Greg Finley
0ba5457f07 Postgres: Parse desc index (#3405) 2022-05-29 11:18:14 +01:00
Matthew Dahlman
0ae7b780da extend MySQL SetAssignmentStatementSegment (#3394) 2022-05-23 18:33:10 +01:00
Benji York
1d68f0889f Handle Postgres-style type casts when using the colon_nospaces templating style (#3383)
* make colon_nospaces work with Postgres-style casts

Postgres uses double-colons for type casts (see
https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS).

This change makes it so that we don't confuse them with colon
placeholders.

* Linting fixes

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-22 12:23:06 +01:00
Matthew Dahlman
404d4064a2 capitalization (#3385)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-22 12:06:29 +01:00
Matthew Dahlman
4d8c44f610 MySQL: Update keywords (#3381)
* Add support for ALTER SCHEMA to PostgreSQL (and therefore to Redshift) - Issue 3320

* add newline at end of file

* dang. removed stupid spaces.

* Update test/fixtures/dialects/postgres/postgres_alter_schema.sql

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_postgres.py

remove blank line

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Add Redshift alter schema test

* add quota grammar

* yml for redshift tests

* && and XOR initial commit

* new line

* Fix linting issues

* Barry's AndKeywordSegment override idea

* Expression_C_Grammar -> Expression_A_Grammar and ramifications

* dang. Uncomment first line of select_boolean_operators.sql

* reflect requests from latest review

* Update src/sqlfluff/dialects/dialect_mysql.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* implement requests from latest review

* typo in NotGrammar

* AndKeywordSegment added back plus AndOperatorGrammar, OrOperatorGrammar, NotOperatorGrammar

* initial checkin of mysql keywords

* Apply suggestions from code review

* reserved keywords

* updates tests to handle new reserved words

* improve comments

* changes and tests for issue-1675

* updates requested in PR

* Update src/sqlfluff/dialects/dialect_mysql.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-22 11:38:04 +01:00
Matthew Dahlman
8abe97dd61 Teradata: Database statement and Set Session Database (#3382)
* Add support for ALTER SCHEMA to PostgreSQL (and therefore to Redshift) - Issue 3320

* add newline at end of file

* dang. removed stupid spaces.

* Update test/fixtures/dialects/postgres/postgres_alter_schema.sql

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_postgres.py

remove blank line

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Add Redshift alter schema test

* add quota grammar

* yml for redshift tests

* && and XOR initial commit

* new line

* Fix linting issues

* Barry's AndKeywordSegment override idea

* Expression_C_Grammar -> Expression_A_Grammar and ramifications

* dang. Uncomment first line of select_boolean_operators.sql

* reflect requests from latest review

* Update src/sqlfluff/dialects/dialect_mysql.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* implement requests from latest review

* typo in NotGrammar

* AndKeywordSegment added back plus AndOperatorGrammar, OrOperatorGrammar, NotOperatorGrammar

* Apply suggestions from code review

* changes and tests for issue-1675

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-22 11:18:42 +01:00
github-actions[bot]
323c6dc4e1 Prep version 0.13.2 (#3370)
* Bump to version 0.13.2

* Add changes

* Update CHANGELOG.md

* Update CHANGELOG.md

* Latest changes

* Update CHANGELOG.md

Co-authored-by: tunetheweb <tunetheweb@users.noreply.github.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-20 17:46:52 +01:00
Barry Pollard
f6902983b9 All dialects: Allow RESPECT NULLS/IGNORE NULLS in window functions (#3376) 2022-05-20 16:57:15 +01:00
Barry Pollard
ea987e5f6a Postgres: correct RETURNS TABLE column type (#3379) 2022-05-20 14:47:26 +01:00
Daniel Mohns
8f6fd1d8a8 L065: Add rule for set operators surrounded by newlines (#3330)
* L065: Add rule for set operators surrounded by newlines

* Handle cases where Whitespace segment not accessable

* Fix mypy and lint

* Fix indentation via L003

* Add clarifying comment about `tsql`

* Workaround for mypy

* Update src/sqlfluff/rules/L065.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-20 06:26:49 +01:00
Daniel Mohns
c2b1ec4421 L064: Apply preferred quote-style for partially templated quoted literals (#3300)
* L064: Add initial support for partially templated quoted literals

* Add more test cases

* Make mypy happy

* Fix review comments

* Refine logic to check for quotes inside templates

* Update src/sqlfluff/rules/L064.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-19 16:31:00 +01:00
Barry Pollard
ec2faeee3c BigQuery: Support Stored Procedures (#3369)
* BigQuery: Support Stored Procedures

* Tidy up

* Typo

* Regen YAMLs
2022-05-19 15:27:37 +01:00
Matthew Dahlman
ae5109d08d MySQL extra Boolean operators (&&, ||, !) (#3359)
* Add support for ALTER SCHEMA to PostgreSQL (and therefore to Redshift) - Issue 3320

* add newline at end of file

* dang. removed stupid spaces.

* Update test/fixtures/dialects/postgres/postgres_alter_schema.sql

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_postgres.py

remove blank line

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Add Redshift alter schema test

* add quota grammar

* yml for redshift tests

* && and XOR initial commit

* new line

* Fix linting issues

* Barry's AndKeywordSegment override idea

* Expression_C_Grammar -> Expression_A_Grammar and ramifications

* dang. Uncomment first line of select_boolean_operators.sql

* reflect requests from latest review

* Update src/sqlfluff/dialects/dialect_mysql.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* implement requests from latest review

* typo in NotGrammar

* AndKeywordSegment added back plus AndOperatorGrammar, OrOperatorGrammar, NotOperatorGrammar

* Apply suggestions from code review

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-19 12:06:25 +01:00
Barry Pollard
54cd3c8871 Postgres and Redshift: Support LOCK [TABLE] (#3350)
* Postgres and Redshift: Support `LOCK [TABLE]`

* Add some more LOCK examples
2022-05-18 18:39:23 +01:00
Barry Pollard
7b10c7a496 Placeholder updates: Allow optional braces in dollar placeholders, add colon_nospaces, and cast to string (#3354)
* Allow braces in dollary placeholders

* Fix 3356

* Add Boolean test

* Correct docs and add colon_nospace

* nospace to nospaces
2022-05-18 18:21:28 +01:00
Barry Pollard
36e89cbf2d BigQuery: Basic FOR..IN..DO...END FOR support (#3340)
* BigQuery: Basic `FOR..IN..DO...END FOR` support

* Remove commented out line

* Additional test case

* Add comment
2022-05-18 17:54:36 +01:00
Barry Pollard
d4c741fac8 L025: exclude values clauses (#3358) 2022-05-18 17:30:03 +01:00
Greg Finley
7f3db55c22 GitHub Actions: Update existing PR on new runs (#3367) 2022-05-18 16:54:44 +01:00
Greg Finley
c4f6232ec3 GitHub Actions: Copy draft release notes to CHANGELOG (#3360)
* GitHub Action to set version number

* Mention that it creates a branch

* Remove testing lines

* create pull request

* Start Changelog entry

* Update job name in CONTRIBUTING.md

* remove redundant info

* Update .github/workflows/create-release-pull-request.yaml

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update .github/workflows/create-release-pull-request.yaml

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update .github/workflows/create-release-pull-request.yaml

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Start Of Releases line

* Bump to version 0.13.2

* Run release notes on any fork

* skip PR for now

* list releases

* auth

* echo stuff

* chop

* Revert "skip PR for now"

This reverts commit fdb9cdfb19.

* Print the stuff to the CHANGELOG

* no parens

* try echo

* missing dollar

* Random change

* try writing to a temp file

* try writing to a file

* try more stuff

* better new-lining

* revert everything back

* github token as env

* Add blank sections

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: greg-finley <greg-finley@users.noreply.github.com>
2022-05-18 08:36:34 +01:00
Greg Finley
ae5c5ef669 GitHub Action to set version number (#3347)
* GitHub Action to set version number

* Mention that it creates a branch

* Remove testing lines

* create pull request

* Start Changelog entry

* Update job name in CONTRIBUTING.md

* remove redundant info

* Update .github/workflows/create-release-pull-request.yaml

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update .github/workflows/create-release-pull-request.yaml

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update .github/workflows/create-release-pull-request.yaml

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Start Of Releases line

* Update .github/workflows/create-release-pull-request.yaml

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-17 19:52:35 +01:00
Matthew Dahlman
d39b65d49c Postgres and Redshift: support ALTER SCHEMA (#3346)
* Add support for ALTER SCHEMA to PostgreSQL (and therefore to Redshift) - Issue 3320

* add newline at end of file

* dang. removed stupid spaces.

* Update test/fixtures/dialects/postgres/postgres_alter_schema.sql

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_postgres.py

remove blank line

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Add Redshift alter schema test

* add quota grammar

* yml for redshift tests

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-17 18:46:26 +01:00
Barry Pollard
b51beab1b6 MySQL: better SELECT..INTO support (#3351) 2022-05-17 17:11:44 +01:00
Barry Pollard
bb084fe437 Postgres: support better function calls in create trigger (#3349) 2022-05-17 16:49:44 +01:00
Barry Pollard
eaf2361715 Misc rule doc updates (#3352) 2022-05-17 16:21:13 +01:00
Barry Pollard
2feaa15122 Snowflake: Move CASE keyword to Unreserved list (#3353) 2022-05-17 15:40:51 +01:00
cgkoutzigiannis
7f889eb62d MySQL: Added support for multiple variables in SET statement. (#3328)
* MySQL: Added support for multiple variables in SET statement.

* Change SET statement to match Snowflake dialect.

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-17 10:46:45 +01:00
Greg Finley
dcfbf55634 SOQL: Support date_n_literal (#3344)
* SOQL: Support date_n_literal

* PR feedback
2022-05-16 21:48:55 +01:00
Matthew Dahlman
48fb549566 Update Docs: Getting Started and Index (#3339)
* make Getting Started consistent with README.md (add dialect, update output)

* Linting fixes

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-16 14:02:11 +01:00
Greg Finley
9047416856 SOQL: Disable L026 rule (#3338)
* SOQL: Disable L026 rule

* Move test to fixture

* _dialects_disabled_by_default

* Docstring

* more docstring
2022-05-14 07:47:02 +01:00
Barry Hart
d076f556a2 Fix critical parse error logged after L003 fix (#3337)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-05-13 18:16:10 -04:00
Greg Finley
11afb5d1ac SOQL: Disallow non-SELECT statements (#3329)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-13 16:57:22 +01:00
Frazer Smith
30cf016de5 ci: bump github actions (#3336)
* ci: bump actions/checkout from 2 to 3

* ci: bump actions/setup-python from 2 to 3

* ci: bump actions/setup-python from 1 to 3
2022-05-13 16:04:50 +01:00
Greg Finley
f7e80a184e Start SOQL dialect (#3312)
* Start SOQL dialect

* autocomplete_test

* Alphabetize properly
2022-05-11 21:25:29 +01:00
jungkeun.cho
c316005532 Hive: support CLUSTER, DISTRIBUTE, SORT BY (#3304)
* Hive: support cluster, distribute, sort by

* add testcase

* Apply tunetheweb's review

* Make match_grammar as copy of origin not reference

* Apply review, Fix ORDER as Sequence(ORDER, BY)

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-11 20:27:55 +01:00
Matthew Dahlman
9c473620ab fixed 1-character typo (#3319) 2022-05-11 19:06:51 +01:00
Barry Pollard
040ad57da5 L011: Support MERGE statements (#3292)
* L011: Support `MERGE` statements

* Fix list
2022-05-11 11:29:44 +01:00
Daniel Mohns
8990a58431 BigQuery: Add workaround to fix false-positves of L063 (#3306)
* BigQuery: Add workaround to fix false-positves of L063

* Add BigQuery fixture test
2022-05-10 22:28:51 +01:00
James McNeilis
de2731f8c3 Snowflake: REMOVE statement rework (#3308)
* Standardise REMOVE statement

* Refactor remove statement

* Add new test case
2022-05-10 21:39:24 +01:00
James McNeilis
d9bec01c46 Snowflake: PUT statement (#3307)
* Add Put statement

* Lint

* Remove test file
2022-05-10 21:01:24 +01:00
James McNeilis
a4a87f6d86 Snowflake: GET statement (#3305)
* Troublesome Regex

* Update UNIX example

* Update inline dollar sign, add unquoted file path

* Update tests

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-10 19:43:37 +01:00
James McNeilis
b0a80c5f29 Snowflake: Support ALTER EXTERNAL TABLE (#3302)
* Add Class to dialect

* Add tests

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-10 19:17:18 +01:00
jpers36
520b3d1eb8 T-SQL: Fix PIVOT placement (#3298)
* T-SQL: Fix PIVOT placement

* T-SQL: Fix PIVOT placement

* T-SQL: Fix PIVOT placement

* T-SQL: Fix PIVOT placement

* T-SQL: Fix PIVOT placement

* Update src/sqlfluff/dialects/dialect_tsql.py

Co-authored-by: jpersons <jpersons@iuhealth.org>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-10 19:00:25 +01:00
Barry Pollard
2910f07bbd Cleanup role references (#3287)
* Cleanup role references

* Simplify RoleReferenceSegment
2022-05-10 10:27:57 +01:00
omonereo-tf
86bba7073b Adding Typeform and videoask into inthewild.rst (#3296)
* Adding Typeform and videoask into inthewild.rst

From Typeform, we would like to add our use case in your docs and thank you for this great tool :)

* Linting and grammar fixes

* Remove trailing spaces

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-09 18:02:48 +01:00
James McNeilis
3f8e8c38c4 Snowflake: LIST statement enhancement (#3295)
* List statement enhancement

* Linting

* Remove comments

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-09 17:36:42 +01:00
Greg Finley
4181ac851b MySQL: Support Create User (#3289)
* WIP

* WIP

* DEFAULT ROLE

* REQUIRE

* _resource_option

* _password_option

* comment and attribute

* String literal

* keywords

* Add tests

* Collapse to a single mysql_dialect.replace

* Bake DoubleQuotedLiteralSegment into QuotedLiteralSegment

* Put everything in match_grammar
2022-05-09 17:21:30 +01:00
James McNeilis
64b449a9b3 Snowflake: CREATE STAGE grammar enhancement for file formats (#3293)
* Update match grammar to handle objects

* Update FORMAT_NAME to also take objects
2022-05-09 14:12:56 +01:00
Paul Guyot
29378f813b T-SQL: Complete support for delete statement (#3285)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-09 12:02:24 +01:00
Greg Finley
8d73a2d937 MySQL: Support account names (#3286)
* Allow various quotings

* Allow combinations with at sign

* SingleIdentifierSegment class

* Fix type label

* Update src/sqlfluff/dialects/dialect_mysql.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_mysql.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Keep SessionVariableNameSegment as a singleton

* Add references back

* ObjectReferenceSegment

* Move function

* Extend the match_grammar

* Redundant comment

* Disallow second gap

* Update src/sqlfluff/dialects/dialect_mysql.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Extend RoleReferenceSegment

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-08 21:16:48 +01:00
Barry Hart
cd6215eec7 L028: In tsql dialect, table variables cannot be used to qualify references (#3283)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-05-07 09:14:33 -04:00
Barry Hart
54aa61e8c9 L007: An operator on a line by itself is okay (#3281)
* Add .gitpod.yml

* L007: An operator on a line by itself is okay

* Remove accidentally added file

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-05-07 06:23:01 -04:00
Barry Hart
ddbd330f2e L046 (spaces around Jinja tags) should check all slices in a segment (#3279)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-06 17:41:23 -04:00
Barry Hart
06c6182cd4 L003 bug fix: Not ignoring templated newline (#3278)
* L003 bug fix: Not ignoring templated newline

* Another test case

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-05-06 17:15:00 -04:00
Barry Pollard
77e283044c Prepare 0.13.1 (#3254)
* Prepare 0.13.1

* Update CHANGELOG.md

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Latest changes

* Latest changes

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-05-06 17:02:27 +01:00
Barry Pollard
3de129150d Allow optional AS in MERGE statements using SELECT (#3276) 2022-05-06 16:44:12 +01:00
Barry Pollard
99cc8a55e3 Add groups each rule is in to Rules documentation (#3272)
* Add groups each rule is in to Rules documentation

* Fix test

* Clean up

* Ordering

* Fix incorrect change
2022-05-06 16:21:47 +01:00
Barry Pollard
93d109d87f BigQuery: Enhanced EXPORT DATA statement (#3267) 2022-05-06 12:45:30 +01:00
Barry Pollard
45dfc4b0f3 BigQuery: CREATE TABLE support for COPY and LIKE (#3266) 2022-05-06 12:09:47 +01:00
Greg Finley
818b312240 Improve error on missing keywords (#3268) 2022-05-06 10:22:22 +01:00
Greg Finley
73b04f4f18 MySQL: Add FLUSH support (#3269)
* MySQL: Add  support

* Relay logs for channel

* Flush tables
2022-05-06 08:45:57 +01:00
Greg Finley
89a07d0052 Postgres: Add ALTER TYPE support (#3265)
* Add ALTER TYPE, closes #3216

* Move ALTER TYPE and CREATE TYPE to Postgres
2022-05-05 23:26:56 +01:00
Barry Hart
03d9799720 Bug fix: L036 handle single-column SELECT with comment on same line as SELECT keyword (#3259)
* Bug fix: L036 handle single-column SELECT with comment on same line as SELECT

* Update docstring, add test case for the bug

* Progress

* Report lint warning but don't try to autofix

* Add more details about why autofixing is tricky

* Fix failing test

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-05 23:05:13 +01:00
Greg Finley
179289ad30 Put working example in the README (#3261)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-05 22:48:45 +01:00
James McNeilis
feb0aff631 Snowflake: Add CREATE FILE FORMAT Support (#3104)
* Add CreateFileFormatSegment, CSV Format Type Options

* Swapping to AnyNumberOf()

* Add other file formats, complete create file format

* Move TYPE to Parameters, Add tests, Remove old class

* Big refactor, create tests

* Resolve merge conflicts fully

* Update Regex and String Parsers

* test fixtures

* Remove commented out code

* Remove artefact, ugh

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Remove raw string

* Generate yml fixtures

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-05 22:30:51 +01:00
Barry Hart
6954d68f35 Bug fix: Disable L059 in snowflake dialect (#3260)
* Bug fix: Disable L059 in snowflake dialect

* Add note explaining the rule is disabled for Snowflake

* Update src/sqlfluff/rules/L059.py

Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
2022-05-05 14:56:30 -04:00
Barry Pollard
8e23757214 Remove redundant Anything match_grammars (#3258) 2022-05-04 23:48:20 +01:00
Barry Pollard
491ca55ffd Postgres: Add DOMAIN support (#3257) 2022-05-04 23:22:30 +01:00
Paul Guyot
ff4cb59df1 T-SQL: Allow optional brakets with EXECUTE (#3255) 2022-05-04 13:02:39 +01:00
Paul Wildenhain
3e0d6150d4 ⚙️ Add rule groups and a core rules group (#3142) 2022-05-03 21:34:31 -04:00
Barry Pollard
43b7f8a256 MySQL: Better UNSIGNED support (#3250) 2022-05-03 17:19:04 +01:00
Barry Pollard
142c8ff87b MySQL (and others): Support DROP TEMPORARY TABLE (#3251) 2022-05-03 16:46:36 +01:00
Dave D
f2db37a875 Add Db2 dialect (#3231)
* Add Db2 for i dialect

* revert CHANGELOG changes

* switch to generic Db2 to target all versions

* fix wrong dialect

* renaming files/folders from db2fori to db2

* generate yml file

* change url for db2 and other fixes

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-02 19:57:14 +01:00
Daniel Mohns
5efff59e13 BigQuery: Add CREATE EXTERNAL TABLE statement (#3241)
* Add BigQuery `CREATE EXTERNAL TABLE` statement

* Use `ColumnDefinitionSegment`
2022-05-02 17:54:28 +01:00
Barry Pollard
5df376a9c7 SQLite: Add support for expressions in CREATE INDEX columns (#3240)
* SQLite: Add support for expressions in `CREATE INDEX` columns

* Typo fix

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-05-02 10:32:07 +01:00
Barry Pollard
720063702b Fix exception in check_still_complete and matching in StartsWith (#3236)
* Prevent exception in `check_still_complete`

* Correct error message

* Fix the matching bug

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-05-02 07:59:14 +01:00
Chris Alexeev
3ce285d615 Snowflake: Add Support for DROP Statements (#3238)
* add snowflake drop statements

* approach #1

* consolidate drop statements

Co-authored-by: Chris Alexeev <chris.alexeev@trimedx.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-05-01 23:12:12 +01:00
Barry Pollard
13dc095dea Allow YAML generation script to accept arguments when run through tox (#3233)
* Allow YAML generation script to accept arguments when run through `tox`

* Update docs

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-05-01 22:49:10 +01:00
Barry Hart
8564ed0a49 Bug fix: Cleanly catch and report errors during 'load_macros_from_path' (#3239)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-05-01 16:05:34 -04:00
Fabian Winter
ae9d12e4a2 Indent procedure parameters (#3234)
Issue: #3200
2022-05-01 09:11:08 +01:00
Barry Hart
eb3648ebbd Enhance apply_fixes() to automatically fix violations of can_start_end_non_code (#3232)
* Enhance apply_fixes() to automatically fix violations of can_start_end_non_code

* Refactor check for start/end non-code

* Move code/meta check to new function _is_code_or_meta()

* Update apply_fixes() to bubble illegal segments up the tree

* Fix a bug, add an assertion, add a log message when auto-fix fires

* Comments, tidying, replace loops with takewhile()

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-30 09:10:49 -04:00
Fabian Winter
87d3c503d0 TSQL: Fix for xml path identifier (#3230)
Issue: 3219

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-30 12:41:16 +01:00
Lorin Dawson
f7de0dff05 SparkSQL: Additional Delta Merge Test Cases (#3228)
* test cases

* test cases

* sqlfluff fix
2022-04-30 12:17:44 +01:00
Barry Hart
0aa727f8ae Fix bug where L018 warns inappropriately if CTE definition includes a column list (#3227)
* Fix bug where L018 warns inappropriately if CTE definition includes a column list

* Simplify

* Add comment

* Fix crash in rules critical errors test

* Oops, last fix was bugged

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-04-29 12:01:52 -04:00
Barry Pollard
322026eb95 BigQuery: Better STRUCT support (#3217)
* BigQuery: Better `STRUCT` support

* Better comment
2022-04-29 16:25:16 +01:00
Barry Hart
278abbc053 Fix bug where L003 and L036 fixes caused a parse error (#3221)
* Fix bug where L003 and L036 fixes caused a parse error

* L036 fix, test case

* Simplify .sqlfluf test file

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-29 08:42:51 -04:00
Fabian Winter
1f786b1ecd Make if exists work with union (#3218)
Issue: 3197

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-29 13:22:23 +01:00
Barry Hart
ba89ff07e9 Fix bug where the fix_even_unparsable setting was not being respected in .sqlfluff (#3220)
* Fix bug where the fix_even_unparsable setting was not being respected in .sqlfluff

* Add explanatory comment for the chdir()

* Add missing file

* PR review

* PR review: Fix capitalization of related code

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-04-29 07:48:05 -04:00
Barry Pollard
262010b91c BigQuery: Better DELETE table support (#3224) 2022-04-29 12:15:39 +01:00
James McNeilis
075b2ae8b1 Snowflake: ALTER MATERIALIZED VIEW statement (#3215)
* Add tests

* Remove unnecessary Keyword()
2022-04-28 18:19:50 +01:00
Barry Pollard
724312c80b BigQuery: recognise DATE, DATETIME and TIME as a date parts for EXTRACT (#3209)
* BigQuery: recognise `DATE` as a valie datepart

* Better fix

* Additional date parts
2022-04-28 17:05:13 +01:00
Barry Pollard
cf211823d4 Postgres: enhanced UPDATE statement support (#3203) 2022-04-28 16:46:54 +01:00
Barry Pollard
91146e459a Prevent Date Constructors from being changed to double quotes by L064 (#3212)
* Prevent Date Constructors from being changed to double quotes by L064

* Fix rule L048 and BigQuery
2022-04-28 16:30:20 +01:00
Barry Pollard
b024a8efee Postgres: Fix Drop Extension syntax (#3213) 2022-04-28 16:13:21 +01:00
Barry Hart
c66e3c5ed7 Snowflake: Handle FLATTEN() table function aliases correctly in L025, L027, L028 (#3194)
* Fix issue where L025 was removing the alias for a FLATTEN() call

* Revisit L025: Was working correctly

* Add L027 test case

* L025: Don't warn or remove unused aliases for table functions

* Improve test case comment

* Alternate fix for issue 3178

* Fix broken tests

* Trigger build

* Coverage, tidying

* Remove unnecessary changes

* Update type hint

* Undo formatting changes

* Add a test case, improve test case comments

* Trigger build

* Add new test case per PR review

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-04-28 08:25:17 -04:00
Danny Jones
e7ec286f72 Snowflake: Function LANGUAGE SQL (#3202)
* Snowflake: Moved View to unreserved keywords

* Snowflake: Add Support For SQL Keyword

* Added SQL to procedure

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-28 10:12:20 +01:00
Barry Pollard
5df82444cc Postgres: Enhanced CREATE MATERIALIZED VIEW (#3204)
* Postgres: Enhanced `CREATE MATERIALIZED VIEW`

* Fix Snowflake
2022-04-28 09:33:24 +01:00
Fabian Winter
656a958146 TSQL: Support basic FOR XML statements (#3193)
This is not all FOR XML has to offer, but it should be enough for now :)

Issue: 2668
2022-04-27 09:40:19 +01:00
Fabian Winter
bc17684d6e TSQL: Fix cursor syntax (#3192)
Cursors usually don't have `@` in their names, so we need to fix their
parser.

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-26 19:24:37 +01:00
James McNeilis
ca522e1b1a Snowflake remove statement enhancement (#3191)
* Add variables for remove statement

* Generate fixtures
2022-04-26 18:17:31 +01:00
Danny Jones
8f148de5c9 Snowflake: Moved View to unreserved keywords (#3190) 2022-04-26 15:16:04 +01:00
Barry Pollard
e5eb5025f9 BigQuery: Support EXPORT DATA (#3177)
* BigQuery: Support `EXPORT DATA`

* Remove unnecessary import added in error

* Add `WITH CONNECTION` syntax

* Review feedback
2022-04-25 20:01:21 +01:00
Barry Pollard
4949893a3e T-SQL: Fix exception when using variable names in FROM clause (#3175)
* T-SQL: Fix exception when using variable names in `FROM` clause

* Alternative mypy happiness

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-04-25 18:18:34 +01:00
Barry Hart
3793f35c2c Fix bug where "encoding" setting in .sqlfluff file was not being respected (#3170)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-25 12:55:16 -04:00
Michael O Toole
6c026c76aa Highlight PRS errors in red (#3168)
* Update Violation printing

* Adedd back missing nocover

* Linting and coverage errors

* Remove Typeguard

* Ignore and force types on strange typing error

* Ignore and force types on strange typing error

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-25 10:40:56 +02:00
Barry Pollard
657aed3abf Remove unnecessary StartsWith and make terminator mandatory when using it (#3165)
* Remove unnecessary `StartsWith`

* Make terminator mandatory

* Coverage
2022-04-25 07:24:32 +01:00
Barry Pollard
c4c0095d93 Postgres: Support Composite Types (#3167) 2022-04-24 14:11:07 +01:00
Fabian Winter
4f94b77790 TSQL: Support opening, closing, deallocating and fetching cursors (#3166)
* TSQL: Support opening, closing and deallocating cursors

Issue: 2696

* TSQL: Support fetching for cursors

Issue: 2696

* Fix

* Fix
2022-04-23 16:39:35 +01:00
Fabian Winter
efa866aadb TSQL: Add declaration of cursors (#3164)
Issue: 2696

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-23 14:37:02 +01:00
Barry Pollard
8fb8e0152f Missed #3151 from CHANGELOG (#3163) 2022-04-23 07:39:21 -04:00
Barry Hart
5a56a87c83 Bug fix: L028 sometimes makes incorrect fix when there are subqueries (#3156)
* Bug fix: L028 sometimes makes incorrect fix when there are subqueries

* Move the "number of aliases" check out of _generate_fixes(), because it's about to be more complex

* Refactor: Convert _generate_fixes to a generator; this will make fixing easier

* Refactor to recurse over the entire "tree" of queries

* Fix the bug

* Fix the bug, tidying

* Tidying

* Fix crashes in critical rules errors test

* Fix another crash in rules critical errors test

* Fix crash

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-23 10:17:52 +01:00
Fabian Winter
7e8ed5c09c TSQL: Support OUTPUT INTO (#3162)
It was already in `merge`, but now `insert`, `update` and `delete` get
support, too.

Issue: 2698

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-23 10:00:41 +01:00
Fabian Winter
ff8f408ed3 T-SQL: Add CREATE TYPE statement (#3154)
* TSQL: Add create type statement

Issue: 3140

* fixup! TSQL: Add create type statement

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-23 09:18:35 +01:00
jungkeun.cho
6be8f177f5 Hive: SupportTABLESAMPLE (#3159)
* Hive: Support tablesample

* Change example file name

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-23 09:03:14 +01:00
jungkeun.cho
b314027651 Hive: Support back quoted identifier and literal (#3158)
* Hive: Support back quote

* Change way of handling backquoted identifier

Co-authored-by: jungkeun.cho <jungkeun.cho@linecorp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-23 08:38:08 +01:00
Fabian Winter
81307a91c5 TSQL: Add table hints to insert and delete (#3155)
Issue: #3136
2022-04-23 08:20:07 +01:00
Barry Pollard
6807ac8172 Prepare 0.13.0 (#3120)
* Prepare 0.12.1

* Editing

* Latest changes

* Latest changes
2022-04-22 17:29:38 +01:00
Barry Pollard
279dacd53f Redshift: Fix CREATE TABLE column constraints and COPY (#3151)
* Redshift: Fix `CREATE TABLE` column constraints

* Add `COPY` fix
2022-04-22 17:08:51 +01:00
Daniel Mohns
e01675e50d New Rule L064: Consistent usage of preferred quotes for quoted literals (#3118)
* L064: Consistent usage of preferred quotes for STRING datatype

* Fix CI a bit

* Cleanup code

* Don't put strings into lint error

* Format

* Increase coverage

* Remove unnecessary conditional

We added an additional statement to the if clause that handles cases where neither prefered or alternate quotes don't exist and exit early.
So removing part of the code that was copied from black but is unreachable in our implementation.

* Disable rule by default

* Cleanup comments and docs

* Add more test cases

* Add consistent configuration option

* Bring back raw and fixed string in lint error

In scenarios where the string contains a lot of quotes it might be very hard for the user to tell what is the "correct" way of quoting.

* Update src/sqlfluff/rules/L064.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/rules/L064.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Move constants into rule

* Update src/sqlfluff/core/rules/config_info.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/rules/L064.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/rules/L064.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Clarify tripple quote escape behaviour

* Make warning a bit less scary

* Update src/sqlfluff/core/default_config.cfg

* Update src/sqlfluff/core/default_config.cfg

* Update src/sqlfluff/core/rules/config_info.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/rules/L064.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/rules/L064.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/rules/L064.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/rules/L064.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Remove scary warning

* Remove config option

* Improve flags checking

* Add comment clarifying origin of normalization code

* Clarify raw string body handling

* Make regex helper function intend more clear

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-04-22 16:18:28 +01:00
Barry Pollard
4d2cd04a0c L025 bug fix: stop incorrectly flagging on nested inner joins (#3145)
* L025 bug fix: stop incorrectly flagging on nested inner joins

* Comment
2022-04-22 15:51:03 +01:00
Barry Pollard
2c62defacd TSQL: Add labels, as weel as GRANT/DENY/REVOKE` (#3149) 2022-04-22 15:34:10 +01:00
Barry Pollard
245206bf0b Snowflake: allow bracketless VALUES in FROM clauses (#3141) 2022-04-22 08:57:39 +01:00
Fabian Winter
b8e2b45b47 TSQL: Support try_convert (#3143)
Issue: #3137

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-21 19:05:46 +01:00
Fabian Winter
3a0e2fc820 T-SQL: Support NVARCHAR(MAX) (#3130)
* T-SQL: Support nvarchar(max)

Issues: #2710, #3116

* fixup! T-SQL: Support nvarchar(max)

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-21 18:30:01 +01:00
Barry Pollard
6c899aca30 Allow column-less INSERT INTO with bracketed SELECT (#3139) 2022-04-21 14:51:10 +01:00
조정근
afcace4653 Hive: Support dynamic partition insert (#3126)
* Hive: Support dynamic partition insert

* Add testcase

* Merge multiple examples as one file

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-21 09:50:27 +01:00
nevado
f5e3976fee tsql - alter table - add support for 'with check add constraint' and 'check constraint' (#3132) 2022-04-20 23:12:50 +01:00
Fabian Winter
24d561955f TSQL: Support names for transactions (#3129)
* TSQL: Support names for transaction

issue: 3122

* fixup! TSQL: Support names for transaction
2022-04-20 20:28:38 +01:00
Danny Jones
203a82affb Snowflake: StartsWith() in FromExpressionElementSegment caused performance issues for large queries (#3128)
* Bugfix: StartsWith() in FromExpressionElementSegment caused massive performance issues in Snowflake

* Linting

* Reverting change made by wrong version of black
2022-04-20 17:48:15 +01:00
jonyscathe
7a3c2b4f39 fix: Adjust with_compound_statement (#3121)
Extra WITH statements could be associated with the compound statement.
Fixed by replacing match_grammar StartsWith and parse_grammar optional
Sequnce with a match_grammar Sequence.

Co-authored-by: Jonathan Forrest <jforrest@eskatos.com>
2022-04-20 07:30:26 +01:00
Lorin Dawson
ddc3200009 SparkSQL: Update to support all valid Literal Types (#3102)
* test cases for literals

* update for literals

* linting fixes

* updates tests

* add some no cover comments

* one more no cover comment

* final no cover comment

* revert L006.py

* revert L048.py

* update to sparksql and refresh yml files

* most recent changes

* add SignedQuotedLiteralSegment

* update yml

* remove no cover comments from L006

* formatting

* additional test cases for L048 and L006

* Apply suggestions from code review

* Update src/sqlfluff/rules/L006.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-19 23:10:58 +01:00
jpers36
fc82ef99b4 TSQL: Exclude non-function-name keywords from function names (#3112)
* TSQL: Exclude non-function-name keywords from function names

* TSQL: Exclude non-function-name keywords from function names

* TSQL: Exclude non-function-name keywords from function names

* TSQL: Exclude non-function-name keywords from function names

* TSQL: Exclude non-function-name keywords from function names

Co-authored-by: jpersons <jpersons@iuhealth.org>
2022-04-19 15:11:16 +01:00
Barry Pollard
41e2920f46 ANSI AT TIME ZONE parsing improvements (#3115)
* ANSI `AT TIME ZONE` parsing improvements

* Fix other dialects
2022-04-18 19:34:04 -04:00
Barry Hart
07bef156f1 When fixing a file, preserve the input file's permissions (#3114)
* When fixing a file, preserve the input file's permissions

* Set mode before overwriting existing file

* Update command-line test to verify file mode is preserved

* Fix broken tests

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-04-18 18:27:34 -04:00
Barry Hart
354f34cd73 Bug: L058 (flatten nested CASE) triggers incorrectly (the ELSE contains additional code) (#3113)
* Fix bug where L058 triggers but shouldn't

* Comments

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-04-18 17:41:12 -04:00
Barry Hart
f7850a48f0 Bug fix: Handle "lint" human-format file output correctly (#3109)
* Bug fix: Handle "lint" human-format file output correctly

* Simplify

* Simplify

* Undo previous change, introduced a bug

* Fix docstring

* Fix "sqlfluff fix" bug when reading from stdin

* Another tweak to "sqlfluff fix"

* Add test for "--write-output" with human format

* Replace __enter__, __exit__, __call__ with write() and close() functions

* Fix test error

* Coverage

* Undo formatting change

* Update src/sqlfluff/cli/outputstream.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-18 13:28:52 -04:00
Daniel Mohns
38c31c99f6 L003: Add configuration option to disallow hanging indents (#3063)
* L003: Add configuration option to disallow hanging indents

* Simplify config option naming

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-04-17 19:43:52 -04:00
Daniel Mohns
15fc256aa2 Add native Github-actions output (#3107)
* Add native Github-actions output

* Update docs

* Add test and handle error vs failure

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-04-17 19:09:18 -04:00
Barry Pollard
57710114a3 Improved signed literal parsing (#3108) 2022-04-17 09:30:58 -04:00
Barry Hart
f693cd184d Don't allow fixes to span template blocks (#3105)
* Fixes can't span template blocks

* Rename pre-existing block_idx variable to slice_idx to avoid name collision

* Add test

* Increment index *after* block_end tag, not before

* Fix some broken tests

* Compute fix slices differently

* Compute fix slices differently for this check

* Simplify the changes

* Fix more bugs

* Refactor how we decide which slices to consider

* Trigger build

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-04-17 08:36:18 +01:00
Daniel Mohns
fccae141eb L010: Add ignore_words_regex configuration option (#3098)
* L010: Add `ignore_words_regex` configuration option

* Simplify attribute handling

* Add tests to L010

* Add `ignore_words_regex` to L029

* Add `ignore_words_regex` to L057

* Add `ignore_words_regex` to L059

* Apply black

* Fix yamllint

* Make sure all code is covered by tests

* Change to use `regex.search`

* Apply black

* Rework `ignore_words_regex` unquoted test

* Small improvement to L030 test

* Clarify usage in partial matches in `ignore_words_regex`

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-15 18:10:27 +01:00
Barry Pollard
aa704c4091 Redshift: Better AT TIME ZONE support (#3087)
* Redshift: Better `AT TIME ZONE` support

* Add test case

* Fix typos
2022-04-15 17:46:45 +01:00
Kaartic Sivaraam
847bfd92a3 Fix a potential typo (#3100)
The suggestion is purely based on my assumption as to how the author
expected to phrase the sentence.

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-15 17:21:13 +01:00
James McNeilis
deebce0d9a Snowflake: Add Create Storage Integration grammar. (#3075)
* Add create storage integration grammar

* Remove TODOs and resolve comments

* Add QuotedStarSegment

* Remove optionl parameters for AnySetOf

* Remove errors introduced, and wildcard segment for STORAGE_BLOCKED_LOCATIONS

* Remove optional

* Remove Sequence to allow AnySetOf to be optional

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-15 17:01:17 +01:00
Daniel Mohns
98c7b7bb33 ANSI: Allow indented_using_on in MERGE statements ON (#3096)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-14 11:05:38 +01:00
Barry Pollard
aaa6b3a2bc Postgres: Support COLLATE in more clauses (#3095) 2022-04-14 09:35:45 +01:00
Barry Pollard
4bc2916bf8 BigQuery: Support NORMALIZE function (#3086)
* BigQuery: Support `NORMALIZE` function

* Update src/sqlfluff/dialects/dialect_bigquery.py

* Review feedback

* Review feedback
2022-04-13 20:56:56 +01:00
Barry Pollard
0cfccf4a92 ANSI (and other dialects): Add DROP FUNCTION support (#3082) 2022-04-13 14:14:55 +01:00
Barry Pollard
778271bcd5 Postgres: Support DROP EXTENSION (#3083) 2022-04-13 13:17:29 +01:00
James McNeilis
8da1c9ef27 Add optional for describe statement (#3076)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-12 08:48:56 +01:00
Barry Hart
c039be5783 Update individual rules to take advantage of core rule processing changes (#3041)
* Refactor rule segment iteration for flexibility and speed

* Fix a bug that was clearing memory when _eval() returned None

* Create CrawlBehavior class, fix broken test

* Update rule L009 to set recurse_into = False

* After first linter loop pass, skip rules that don't do fixes

* Reduce number of RuleContext objects, compute siblings_pre/post on demand

* Add "raw_segment_pre" as an alternative to "raw_stack"

* Coverage

* Rules declare whether they need context.raw_stack

* Implement linter phases so post-processing rules only run once

* Tidy, simplify

* Update L050 to use recurse_into = False

* Tidying

* Tune L003 a bit

* Refactor L003 for performance, add RuleContext.final_segment property

* Comments, coverage

* Refactor core rule processing for flexibility and speed

* Only "main" phase when linting (as opposed to fixing)

* Move test fixes from big PR

* PR review

* Simplify how we detect first linter pass and track lint violations

* Coverage

* Apply suggestions from code review

Comment changes suggested by Barry Pollard

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* PR review

* PR review

* Comments, tidying

* Update rule development docs with some of the new (and old) options

* Add more comments about needs_raw_stack

* PR review

* Apply suggestions from code review

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-11 20:02:13 -04:00
Michael O Toole
bbb8be7c96 L003 forgives non misbalanced Jinja tags (#3065)
* Account for disbalanced Jinja templates

* Account for disbalanced Jinja templates

* Improve and clarify comments

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-12 00:01:39 +01:00
Martyn Jones
a6180d0e43 Fix tsql dialect EXEC = @Variable StoredProc Failed Parsing Bug (#3070) (#3077)
* Fix T-SQL EXEC = @Variable Failed Parsing Bug (3070)

* Update test/fixtures/dialects/tsql/execute.sql

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-11 23:41:27 +01:00
Chris Alexeev
d49e212fa3 Snowflake Dialect: Add External Function DDL (#3071)
* external function added and alter function edited

* ran pre-commit

* last minute edits

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* fix errors

Co-authored-by: Chris Alexeev <chris.alexeev@trimedx.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-11 21:49:57 +01:00
Lorin Dawson
faf0439337 delta update statement (#3073) 2022-04-11 21:23:35 +01:00
Lorin Dawson
c88baa6fd5 SparkSQL: Test cases for Delta DELETE FROM syntax (#3072)
* test cases for delta delete from

* additional test cases
2022-04-11 19:02:38 +01:00
Barry Pollard
911e35f7e0 Postgres: Support quoted LANGUAGE params (#3068)
* Postgres: Support quoted `LANGUAGE` params

* Switch to Identifier

* Standardise on param
2022-04-11 11:15:38 +01:00
Barry Hart
63788ae5fb Fix bug handling Jinja set with multiple vars, e.g.: {% set a, b = 1, 2 %} (#3066)
* Fix bug handling Jinja set with multiple vars, e.g.: {% set a, b = 1, 2 %}

* Add test

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-04-10 17:46:43 -04:00
Barry Hart
2b93a26e6f L007 should ignore templated newlines (#3067)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-04-10 17:31:59 -04:00
Barry Pollard
8835477e5c Allow aliases to pass L028 (#3062)
* Allow aliases to pass L028

* Test update
2022-04-09 20:29:56 +01:00
Barry Hart
073290b7f4 Refactor core rule processing for flexibility and speed (#3061)
* Refactor core rule processing for flexibility and speed

* Only "main" phase when linting (as opposed to fixing)

* Move test fixes from big PR

* PR review

* Simplify how we detect first linter pass and track lint violations

* Coverage

* Apply suggestions from code review

Comment changes suggested by Barry Pollard

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* PR review

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-09 14:13:01 -04:00
Barry Pollard
1e20a481d3 Add editorconfig and precommit for SQL and YML files (#3058)
* Add editorconfig and precommit for SQL and YML files

* Revert unintended change

* Fix test

* Fix another test

* Editorconfig update

* Fix another test

* More fixes
2022-04-09 16:00:39 +01:00
Barry Hart
06fe4d633d Rule L003 performance: Cache the line number and last newline position (#3060)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-04-09 08:56:44 -04:00
Dmytro Kulyk
a72ec67d43 Fixed documentation for sql_file_exts (#3059) 2022-04-09 11:43:55 +01:00
Barry Pollard
deb58efe3b BigQuery: Support SAFE functions (#3048) 2022-04-08 20:02:45 +01:00
Barry Pollard
3c47c45c94 Postgres: Fix UNNEST for L025 (#3054) 2022-04-08 19:28:11 +01:00
Barry Pollard
93bc838b83 Exasol: CREATE/DROP/ALTER USER/ROLE clean up for consistency (#3045)
* Exasol: `CREATE/DROP/ALTER USER/ROLE` clean up for consistency

* More consistency changes

* Add `CREATE USER` to ANSI
2022-04-08 13:16:33 +01:00
Mark Ferree
42a7cab801 Postgres add ALTER ROLE/ALTER USER support (#3043)
* Fix parse error for ALTER ROLE and ALTER USER statements.

* Missed a trailing comma.

* Update src/sqlfluff/dialects/dialect_postgres.py

Co-authored-by: Mark Ferree <mferree@varomoney.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-08 10:36:22 +01:00
Patrick von Glehn
2bdeb9354d Add CarePay to SQLFluff in the wild (#3038)
* Update inthewild.rst

Add Carepay to SQLFluff in the wild

* Update docs/source/inthewild.rst

* Update docs/source/inthewild.rst

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-07 20:40:26 +01:00
James McNeilis
163b98513e Add Conflict Grammar for Postgres (#3027)
* Initial commit, lots of TODO

* Finished sequences, added ANSI

* Resolve errors, add tests

* Docstrings, linting

* Remove redundant comment

* Black file, my bad

.
,

* Move OperationClass, change COLLATE ref
2022-04-07 18:28:03 +01:00
Barry Pollard
ee106517f7 Add dialect to Docker test (#3033) 2022-04-07 10:27:45 +01:00
Barry Pollard
f057b9f1c4 Prepare 0.12.0 (#2987)
* Prepare 0.12.0

* Code formatting

* Latest changes

* Update CHANGELOG.md

Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>

* Update CHANGELOG.md

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Latest changes

* Update release date

* Latest changes

* Update CHANGELOG.md

Co-authored-by: Daniel Mohns <dmohns@users.noreply.github.com>

* Latest changes

* Latest changes

* Latest changes

* Latest changes

* Latest changes

* Typos

Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Daniel Mohns <dmohns@users.noreply.github.com>
2022-04-07 09:55:02 +01:00
Paul Yang
03a83fffea fix: use FromExpressionSegment instead of FromExpressionElementSegment (#3031)
in UpdateStatementSegment

Co-authored-by: Paul Yang <paulyang@kkstream.com>
2022-04-07 08:04:16 +01:00
Barry Hart
ab9f7eb021 Fix bug in patch generation for segments made of templated + literal code (#3030)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-04-06 22:19:42 +01:00
Barry Hart
793bbe7e1a PR review followup (#3029)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-06 21:46:24 +01:00
Mark Ferree
e2cc851abb Postgres better CREATE USER/CREATE ROLE support (#3016)
* Creating new segment to resolve parse error on CREATE USER calls.

* Adding class definition, keywords, more test cases

* Removing unnecessary whitespace change

* Combining CREATE USER and CREATE ROLE

* Fixing 'SuperuserKeywordSegment' which was not found in the redshift dialect
' errors

Co-authored-by: Mark Ferree <mferree@varomoney.com>
2022-04-06 21:25:42 +01:00
Philipp
09f882fd01 SparkSQL: Add MERGE syntax (#3025)
* Add sparksql merge syntax

* Apply suggestions from code review

Co-authored-by: Philipp <philipp.i.b.lange@gmail.com>

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-06 21:05:41 +01:00
Barry Pollard
ba4542d93f Remove Delimited workarounds (#3024)
* Remove Delimited workarounds

* Missed one
2022-04-06 20:43:28 +01:00
Barry Pollard
cf3ac18658 Add exclude option for Ref grammar (#3028)
* Add `exclude` option for `Ref` grammer

* Add another one
2022-04-06 20:15:34 +01:00
Lorin Dawson
595d25f1fe SparkSQL: Adding support for Delta Lake table schema updates (#3013)
* commit to push for feedback

* update to use OneOf and exclude to pass tests

* create and update yml files

* black

* switch anynumberof to oneof in exclude argument

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-06 19:51:37 +01:00
Daniel Mohns
6ca3959e87 L027: Check table aliases exists (#2998)
* L027: Check table aliases exists

* Apply Black

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-04-06 19:24:31 +01:00
Danny Jones
47c8bb2910 Snowflake: Added support for REMOVE Statements (#3026)
* Snowflake: Added support for REMOVE Statements:

* Linting
2022-04-06 18:58:29 +01:00
Barry Pollard
a955cd6c92 BigQuery: Support WEEK function with days of weeks (#3021)
* BigQuery: Support `WEEK` function with days of weeks

* Forgot about the weekend!

* Add an extra test
2022-04-06 17:32:42 +01:00
Philipp
0a63e448d4 Sparksql quoted identifier in STRUCT (#3023) 2022-04-06 15:27:31 +01:00
Barry Hart
c6c19da455 Force user to specify a dialect (#2995)
* Force user to specify a dialect

* Try to get tests working with no default dialect

* Trigger build

* Fix some of the broken tests

* Fix test/cli/commands_test.py

* Fix test/core/config_test.py

* Fix test/core/linter_test.py

* Fix test/core/parser/lexer_test.py

* Fix more tests

* Fix some tests

* All tests in test/core/ are working

* Add comment

* Linter() constructor shouldn't require a dialect

* Fix more tests

* Fix most YAML tests, also test/rules/std_test.py

* Fix broken example and rule

* Fix dbt tests

* Fix broken test, remove .sqlfluff to see what breaks

* Fix issue with benchmarks

* Fix simple command-line GitHub CI tests

* Fix diff-quality tests

* Fix more tests

* Fix some old issues with progress bar tests

* Add test/fixtures/.sqlfluff

* Tidying, add test to address coverage gap

* Don't require path initially for sqlfluff lint, parse, and fix commands

* Undo unnecessary change

* Update src/sqlfluff/core/config.py

* Prefer configs to override

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-06 09:27:05 -04:00
Daniel Mohns
c142a23110 BigQuery: Parse CREATE TABLE with trailing comma (#3018)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-06 09:05:11 +01:00
koryd
ee738c0d3a Snowflake: Add IS (NOT) DISTINCT FROM test cases (#3014)
* added in segment rules for 'is distinct from' and 'is not distinct from'

* added tests

* Apply suggestions from code review

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: kdonati <kdonati@indeed.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-06 08:33:10 +01:00
Daniel Mohns
03b23cb22d BigQuery: Add support for column OPTIONS in STRUCT definitions (#3017)
* BigQuery: Add support for column `OPTIONS` in `STRUCT` definitions

* Make data type actually match the comment
2022-04-06 07:51:59 +01:00
Sergey Korsik
eb6a564d09 PostgreSQL: added support for CREATE ROLE and DROP ROLE statements (#3010)
* Fixes for CREATE ROLE and DROP ROLE (postgres)

* Update src/sqlfluff/dialects/dialect_ansi.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_ansi.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_ansi.py

* Update src/sqlfluff/dialects/dialect_ansi.py

* Review feedback

* Correct typo

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry <barry@tunetheweb.com>
2022-04-05 19:38:25 +01:00
Barry Pollard
220b4ac443 Separate slow CI job to it's own workflow (#3012)
* Separate slow CI job to it's own workflow

* Also run at 2am
2022-04-05 19:21:35 +01:00
Lorin Dawson
fc22204536 test cases for delta write (#3009)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-05 18:16:22 +01:00
Danny Jones
c1e9bce86d Snowflake: Added support for CLUSTER BY and other CREATE TABLE improvements (#3008)
* Added support for CLUSTER BY function(), also relaxed ordering requirements for CREATE TABLE

* Black

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-05 17:42:39 +01:00
Barry Pollard
c74acba743 Support TRIM function parameters (#3007)
* Support `TRIM` function parameters

* Fix parsing
2022-04-05 17:03:24 +01:00
Barry Pollard
e8af773126 BigQuery: Support AT TIME ZONE in EXTRACT (#3004)
* BigQuery: Support `AT TIME ZONE` in `EXTRACT`

* Add comment

* Better implementation

* Change to expression

* Regen YAMLs
2022-04-05 16:09:31 +01:00
Barry Pollard
981855512c BigQuery: Move some keywords to unreserved (#3002) 2022-04-05 15:33:35 +01:00
Daniel Mohns
e0646975f1 BigQuery: Allow quoted variable names in DECLARE (#3006) 2022-04-05 13:56:42 +01:00
Paul Guyot
e5a73c2f6f T-SQL: allow optional AS keyword in parameters def (#3001)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry <barry@tunetheweb.com>
2022-04-05 07:22:32 +01:00
Paul Guyot
95028d3458 T-SQL: add support for returns @var table syntax (#3000)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-05 00:37:17 +01:00
Paul Guyot
19a660482e TSQL: add support for parenthesized nested joins (#2993)
* TSQL: add support for parenthesized nested joins

* Fix rule L026

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry <barry@tunetheweb.com>
2022-04-05 00:16:43 +01:00
Daniel Mohns
0773373122 dbt: Read builtins from code (#2988)
* dbt: Read builtins from code

* Fix doclinting

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-04 23:39:25 +01:00
Paul Guyot
1a8d9f30ad T-SQL: fix table type in DECLARE statements (#2999)
* T-SQL: fix table type in declare statements

* Add missing trailing line

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-04 23:14:31 +01:00
Paul Guyot
ae7b629484 TSQL: allow leading GO (#2997)
Co-authored-by: Paul Guyot <pguyot@upclear.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-04 22:46:48 +01:00
Paul Guyot
939113e0c1 T-SQL: add support for assignment operators (#2996)
* T-SQL: add support for assignment operators

* Cleanup & add a type for class

* Add support for compount operators for Updates (fix #2008)

Co-authored-by: Paul Guyot <pguyot@upclear.com>
2022-04-04 22:17:27 +01:00
Daniel Mohns
29cb4b6c71 BigQuery: Add more MERGE statement variants (#2989) 2022-04-04 17:10:50 +01:00
James McNeilis
f136ed2c30 L041: Fix bug when there is a newline after the select clause modifier (#2981)
* Initial fix

* Add test

* Update comments

* Flake8 linting fix

* Review feedback

* Black

Co-authored-by: Danny Jones <51742311+WittierDinosaur@users.noreply.github.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry <barry@tunetheweb.com>
2022-04-04 00:03:15 +01:00
Barry Hart
cd9acddb95 Rule L045 doesn't recognise CTE usage in a subquery when rule L042 is enabled (#2980)
* Bug: L042 modifies parse tree even during "lint"

* Debugging code

* Got it applying the subquery -> CTE fix by disabling the "insert CTE definition" fix

* Mostly fixed

* Tidying

* mypy

* Remove obsolete comment

* Tinkering, not fixed

* Fix the bug

* Tidying

* PR review

* PR review

* Restore comments

* Update src/sqlfluff/core/parser/segments/base.py

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-03 23:44:26 +01:00
Daniel Mohns
5acf286e19 dbt: Make is_incremental() defaults consistent (#2985)
Between `_generate_dbt_builtins()` and `default_config.cfg`.

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-04-03 22:41:23 +01:00
Barry Pollard
67ca49a55d Rename Grammars for consistency (#2986)
* Rename Grammars for consistency

* Revert incorrect change
2022-04-03 21:30:08 +01:00
Danny Jones
99ceea6073 Added support for MySQL Update Statements (#2982)
* Added support for MySQL Update Statements

* Added multi-table example

* Update src/sqlfluff/dialects/dialect_mysql.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Make UpdateStatementSegment consistent across dialects

* Linting fixes

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-03 17:30:27 +01:00
Danny Jones
4c99d8cdee Added Create External Schema, bugfix in Partioned By (#2983)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-03 16:39:32 +01:00
Danny Jones
466b2b988d Added ALTER INDEX and REINDEX to Postgres, Some Grammar Cleaning (#2979)
* Added ALTER INDEX and REINDEX to Postgres, Some Grammar Cleaning

* Linting

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-03 16:17:37 +01:00
Barry Pollard
e378331ee2 TSQL grammar deduplication (#2967)
* TSQL grammar deduplication

* Rename Segments -> Grammars

* Statement terminators should be between statements not within them

* linting

Co-authored-by: Alan <alanmcruickshank@gmail.com>
2022-04-03 15:58:10 +01:00
Michael O Toole
8126c06720 L003 Refactor V2 (#2884)
* Calculate Tempalte info with Line using class

* _LineSummary for the win

* _Memory joins the team

* L003 preformance improvements

* Correct Comment Errors

* Coverage fixes

* linting errors

* memo is_empty

* Fix coverage

* linting Issue

* Seperate out more sub elements

* Hanging into method

* Running Again

* further clean up

* spelling Errors

* Comments spelling and fStrings

* Linting Bugs

* Fixed now incorrect tests

* remove unneeded test

* remove useless lcass method

* Compact rules

* be explicit

* Fix cli output test

* Fix typos

* denest functions and gitignore

* DAte no longer capital
2022-04-03 12:21:59 +01:00
Danny Jones
5eefcae75f Delimited Refactor (#2831)
* Draft

* Fixes most issues with implementation

* Fix BQ date_part as expression

* Fix greedier expressions

* Fix greediness in longest_trimmed_match

* Fix some snowflake issues

* Fix remaining snowflake issues

* Extra exasol tests

* Fix spark issues

* Fix mysql issues

* Exasol workaround

* Black

* Add mypy hint

* Linting

* Fix noqa_prs test

* Remove wayward comma

* Regenerate yml

* Fix Mypy

* Remove exasol test

* Remove unnecessary method

* Coverage

* Pragma

* Code Coverage

* Linting

* Mypy ignore

* Patch Bigquery hyphenated table reference

* Fix BQ unpacking bug

* Fix broken test

* Separated Hyphenated back out

* Removing debug comments

* Partially functional exasol scripts

* Fix the terminator segment

* reinstate removed test

* linting

Co-authored-by: Alan Cruickshank <alanmcruickshank@gmail.com>
2022-04-02 17:46:35 +01:00
Lorin Dawson
817aa0294c SparkSQL: Support for querying snapshots when reading data with Delta Lake (#2972)
* support for reading snapshots in delta

* fixed a missed Spark3 reference the in README

* change atsign_literal to at_sign_literal

* remove AsOfGrammar

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-02 16:47:38 +01:00
Barry Pollard
f2b5324da4 Fix bug in L063 for BigQuery STRUCT params (#2975)
* Fix bug in L063 for BigQuery `STRUCT` params

* Restrict parent selectors to keywords to avoid having to maintain list of exclusions
2022-04-02 09:53:38 +01:00
Barry Hart
473e64fe97 Fix assertion error in dbt templater when file ends with whitespace strip ("-%}") (#2976)
* Fix assertion error in dbt templater when file ends with whitespace strip ("-%}")

* Fix the bug

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-02 09:04:33 +01:00
Tomasz Cholewik
401fa4a3c3 Pass dbt vars to dbt (#2923)
* Fix: vars_from_cli

* Updated Dev container config

* fixed missing requirement to use buildkit
* parametrized .dbt/profiles.yml to point to correct container
  automatically

* Update plugins/sqlfluff-templater-dbt/test/templater_test.py

* Update plugins/sqlfluff-templater-dbt/test/templater_test.py

* Black (again) - wish I'd never started this!

* Minor fixes

* Update templater_test.py

Copy DBT_FLUFF_CONFIG before modifying

* Update docs/source/configuration.rst

Co-authored-by: Tomasz Cholewik <tcholewik@consumer-edge.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry <barry@tunetheweb.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-04-01 18:57:30 -04:00
Daniel Mohns
3d52e8270d BigQuery: Add support for column OPTIONS (#2973)
* Add support for BigQuery column options

* Update src/sqlfluff/dialects/dialect_bigquery.py

* Update src/sqlfluff/dialects/dialect_bigquery.py

* Update src/sqlfluff/dialects/dialect_bigquery.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-01 20:28:53 +01:00
Daniel Mohns
a5072bb217 Issue 2970: Allow expressions in BigQuery options (#2971)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-01 18:43:36 +01:00
Paul Guyot
2f205e4eae Bump black to 22.3.0 on pre-commit (#2969)
Co-authored-by: Paul Guyot <pguyot@upclear.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-01 18:21:34 +01:00
Alan Cruickshank
cb9a25b564 TSQL: Redefine DatatypeIdentifierSegment (#2959)
* Remove redefinition of data type segment.

* Redefine data type identifier.

* bring the ansi dialect into line

* Don't reserve timestamp in teradata

* default the other way

* revert change to teradata

* Do exclude keywords in datatypes

Co-authored-by: Barry <barry@tunetheweb.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-04-01 17:51:52 +01:00
Paul Guyot
328a1153a3 Add support for WAITFOR statement (#2968)
Co-authored-by: Paul Guyot <pguyot@upclear.com>
2022-04-01 17:22:35 +01:00
Paul Guyot
2705453d4d Add WHILE statements to T-SQL dialect (#2966)
Co-authored-by: Paul Guyot <pguyot@upclear.com>
2022-04-01 15:14:11 +01:00
Paul Guyot
c9c25d400b INTO is optional within T-SQL INSERT statement (#2963) 2022-04-01 14:22:43 +01:00
Barry Pollard
4c848479b1 Add basic IS (NOT) DISTINCT FROM support in most dialects (#2962) 2022-04-01 13:33:34 +01:00
Lorin Dawson
c8d860757b SparkSQL: Create Table Delta Lake Variant (#2954)
* create table delta

* rename & move delta test case

* yml file

* Update src/sqlfluff/dialects/dialect_sparksql.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-31 17:40:02 +01:00
Barry Pollard
b40eddf0f9 TSQL: Add support for CREATE/DROP/DISABLE TRIGGER (#2957)
* TSQL: Add support for `CREATE`/`DROP`/`DISABLE` `TRIGGER`

* Remove unnecessary test case
2022-03-31 17:07:12 +01:00
Barry Hart
78aadedf5a Bug: L042 modifies parse tree even during "lint" (#2955)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-30 18:50:18 -04:00
Aviv Nitsan
2c22edbf5d Allow multiple post function clauses in Postgres and Redshift (#2952)
* Add failing test for redshift percentile_cont

* Fix percentile_cont parsing for Redshift

Per @tunetheweb's comment: https://github.com/sqlfluff/sqlfluff/issues/2951#issuecomment-1083434954
2022-03-30 19:24:03 +01:00
Barry Pollard
42f1ca3a15 Fix bug in L022 for trailing comments in CTE (#2946) 2022-03-30 13:15:06 +01:00
Barry Hart
05dea5db22 More dialect checking, fixes, inheritance cleanup (#2942)
* Add back runtime checks for "replace()" that were deleted in prior PR

* Clean up Snowflake dialect

* Fix inconsistent segment type names

* More tidying

* Postgres cleanup

* Clean up sparksql dialect

* Revert bad change

* Remove inheritance, fix segment type

* Add back blank line that was removed

* Regenerate YML files

* Require explicit override of both match_grammar/parse_grammar if parent has both

* Fix bug in PartitionClauseSegment

* Add type hints to ANSI dialect so others won't need "type: ignore"

* Fix typo

* More "type: ignore"

* Coverage

* Add error-check test as suggested in PR review

* Remove no covers

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-30 07:53:24 -04:00
Barry Pollard
1845353819 TSQL: Support OUTPUT Params and GOTO Statements (#2949)
* TSQL: Support OUTPUT Params and GOTO Statements

* Add another test case
2022-03-30 12:21:38 +01:00
Lorin Dawson
a1385c1d75 BREAKING CHANGE: change existing dialect name from spark3 to sparksql (#2924)
* change dialect name spark3 to sparksql

* fix docs

* fix spark3 to sparksql in l026 comment

* fix spark3 t osparksql in L057 comments

* Update test case

Co-authored-by: Barry <barry@tunetheweb.com>
2022-03-29 09:42:11 +01:00
Ziko Rajabali
ebd4dfa6c1 Add Symend to SQLFluff In The Wild (#2940)
* Add Symend to the list of companies using SQLFluff in the wild

* Better english

* Update docs/source/inthewild.rst

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-29 08:05:47 +01:00
Barry Hart
c55aba3957 Simplify segment creation and inheritance in dialects (#2933)
* To replace base dialect segment class, must subclass or provide same stuff

* Fix spark3 and redshift dialects

* Fix exasol dialect

* Fix oracle dialect

* Fix teradata dialect

* Add comments

* Add "no cover"

* Experimental changes to make dialect inheritance simpler, more type safe

* Fix bad reference

* Fix bad reference

* Use absolute module paths, not relative

* Eliminate need for "@segment" decorator

* Update spark3 and bigquery dialects

* Update remaining dialects

* Switch to static segment inheritance

* Remove unused function

* Improve docstring

* Call add_update_segments() automatically (from load_raw_dialect())

* Fix tsql

* Fix TSQL the right way

* Fix broken tests

* Use inheritance to simplify

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-28 18:16:05 -04:00
Ziko Rajabali
3e0825951f Snowflake: Add ALTER STREAM support (#2939)
* snowflake dialect: Added and registered CREATE STREAM segment, and created test fixture

* Removed unnecessary parse_grammar statements

* Added missing keywords, removed unnecessary segments, fixed parsing errors

* Fixed flake8 problems

* Boolean Literal Grammar over TrueSegment || FalseSegment

* Add ALTER STREAM to the Snowflake dialect
2022-03-28 22:37:28 +01:00
Barry Pollard
e3ac22d0fa TSQL: Handle multiple nested joins (#2938) 2022-03-28 21:59:42 +01:00
Ziko Rajabali
c6eac9a432 Snowflake: Add CREATE STREAM support (#2936)
* snowflake dialect: Added and registered CREATE STREAM segment, and created test fixture

* Removed unnecessary parse_grammar statements

* Added missing keywords, removed unnecessary segments, fixed parsing errors

* Fixed flake8 problems

* Boolean Literal Grammar over TrueSegment || FalseSegment
2022-03-28 21:33:38 +01:00
Barry Pollard
ea2341ffa5 TSQL: Support nested joins (#2928)
* TSQL: Support nested joins

* Improvement

* Cleanup
2022-03-27 20:57:49 +01:00
Barry Hart
335d7e20cb To replace base dialect segment class, must subclass or provide same stuff (#2930)
* To replace base dialect segment class, must subclass or provide same stuff

* Fix spark3 and redshift dialects

* Fix exasol dialect

* Fix oracle dialect

* Fix teradata dialect

* Add comments

* Add "no cover"

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-27 12:14:23 -04:00
Barry Pollard
93eac61cd6 Add new rule L063 to allow separate capitalisation policy for Datatypes (#2931)
* Add new rule L063 to allow separate capitalisation policy for Datatypes

* More fixes

* Add some extra guards

* Fix test

* Update src/sqlfluff/core/rules/base.py
2022-03-26 21:46:50 +00:00
Derick Lung'aho
671fd658b5 Adds support for column definitions in table alias expressions (#2932)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-26 21:19:19 +00:00
Barry Pollard
cbc0708a04 BigQuery: support numeric aliases in UNPIVOT clauses (#2925) 2022-03-26 14:59:01 +00:00
Barry Pollard
8c31b4eb1d TSQL: Supported nested MERGE statements (#2926) 2022-03-26 13:09:04 +00:00
Alan Cruickshank
db70cb7269 0.11.2 Release (#2914)
* Draft new release

* update changelog

* update changelog
2022-03-25 20:07:48 +00:00
Danny Jones
01d951db0e Added Support For Snowflake Inline Comments (#2919)
* Added Support For Snowflake Inline Comments

* Added slashes to trim start

* Added classic inline comments to Snowflake Inline Comment File

* More in-liney commments
2022-03-25 12:00:15 +00:00
Barry Pollard
d5fa10250f Spark3: Fix bug which did not allow multiple joins (#2917) 2022-03-25 10:49:38 +00:00
Danny Jones
a4c51bb642 Added Snowflake Alter View Support (#2915)
* Added Snowlfake Ater View Support

* Black
2022-03-24 20:44:42 +00:00
Barry Pollard
32d1e46304 Adjust L010 to ignore nulls and booleans covered by L040 (#2913)
* Adjust L010 to ignore nulls and booleans covered by L040

* Update comment

* Alternative method
2022-03-24 18:33:53 +00:00
Barry Hart
c915ddf418 Fix bug where L043 corrupts SQL (#2908)
* Fix bug where L043 corrupts SQL

* Tweak name again

* Bug fix from PR review

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-24 12:01:18 -04:00
Barry Hart
cbf51c94eb Jinja: Add support for Block Assignments (#2907)
* Bug fix: Jinja templater fix false "Undefined variable" errors

* Fix broken test

* PR review

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-23 18:59:09 -04:00
Barry Hart
305159ea64 L042 fix fails with missing function get_identifier() on Postgres, Redshift dialects (#2899)
* L042 fix fails with AttributeError on non-ANSI dialects

* Remove broken code from test

* Second try at the fix (cleaner)

* Add similar test file to Postgres dialect test directory for "Critical rules test

* Add missing YML file

* Rename test file per PR review

* Rename again

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-22 20:37:13 -04:00
Barry Pollard
e1834bccea BigQuery: Better Set Operators support (#2901)
* BigQuery: Better Set Operators support

* Clean up

* Update rule L033 as no longer applies

* Docs
2022-03-22 22:56:48 +00:00
Dmytro Kulyk
48e41a6629 added support for complex type in rowtype def (#2896) 2022-03-22 11:57:37 +00:00
Dmytro Kulyk
378ec411b4 added json type to hive dialect (#2894) 2022-03-21 21:27:56 +00:00
Dmytro Kulyk
1991c62327 Hive: fix to align with L027 rule (rowtype attribute name) (#2893)
* added fix to align with L027 rule

* Update test/fixtures/rules/std_rule_cases/L027.yml

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-21 20:59:01 +00:00
Barry Pollard
5b45e2a877 Hive: Add ARRAY support (#2891)
* Hive: Add `ARRAY` support

* Extra test cases

* Add empty array test
2022-03-21 10:08:57 +00:00
Michael Rosenberg
a4d7258f1a Implemented PIVOT/UNPIVOT Redshift + Fixed Snowflake Bug + Standardized PIVOT/UNPIVOT Parsing (#2888)
* Added PIVOT and UNPIVOT as reserved keywords

* Finished implementing Redshift PIVOTs

* Added first example for Redshift pivot

* Added PIVOT and UNPIVOT as reserved keywords

* Finished implementing Redshift PIVOTs

* Added first example for Redshift pivot

* Fixed bugs + updated tests

* Added tests + fixed bugs

* Refactored and simplified

* Linted

* More linting

* Deleted unneccessary code

* Reverted t-sql changes

* updated bigquery + redshift

* flaked
2022-03-20 14:55:02 +00:00
Barry Hart
06f75c5aea Fix AssertionError in dbt templater when file ends with multiple newlines (#2887)
* Fix AssertionError in dbt templater when file ends with multiple newlines

* Fix failing tests

* Add test

* Comments, tidying

* More comments

* Undo some cleanup changes that broke stuff

* Add back newlines that I accidentally removed

* More comments per PR review

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-20 10:13:54 -04:00
Dmytro Kulyk
84817465e3 Row typecasting in hive cast function (#2889)
* added row typecasting to hive

* Update src/sqlfluff/dialects/dialect_hive.py

* Fix typo and Regen YAMLs

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry <barry@tunetheweb.com>
2022-03-20 12:21:25 +00:00
Barry Hart
a99c156291 dbt templater should gracefully skip macro files (#2886)
* dbt templater should gracefully skip macro files

* Add automated test to verify dbt macros are skipped

* Parametrize existing tests for disabled files to also test macro files

* Fix macro skipping for dbt < 1.0

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-19 08:06:52 +00:00
Barry Hart
03dde1e041 Disable L031 on BigQuery due to complex backtick / project name behavior (#2882)
* Disable L031 on BigQuery due to complex backtick / project name behavior

* PR review

* One note, not two

* Apply suggestions from code review

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Run Black

* Update src/sqlfluff/rules/L031.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Add doc decorator

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-18 15:04:41 -04:00
Barry Hart
e9040110eb Documentation: Update dbt templater docs with more detail about pros and cons (#2885)
* More doc tweaks

* Mention debugging, dbt-utils, etc

* Tone it down

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-18 14:14:42 -04:00
Barry Pollard
d6b6b0f303 BigQuery: Better STRUCT Array Support (#2881) 2022-03-18 14:07:55 +00:00
Barry Hart
ad75318a7c L042: Detect violations when column is templated (#2879)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-18 09:49:40 +00:00
Marc-Antoine Schmidt
be67a7e7ad Improve parsing of BETWEEN statements (#2878)
* Between statement parsing improvement

* Added yml test file

* black formatting
2022-03-18 09:19:13 +00:00
Barry Pollard
5a389a0148 Prepare 0.11.1 release (#2866)
* Prepare 0.11.1 release

* Update CHANGELOG.md

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Latest changes

* Latest changes

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-03-17 08:31:16 +00:00
Lorin Dawson
df7662d7d8 Spark3: Support for SHOW statements (#2864)
* show statements

* black

* fix l044 for alter view test case

* fix L044 for create table datasource test cases

* updates to and test cases for L014

* fix L014 tests to specify spark dialect

* current draft for feedback

* remove extra code

* fix and text cases for L057

* finalize test for L059

* fix for select_delimited_identifier_with_escaped_backticks test case

* refresh yml files and formatting

* Update src/sqlfluff/dialects/dialect_spark3.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_spark3.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Apply suggestions from code review

Co-authored-by: Lorin Dawson <22798188+R7L208@users.noreply.github.com>

* Regen YAMLs

* Run black

* Remove unused import

* More black

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry <barry@tunetheweb.com>
2022-03-16 22:45:29 +00:00
Kyle Weber
686b571ce0 Add Markerr to list of organizations using SQLFluff in the wild (#2874)
* Update inthewild.rst

* Update docs/source/inthewild.rst

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-16 22:00:01 +00:00
Barry Hart
28df654ca4 Refactor JinjaTracer: Split into two classes, break up "_slice_template()" function (#2870)
* Minor cleanup/refactor of JinjaTracer

* More refactoring

* More refactoring

* More refactoring

* Add more type annotations

* Extract a function track_block_end() out of update_next_slice_indices()

* Make some functions static

* Split up _slice_template() some more

* More types and tidying

* RawSliceInfo: Provide default value for next_slice_indices

* Use RawSliceInfo instance instead of alt_id/alt_code variables

* Split JinjaTracer into two classes: JinjaAnalyzer and JinjaTracer

* Make idx a field, rename as idx_raw

* Tidying

* PR review

* PR review

* Add explanatory comment about str_buff and str_parts

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-16 12:17:39 -04:00
Barry Pollard
c0f1983401 BigQuery: support Parameterized Numeric Literals (#2872) 2022-03-16 13:09:20 +00:00
Michael O Toole
6da4f6a780 L042 autofix (#2860)
* Semi Working Draft

* Fix the CTEs

* Clean up type checking

* Cover clashing test cases

* fixed all the things

* update for 3.7

* imporve cover

* cleanup linting errors

* Doc strings and linting

* merge conflicts

* fix linting issues

* Safely get dialect Segement defs

* corrcet mypy issues

* refactor based on comments

* return removed test

* MY not understanding generics

* Fixed Pending L032

* align with Main

* Added test for failing query

* Added test for failing query

* Force position/Apply inline replace

* create fresh point

* actually use template slice

* Update test/fixtures/linter/autofix/ansi/L042_subqueries_in_joins/after.sql

* Update test/fixtures/dialects/ansi/unaliased_using_subquery.sql

* Update test/fixtures/linter/autofix/ansi/L042_subqueries_in_joins/before.sql

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-03-16 11:14:22 +00:00
rpr-ableton
dff1bad8b1 Redshift transaction segment (#2852)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-16 08:21:50 +00:00
Barry Hart
613d5887fc Follow-up for issue 2835: The issue recurred after fixing issue 2822 (#2868)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-15 16:42:41 +00:00
Barry Hart
f6f6c2f13a L009: Handle adding newline after {% endif %} at end of file (#2862)
* L009: Handle adding newline after {% endif %} at end of file

* Lexer should add trailing placeholders if needed

* Fix L009 to run on the actual final segment, *even if meta*

* Update iter_patches() to return EnrichedFixPatch for better fix placement

* Fix broken test

* Comments, type hints

* First draft of refactor how we handle FixPatch vs EnrichedFixPatch

* Second phase of refactoring FixPatch

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-15 11:20:13 -04:00
Barry Pollard
447ecf862a Redshift: Add support for AT TIME ZONE (#2863) 2022-03-14 22:38:26 +00:00
Michael O Toole
e26733a401 L032 bug fix and fix improvement (#2859)
* Moved to clean branch

* remove print

* Lint dat Yaml

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-03-14 10:55:39 -04:00
Barry Hart
3c127ddccf Refactor JinjaTracer; store lex output as individual strings where possible (#2856)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-14 07:49:41 -04:00
Michael O Toole
a182596499 Add ability to regenerate subsets of fixture YAMLs (by dialect, or new only) (#2850)
* Generate only required fixtures

* Added new only flag

* Improvements as requested
2022-03-14 09:39:29 +00:00
Barry Hart
f79355796d Fix bug with Jinja and dbt "{% set %}" blocks (#2849)
* Fix a design flaw in handling of Jinja "{% set %}" blocks

* Remove print() statement

* Comments

* Fix dbt test failures, move slice sanity checks

* Fix remaining broken tests

* Formatting tweaks

* Remove extra newline

* Fix old bug in test

* Add a test

* Skip consistency check for base templater tests

* Add comment

* Tweak comment and whitespace

* Fix issue 2835, add tests

* PR review: Add explanatory comment

* Add guard in case list is empty

* Fix broken test

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-13 19:20:03 -04:00
Barry Hart
0bbd70f38a Revert "L042 Autofix - (CTE hoisting) Super Working PR (#2795)" (#2854)
This reverts commit 6c2bfa3196.
2022-03-13 17:03:33 -04:00
Michael O Toole
6c2bfa3196 L042 Autofix - (CTE hoisting) Super Working PR (#2795)
* Semi Working Draft

* Fix the CTEs

* Clean up type checking

* Cover clashing test cases

* fixed all the things

* update for 3.7

* imporve cover

* cleanup linting errors

* Doc strings and linting

* Imporved testing

* fix linting issues

* Safely get dialect Segement defs

* corrcet mypy issues

* refactor based on comments

* return removed test

* MY not understanding generics
2022-03-13 20:17:09 +00:00
Barry Hart
918af576ea Bug fix: "ValueError: Position Not Found for lint/parse/fix" in JinjaTracer (#2846)
* Bug fix: "ValueError: Position Not Found for lint/parse/fix" in JinjaTracer

* Add test case for the bug

* DRY up the code, add commments, fix a test

* Remove .sql test case, add a similar but smaller test case to jinja_test.py

* Add generated YAML file

* Remove unneeded code

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-12 16:38:52 -05:00
Jiajie Zhong
f37dc1410c Reduce unnecessary setting run ci (#2847)
* In job `python-version-tests`, we already told the version we
  setup in step `Set up Python`, so we could simply run command
  `tox -e py` to trigger the job, so we could remove the
  `Set Tox Python Param` step
* In job `other-tests` we just set unused vairable by one step
  and I think we should directly remove it.
2022-03-12 14:20:36 +00:00
Lorin Dawson
999a5e01f2 Spark3: statements to SET and RESET spark runtime configurations (#2839)
* support for reset statement

* DRAFT for set statement

* finalize SetStatementSegment

* remove missed segments in StatementSegment

* feedback from review

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-11 22:56:41 +00:00
Barry Pollard
b44851f4d8 BigQuery - prevent L006 flagging hyphenated table references (#2842)
* BigQuery - avoid L006 being raise on hyphenated table references

* Update test/fixtures/rules/std_rule_cases/L006.yml

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-03-11 22:11:54 +00:00
Barry Pollard
bdd8dde4d1 TSQL fix convert function definition (#2843)
* TSQL fix bug where dateparts where sometimes not recognised as such

* Better solution
2022-03-11 20:57:15 +00:00
Michael O Toole
e5e5c7e8f7 Change rule test script from bash to pythong (#2840)
* Bash --> Pytest

* Remove test refs & add cache

* fix Doc str

* Imporve all the tests

* speed up tests maybe?

* removed over caching

* remove typo from test

* make it use Cores

* add more cores

* Remove Caching etc

* Cleanup imports
2022-03-11 18:11:12 +00:00
Lorin Dawson
a09b32df18 Spark3: Support DESCRIBE statement (#2837)
* describe statement

* Update src/sqlfluff/dialects/dialect_spark3.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-11 15:50:08 +00:00
Lorin Dawson
571c594d03 Spark3: Refactor REFRESH statements into one class (#2838)
* refactor refresh statements into one class

* black

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-11 13:59:35 +00:00
Barry Hart
0e91f423fd Prevent rules incorrectly returning conflicting fixes to same position (#2830)
* Fix L052 bug deleting space after Snowflake SET statement

* Make a similar fix elsewhere in L052, DRY up the code

* Update tests to raise error on fixes with duplicate anchors

* Fix L036 bug: Deleting the same segment multiple times

* Rework the fixes to use object *identity*, not *equality*

* Comments

* Update L052 to use IdentitySet

* Coverage checker

* Update src/sqlfluff/core/linter/linter.py

* Update test/fixtures/rules/std_rule_cases/L052.yml

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* PR review: Raise log level for these messages to CRITICAL

* Add comment per code review

* Update test/fixtures/rules/std_rule_cases/L052.yml

* Bug fix to IdentitySet

* Update L039 to avoid returning multiple fixes with same anchors

* Add test case for fixed L039 issue

* Fix one of the post-fix parse error bugs in L053

* Fix L053 bug, allow create_before + create_after for same anchor

* Tweaks

* Fix type annotation

* Comments, tweaks

* Fix bug in L050, fix missing space in message

* Remove commented-out code

* Add "pragma: no cover"

* Add "pragma: no cover"

* PR review

* More L039 comments

* Discard fixes from lint results if tehre are conflicts

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-10 17:03:46 -05:00
rpr-ableton
e94005e462 Update dateparts values and functions for both Redshift and BigQ (#2829)
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-09 19:56:05 +00:00
Barry Pollard
4ccb5a5b73 MySQL add NOW support (#2825)
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-03-09 17:21:14 +00:00
Barry Pollard
cac0d78cbc MySQL DELETE FROM support (#2823)
* MySQL DELETE FROM support

* Review feedback
2022-03-09 16:49:54 +00:00
Barry Pollard
5e143c42b0 Rule L059 bug with IF (#2824)
* Fix bug with L059 for IF statements

* Remove debug

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-03-09 16:06:41 +00:00
Barry Pollard
36b79bd87c Prevent exceptions when running fix on dialect fixtures (#2818)
* Prevent iiteration error in get_select_statement_info

* Add some extra guards

* Better if

* Even better if

* Indentation

* Review feedback

* Add test cases

* Change test from lint to fix

* Add types

* Coverage

* Typo
2022-03-09 15:23:47 +00:00
Lorin Dawson
8bcd099e43 Spark3: Support to handle CACHE AND UNCACHE auxiliary statements (#2814)
* add support for auxiliary cache and uncache statements

* new test cases for fixing options grammar to allow more than just strings

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-09 13:15:41 +00:00
Barry Pollard
d7ef8ba753 Fix L036 error on CREATE VIEW AS SELECT (#2816) 2022-03-08 23:20:46 +00:00
Barry Hart
e456f60136 Fixes for the new post-fix parse check (#2813)
* Post-fix parse check: Prefer parse_grammar over match_grammar

* Bug fix for _choose_anchor_segment()

* Add comments

* Apply suggestions from code review

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Simplify how we check (parse) the fixes

* Add test case that runs multiple rules

* Type hints, tidying

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-08 18:00:08 -05:00
Philipp
a618565c98 Add initial MERGE syntax to most dialects (#2807)
* Ansi: add MERGE statement

* requested changes

* make MATCHED non-reserved

* requested changes

* add bigquery tests
2022-03-08 15:55:14 +00:00
Barry Hart
1fe387fabd Automated tests should fail if a lint fix introduces a parse error (#2809)
* Automated tests should fail if a lint fix introduces a parse error

* Use the right formatting function (actually operator)

* Some L052 fixes

* More L052 fixes

* Add "pragma: no cover"

* Include rule code (i.e. identifier) in parse error output

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-08 08:28:24 -05:00
Barry Pollard
e12a81c2a0 Correct 0.11.0 release date in CHANGELOG (#2808) 2022-03-07 15:25:27 +00:00
Barry Pollard
262f94d5fc Prepare release 0.11.0 (#2742)
* Prepare release 0.11.0

* Better wording

* Review feedback

* Add latest changes

* More changes

* Latest changes

* Latest changes

* Add latest changes

* Latest changes

* Latest changes

* Latest changes

* Latest changes

* Latest changes

* Code formatting of keywords

* More formatting

* Latest changes

* Last change

* Latest changes

* Fix PascalCase

* Code format
2022-03-07 15:04:19 +00:00
Timo S
fa051b055b Exasol: Fix INTERVAL literals / expression (#2804)
* fix interval expression

* add link to the docs

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-06 23:41:05 +00:00
Timo S
03a513411b Add IDLE_TIMEOUT and SNAPSHOT_MODE (#2805) 2022-03-06 23:14:10 +00:00
Timo S
97df610ecc Support Value range clause for INSERT statements (#2802)
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-06 22:44:05 +00:00
Timo S
3af8485a7e Exasol: Add lua adapter scripts (7.1+) (#2801)
* Add lua adapter scripts (7.1+)

* add adapter script test cases

* fix file ending

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-06 22:24:29 +00:00
Timo S
48d14ac6b8 Exasol: Add openid support for create/alter user (7.1+) (#2800)
* Add openid support for create/alter user

* Add capitalisation + merge parse/match_grammar

* more capitalisation

* Update src/sqlfluff/dialects/dialect_exasol.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-06 21:44:40 +00:00
Timo S
0508eaefd7 New consumer group params 7.1+ (#2799) 2022-03-06 20:58:46 +00:00
Joseph Young
33130cf590 Snowflake: Complete INSERT grammar (#2798) 2022-03-06 19:37:49 +00:00
Joseph Young
332669d395 Fix Postgres VALUES, make Spark3 VALUES consistent (#2797)
* Fix Postgres VALUES, make Spark3 VALUES consistent

* Update src/sqlfluff/dialects/dialect_spark3.py
2022-03-06 18:22:47 +00:00
Joseph Young
7d79eeb2f4 Postgres: INSERT DEFAULT value (#2796) 2022-03-06 16:32:40 +00:00
Joseph Young
08d0d98c21 Postgres: Make AS optional in Postgres DELETE (#2794)
* Postgres: Make AS optional in Postgres DELETE

* Re-add test

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-06 12:08:26 +00:00
Barry Pollard
953fde5282 BigQuery support UNEST aliases (#2793)
Co-authored-by: Joseph Young <80432516+jpy-git@users.noreply.github.com>
2022-03-06 11:48:36 +00:00
Joseph Young
9dc33cf652 Postgres: Add all range operators (#2789)
* Postgres: Add all range operators

* generate-fixture-yml doesn't automatically generate the templater fixtures >:(

* Regenerate yaml

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-06 11:33:52 +00:00
Joseph Young
4d63c93ede Snowflake: Complete DELETE FROM grammar (#2792)
* Snowflake: Complete DELETE FROM grammar

* Make AS optional
2022-03-06 11:06:34 +00:00
Joseph Young
c19c5b2c21 Postgres: Complete DELETE FROM grammar (#2791)
* Postgres: Complete DELETE FROM grammar

* Add DELETE statement to WITH grammar

* Add WITH RECURSIVE example

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-06 08:52:24 +00:00
Joseph Young
97170388a4 Postgres: Add RETURNING grammar to INSERT INTO statement (#2790)
* Postgres: Add RETURNING grammar to INSERT INTO statement

* Whoops forgot to generate yaml

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-06 08:06:06 +00:00
Joseph Young
944d6c3876 Snowflake: Complete PATTERN grammar (#2788)
* Snowflake: Complete PATTERN grammar

* Remove old todo
2022-03-06 07:29:43 +00:00
rpr-ableton
eefc823b28 Redshift: add [ALTER/CREATE/DROP] PROCEDURE segments (#2774)
* REDSHIFT: Add support for procedures

* cover some more cases + review definition of procedure parameter list

* @tunetheweb's comments:
- move CompressionType, ArgMode and ColumnEncoding to grammars instead of segments
- clean up StatementSegment to keep only statements
- renaming some classes for the sake of clarity

* Update src/sqlfluff/dialects/dialect_redshift.py

* Black

* Allow change in params

* Black

* Add max_times_per_element

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry <barry@tunetheweb.com>
2022-03-04 18:28:05 +00:00
Lorin Dawson
544b09a423 Spark3: Support for ANALYZE TABLE statement (#2780)
* support for analyze table

* adjust type on ListFileSegment and ListJarSegment

* change type of noscankeywordsegment

* Update src/sqlfluff/dialects/dialect_spark3.py

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-04 17:16:53 +00:00
Joseph Young
dc05914afb Snowflake: Add MATCH_RECOGNIZE clause (#2781)
* Snowflake: Add MATCH_RECOGNIZE clause

* satisfy flake8

* Add reluctant mode for quantifiers

* Simplify symbol segments

* Update yaml fixture
2022-03-04 16:15:13 +00:00
Joseph Young
9f1c7fe7b1 Snowflake: Complete LIMIT grammar (#2784)
* Snowflake: Complete LIMIT grammar

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Implement review feedback

* Black

* use match_grammar.terminator insert

* Use Ref.keyword for terminator insert

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-04 15:51:16 +00:00
Michael O Toole
267b6bbf6b Rough autofix for L028 (#2757)
* Rough autofix for L028

* Fix Yaml duplicate key

* cleaned up

* flip back docs

* tests and cleaning

* Correct Notes

* Correct Notes

* changes for coverage

* fix coverage

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-04 13:46:03 +00:00
PhilippLange
78bb1bd831 Spark3 bug: Create with complex data types (#2761) (#2782)
* Spark3 bug: Create with complex data types

* Spark3 bug: Create with complex data types

Co-authored-by: Philipp Lange <philipp.lange@mhp.com>
2022-03-04 11:03:35 +00:00
Joseph Young
314cbd2eb8 Snowflake: Complete LIKE grammar (#2779)
* Snowflake: Complete LIKE grammar

* Remaining LIKE grammar

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-03 17:18:58 +00:00
Lorin Dawson
2ae5a219fd auxiliary file and jar statements (#2778) 2022-03-03 16:57:09 +00:00
Joseph Young
1b4b266f1c Snowflake: Refine SET/UNSET MASKING POLICY grammar (#2775)
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-03 16:01:35 +00:00
Michael O Toole
31f78a2b8a L049 bug: correct over zealous "=" --> IS (#2760)
* correct over zealous = --> IS

* small cleanup

* remove test case
2022-03-03 14:24:03 +00:00
Barry Pollard
f1cd4c6646 Make extenstion case insensitive (#2773) 2022-03-03 12:22:17 +00:00
Joseph Young
9a408d3798 Snowflake: Add dollar quoted string literal (#2770) 2022-03-02 21:44:34 +00:00
Barry Hart
251f223544 Bug fix: L036 corrupts "SELECT DISTINCT id" query (#2768)
* L036 corrupts "SELECT DISTINCT id" query

* Fix

* Simplify

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-03-02 21:22:11 +00:00
Joseph Young
d016fefeed Snowflake: Add CHANGES clause (#2764)
* Snowflake: Add CHANGES clause

* tidy formatting

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-02 20:35:12 +00:00
Lorin Dawson
99761d241f Spark3: Support for EXPLAIN statement (#2767)
* support for explain statement

* remove parse_grammar from explain statements

* black
2022-03-02 20:05:37 +00:00
Joseph Young
fa249a9ea0 Snowflake: Add CONNECT BY clause (#2763)
* Snowflake: Add CONNECT BY clause

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-02 18:28:21 +00:00
Lorin Dawson
4aced664ef Spark3: Support for TRANSFORM clause (#2762)
* support for transform clause

* remove unnecessary code changes
2022-03-02 18:03:53 +00:00
Joseph Young
95f1826aff Snowflake: Fix GROUP BY {CUBE|ROLLUP|GROUPING SETS} parsing (#2759)
* Snowflake: Fix GROUP BY {CUBE|ROLLUP|GROUPING SETS} parsing

* snowflake specific tests

* revert spark test
2022-03-02 16:49:22 +00:00
Barry Pollard
68d331543a BigQuery: allow identifiers starting with dash (#2756) 2022-03-02 15:16:25 +00:00
Barry Pollard
44ec589f7c Add ignore_words options to L057 and L059 (#2753)
* Add `ignore_words` options to L057 and L059

* Fix logic

* Another test to pass coverage

* Make check case insensitive
2022-03-01 23:05:57 +00:00
Barry Pollard
6f88179260 L012 bug fix for TSQL alternative alias types (#2750)
* L012 bugfix for TSQL Alt alias types

* Improvement

* Add some more test cases

* Comments

* Review feedback

* Revert unnecessary newline
2022-03-01 22:37:43 +00:00
Lorin Dawson
c19b634d0e Spark3: Support for PIVOT clause (#2752)
* support for pivot clause

* refresh yml files

* formatting update

* remove unneeded lines
2022-03-01 20:05:52 +00:00
rpr-ableton
ecbd7a8fdf Update Redshift reserved keywords list (#2751)
* move ARRAY, OID and TIMESTAMP to the reserved keywords list

* updateredshift_unreserved_keywords.sql
2022-03-01 19:24:13 +00:00
Michael O Toole
f50e72b748 L007 autofix (#2735)
* L007 autofix

* Fix small typing issues

* No cover unreachable code

* Fixed no cover and line lenght

* remove newlines that imply new test but arent

* changed to functional approach

* even shorter

* shortened code

* improved typing

* Fix typing issues

* syntax shortening

* no cover __iter__

* Update src/sqlfluff/core/rules/functional/segments.py

* Update src/sqlfluff/core/rules/functional/segments.py

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-03-01 11:56:37 -05:00
Michael O Toole
319bea6890 L032 fixable in easy cases (#2737)
* Fix USING -> ON when the join is implicit

* remove unneeded newlines

* Added newlines between tests

* linting fixes

* Update src/sqlfluff/core/parser/segments/base.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Update src/sqlfluff/rules/L032.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

* Embrace the Optional

* Remove useless Comment

* Update src/sqlfluff/rules/L032.py

Co-authored-by: Barry Hart <barrywhart@yahoo.com>

Co-authored-by: Barry Hart <barrywhart@yahoo.com>
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-03-01 08:15:40 -05:00
Barry Hart
97cb026ea3 Fix dbt templater runtime error in inject_ctes_into_sql() (#2748)
* Fix dbt templater runtime error in inject_ctes_into_sql()

* Add back blank line that was accidentally removed

* Make it more efficient

* Update plugins/sqlfluff-templater-dbt/test/fixtures/dbt/dbt_project/models/ephemeral_3_level/stg_max_product_contract_seats.sql

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-03-01 10:13:15 +00:00
Timo S
5686f9e6ab L059: Exasol: Allow quotes around passwords in CREATE USER (#2744)
* L059: Allow quotes around passwords in CREATE USER

* Define a list of types to ignore

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
2022-02-28 22:46:58 +00:00
Barry Hart
a9bc45edce Improve docs for "load_macros_from_path" (#2743)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-02-28 17:03:10 -05:00
Barry Hart
8e37b09b3f Make L045 (Query defines a CTE but does not use it) case insensitive (#2746)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-02-28 16:46:47 -05:00
Barry Hart
8c151bf72f Add L049 test for T-SQL alternate alias syntax (=) (#2745)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-02-28 16:22:46 -05:00
Barry Hart
7a204ddccc BaseSegment.pos_marker is typed as non optional but sometimes set to … (#2741)
* BaseSegment.pos_marker is typed as non optional but sometimes set to None

* mypy

* Simplify

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-02-28 15:15:34 -05:00
Barry Pollard
db7bd4159b Support Pascal case for L030 (#2739) 2022-02-28 18:36:12 +00:00
Michael Rosenberg
a1571ac1fe Postgres, Redshift: Support SIMILAR TO pattern matching expressions (#2732)
* Added first LIKE segment

* See if this fixes recursive references

* Added more segments

* Committing PatternMatchingExpressionSegment so far

* Added first LIKE segment

* See if this fixes recursive references

* Added more segments

* Committing PatternMatchingExpressionSegment so far

* Rolled back dev changes for the ANSI dialect

* Copied Expression_A_Grammar to postgres

* Added first LIKE segment

* See if this fixes recursive references

* Added more segments

* Committing PatternMatchingExpressionSegment so far

* Added first LIKE segment

* See if this fixes recursive references

* Added more segments

* Committing PatternMatchingExpressionSegment so far

* Rolled back dev changes for the ANSI dialect

* Copied Expression_A_Grammar to postgres

* Added Like operators

* Updated postgres dialect

* Updated implementation

* Implemented SIMILAR TO

* Added SIMILAR TO tests

* Added POSIX Expression and Operator

* Simplified implementation + added redshift tests

* Linted

* Added TODO

* Added links to issues addressing TODOs

* Simplified to LikeGrammar overwrite

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Deleted bloat not needed due to LikeGrammar overwrite

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Reverted LikeOperator changes in Postgres

* Deleted unnecessary TODO

* Updated yml hashes

* Linted

* Update src/sqlfluff/dialects/dialect_ansi.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-02-28 15:42:22 +00:00
Michael O Toole
413cd9e3db Forgive Shorthand_CAST only / bracket only expressions from L013 (#2729)
* Forgive CAST only / bracket only expressions from L013

* remove commented out test

* fixed YAML linting error

* remove dead code

* cleaned up comment spelliing errors

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-28 13:11:27 +00:00
Barry Hart
0778b478aa L052: Refactor _eval() into individual functions to improve readability (#2733)
* L052: Move semicolon handling to a separate function

* Split semicolon handling into multiple functions

* Tidying

* More tidying, move "ensure semicolon" logic to a separate function

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-28 12:17:42 +00:00
Barry Hart
ce9cd4a753 L018: Move closing parenthesis to next line (#2734)
Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-28 12:00:55 +00:00
Juho Autio
3031baf09b Improve rule yaml tests: assert that fix_str passes the rule (#2624)
* Fix tests: assert that fix_str passes the rule

* Remove fix_str + add TODOs

* Remove fix_str + add TODOs

* Add help comments in assertions

* Add missing fix_str (fix succeeds)

* Roll back indent only changes

* Explain why L004.yml has failing fix_str's

* Try noqa for L003.yml (still fails)

* Enforce that fix_str passes or violations_after_fix is defined

* Drop outdated comments

* Update src/sqlfluff/testing/rules.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/testing/rules.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update src/sqlfluff/testing/rules.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-28 10:42:12 +00:00
rpr-ableton
b534985152 Extend rule L051 to LEFT/RIGHT/OUTER JOINs (#2719)
* first pass at extending L051

* initial work on L051 extension

* clean up printing and add comments

* @tunetheweb's comments + switch from name to raw_upper for clarity

* add simple capitalisation to L051

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-28 10:22:08 +00:00
Fabian Winter
2070760e4b T-SQL: Allow aliases with = (#2727)
* T-SQL: Allow aliases with =

Issue: 2552

* Fix

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 18:26:44 +00:00
Fabian Winter
cb90c89c89 T-SQL: Support table variables (#2728)
Issue: 2699

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 16:57:56 +00:00
Juho Autio
28187909d1 Support for checking violations in YAML rule tests (#2718)
* Support for checking violations in YAML rule tests

Adds a new optional feature for the YAML rule test cases (run with yaml_test_cases_test.py):
- `violations` or `violations_after_fix` can be defined in YAML to check for specific failures

Taking `violations_after_fix` into use for the tricky cases of L004. With that, the python test with the same coverage is deleted.

Also adding the `violations` assertion for one "fail_str only" case to demonstrate how that works.

* Default to test rule if code is omitted

* Format newlines in L004.yml

* Simplify assertion code

* Revert "Simplify assertion code"

This reverts commit d7137101d8.

* Ignore missing coverage

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 16:37:56 +00:00
Barry Hart
3a72de5f98 Roll back PR #2610 (#2726)
* Roll back PR #2610

* Revert changes to src/sqlfluff/core/rules/base.py

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-02-27 16:22:39 +00:00
Michael Rosenberg
d9047cd01b Redshift: Allow Whitespace Around Cast Operators (#2721)
* See if this fixes things

* Deleted allow gaps

* Update to segment

* Added test cases

* Reverse Redshift changes

* Allowed gaps for cast operators

* Added ansi and postgres whitespace coverage

* Linted

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 15:50:58 +00:00
Barry Pollard
a3be2dee00 Support database links in Oracle (#2725) 2022-02-27 15:34:34 +00:00
Barry Hart
bd3914fe34 Rule L019: Ignore comma placement violations if the adjacent code is templated (#2717)
* Rule L019: Anchor on column, not comma, to reduce templating false positives

* Don't overwrite pre-existing "core" config

* Fix failing test by rolling back one of the changes, add comments

* Fix an issue where the new anchor segment was too "big"

* More comment

* Tweak the anchor for trailing comma violations

* Tweak again

* Fix broken test

* Rework the fix so we don't change the anchor

* Add more sophisticated template handling

* Simplify the fix

* Add back a pre-existing newline that was unnecessarily removed

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 10:02:48 -05:00
Fabian Winter
8c0fecf4a3 T-SQL: Add drop constraint syntax (#2724)
Issue: #2694
2022-02-27 14:22:25 +00:00
Michael O Toole
fb2f781f87 ANSI: Support Optionally Bracketed CTE (#2716)
* OptionallyBrackedWith

Support (WITH cte AS (...))
in particular this is used in:
```
INSERT INTO schema.table
(
 WITH cte AS (...)
 SELECT ...
)

* AddTestForNestedCTE

Test nested CTEs which although stupid are valid

* Linting line len

* trailing comma linting err

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 12:17:08 +00:00
Lorin Dawson
74e79b215d unit tests for CASE clause (#2714)
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 12:01:04 +00:00
Lorin Dawson
039cee1bc5 support for window functions (#2711)
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 11:34:22 +00:00
jpers36
5eac46e654 TSQL: Add variables as options for RAISERROR parameters (#2709)
Co-authored-by: jpersons <jpersons@iuhealth.org>
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 11:16:58 +00:00
jpers36
1cff4b930d TSQL: Add OPTION clause to UPDATE (#2707)
Co-authored-by: jpersons <jpersons@iuhealth.org>
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 10:57:50 +00:00
Lorin Dawson
ea0a9909da test cases for where clause (#2704)
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 10:40:47 +00:00
Lorin Dawson
cce8d551ab test cases for table valued functions (#2703)
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 10:21:46 +00:00
jpers36
d2cdbd692c TSQL: Allow for optionally bracketed PARTITION BY elements (#2702)
Co-authored-by: jpersons <jpersons@iuhealth.org>
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-27 10:08:49 +00:00
jpers36
d1cc947afd TSQL: Fix SET TRANSACTION ISOLATION LEVEL parsing (#2701)
Co-authored-by: jpersons <jpersons@iuhealth.org>
2022-02-27 09:53:12 +00:00
Juho Autio
244c3d5996 Migrate tricky L004 tests to python (#2681)
* Migrate tricky L004 tests to python

* Adjust docstrings

* Pass rule code to lint function

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-19 06:36:46 +00:00
Barry Hart
7a5c7f8415 Core linter enhancement: Check for successful parse after applying fixes (#2657)
* Core linter enhancement: Check for successful parse after applying fixes

* Work around import error

* Refine the "reparse" logic

* L003 (indentation rule): Improve anchors for fixes to avoid corrupting parse tree

* Tweak docstring

* Work around the issue with calling parse() in apply_fixes()

* Use the correct dialect for re-parsing

* Fix how we detect and handle parse() errors after applying fixes

* Anchor placement based on start or end of slice, not the whole slice

* Move anchor adjustment logic into RuleBase, so other rules can reuse it

* Filter out meta segments when calling match()

* More tweaks to how we call parse() after fixes

* Fix a failed test

* Remove some obsolete template-related filter logic

* Update test case

* Remove some hacky logic added in this PR that's breaking things now

* Update test-only rule that was causing a parse error after fixing

* Fix anchor for inserting newline

* Fix an issue with the templated_file field on position markers

* Rework _choose_anchor_segment() to handle new segments created by "fix"

* Fix a bug in _choose_anchor_segment(): Stop before hitting tree root

* Fix some L036 issues causing test failures and/or failures on re-parse

* Fix newline placement

* Fix more test failures

* Fix two tests that were triggering post-fix parse errors

* Fix last post-fix L036 parse error

* Add deepcopy() before match()

* Remove obsolete tests (the corresponding code was obsolete, removed in this PR)

* Remove obsolete code (workaround for the bug we're fixing in this branch)

* L039 bug fix: Ignore meta segments

* Tidying

* DRY up L036

* More tidying L036

* More tidying L036

* More tidying L036

* Add docstring to _fixes_for_move_after_select_clause()

* Remove unused code

* Log warnings rather than throwing exception on re-parse error

* Coverage, missing spaces for parse error handling

* Fix crash bug found during manual testing

Co-authored-by: Barry Hart <barry.hart@mailchimp.com>
2022-02-18 20:26:28 -05:00
Lorin Dawson
ef27896c47 Spark3: Support for LATERAL VIEW clause (#2687)
* allow  named argument to accept an iterable

* updated to allow for LATERAL VIEW

* black

* use OneOf instead of list for exclude

* use get_segment to define get_eventual_alias

* remove unused imports

* PR feedback

* black

* Update src/sqlfluff/dialects/dialect_spark3.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* remove AnyNumberOf AliasExpressionSegments

* black

* remove two invalid test cases and update LateralViewClauseSegment

* refresh yml

* updates to LateralViewClauseSegment

* excldue spark3 from L026 by default

* black

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-02-18 20:36:57 +00:00
Juho Autio
0307c76ac4 Document python requirement for tox/mypy & remove basepython from conf (#2644)
* Pin python version for pre-commit hooks

Most notably this pins python version for the mypy pre-commit hook so that it's aligned

* Doc python req for tox, remove basepython

* Update CONTRIBUTING.md

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update CONTRIBUTING.md

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-18 15:27:08 +00:00
Barry Pollard
5f01cc5ddc Fix rule L011 for implicit aliases (#2683)
* Fix rule L011

* Revert unnecessary change

* Pin markupsafe
2022-02-18 15:11:30 +00:00
Barry Pollard
d6a918a6e0 Pin markupsafe to prevent CI failures (#2685)
* Pin markupsafe to prevent CI failures

* Try conditional pin

* Fix typo

* Revert attempt at conditional pin
2022-02-18 14:52:39 +00:00
Timo S
f60022410f Allow CROSS joins for Exasol (#2680)
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-17 22:06:13 +00:00
Timo S
c6b9789606 Exasol: Improve function formatting (#2678)
* Improve Exasol function formatting.

* revert unnecessary change

* Add formatting test cases to L003

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
2022-02-17 21:46:00 +00:00
jpers36
0f6981ab17 TSQL: Add indentation for CREATE INDEX/STATISTICS (#2679)
* TSQL: Add indentation for CREATE INDEX/STATISTICS

* TSQL: Add indentation for CREATE INDEX/STATISTICS

Co-authored-by: jpersons <jpersons@iuhealth.org>
2022-02-17 21:14:28 +00:00
Lorin Dawson
2e27ca0ca8 support for tablesample (#2674) 2022-02-17 08:25:59 +00:00
jpers36
6290033222 TSQL: Improve RAISERROR functionality (#2672)
* TSQL: Improve RAISERROR functionality

* TSQL: Improve RAISERROR functionality

Co-authored-by: jpersons <jpersons@iuhealth.org>
2022-02-16 21:50:34 +00:00
Seve Martinez
b89f0d972b Snowflake dialect update for MERGE INTO predicates (#2670)
* updated snowflake dialect to include predicates for merge statement not matched clause

* Update src/sqlfluff/dialects/dialect_snowflake.py

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* Update test/fixtures/dialects/snowflake/snowflake_merge_into.sql

Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>

* regenerated yaml after adding semi-colon for snowflake merge

Co-authored-by: seve martinez <seve.martinez@coinbase.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-02-16 19:47:46 +00:00
Juho Autio
fce82db906 Assert that fix_str is set (#2663)
* Assert that fix_str is set

* Update src/sqlfluff/testing/rules.py

* Update src/sqlfluff/testing/rules.py

Co-authored-by: Barry Pollard <barry@tunetheweb.com>
Co-authored-by: Barry Pollard <barry_pollard@hotmail.com>
2022-02-16 16:45:53 +00:00
4849 changed files with 408358 additions and 114152 deletions

View File

@@ -1,14 +0,0 @@
version = 1
test_patterns = [
'test/**',
]
exclude_patterns = [
'docs/**',
'util.py', # not part of the core sqlfluff code
]
[[ analyzers ]]
name = 'python'
enabled = true

View File

@@ -14,10 +14,40 @@ indent_size = 2
[*.py]
indent_size = 4
# Don't correct spacing for sql and yaml files as sometimes want them wrong for tests
[*.sql]
# Don't correct indentation for sql and yaml files as sometimes want them wrong for tests
[*.{yml,yaml,sql}]
indent_style = unset
# Some specific tests with trailing newlines
# If adding any exceptions here, make sure to add them to .pre-commit-config.yaml as well
[test/fixtures/templater/jinja_l_metas/0{01,03,04,05,07,08,11}.sql]
indent_style = unset
insert_final_newline = unset
[test/fixtures/linter/sqlfluffignore/*/*.sql]
indent_style = unset
trim_trailing_whitespace = unset
insert_final_newline = unset
[test/fixtures/config/inheritance_b/{,nested/}example.sql]
indent_style = unset
trim_trailing_whitespace = unset
insert_final_newline = unset
[trailing_newlines.sql]
indent_style = unset
trim_trailing_whitespace = unset
insert_final_newline = unset
[plugins/sqlfluff-templater-dbt/test/fixtures/dbt/dbt_project/models/my_new_project/multiple_trailing_newline.sql]
indent_style = unset
insert_final_newline = unset
[plugins/sqlfluff-templater-dbt/test/fixtures/dbt/templated_output/macro_in_macro.sql]
indent_style = unset
trim_trailing_whitespace = unset
insert_final_newline = unset
[plugins/sqlfluff-templater-dbt/test/fixtures/dbt/templated_output/{,dbt_utils_0.8.0/}last_day.sql]
indent_style = unset
trim_trailing_whitespace = unset
insert_final_newline = unset
[test/fixtures/linter/indentation_errors.sql,test/fixtures/templater/jinja_d_roundtrip/test.sql]
trim_trailing_whitespace = false
[*.rst]
indent_size = 3

5
.github/FUNDING.yml vendored
View File

@@ -12,4 +12,7 @@
# as a donation toward infrastructure and hosting costs, or to enable
# maintainers to spend more time on the project.
custom: flattr.com/github/alanmcruickshank
# For more details on how this money is used, see the GitHub sponsor
# page for sqlfluff at https://github.com/sponsors/sqlfluff.
github: sqlfluff

View File

@@ -4,8 +4,8 @@ labels: [ "enhancement" ]
body:
- type: markdown
attributes:
value: |
Use this enhancement template to suggest new features or functionality for SQLFluff. Please not
value: >
Use this enhancement template to suggest new features or functionality for SQLFluff. Please note that
missing syntax support for any of our currently supported dialects, should instead be filed as a
[Bug Report](https://github.com/sqlfluff/sqlfluff/issues/new?assignees=&labels=bug&template=bug-report.yml).

25
.github/codecov.yml vendored
View File

@@ -1,25 +0,0 @@
# Configuration file for codecov.io
# https://docs.codecov.io/docs/codecovyml-reference
codecov:
branch: main
bot: "codecov-io"
ci:
- "github.com"
max_report_age: 24
disable_default_path_fixes: no # yamllint disable-line rule:truthy
require_ci_to_pass: yes # yamllint disable-line rule:truthy
notify:
after_n_builds: 9
wait_for_ci: yes # yamllint disable-line rule:truthy
coverage:
precision: 2
round: down
range: "70...100"
status:
project:
default:
# basic
target: auto
threshold: 0%

77
.github/labeler.yml vendored Normal file
View File

@@ -0,0 +1,77 @@
ansi:
- "/(ansi)/i"
athena:
- "/(athena)/i"
bigquery:
- "/(bigquery)/i"
clickhouse:
- "/(clickhouse)/i"
databricks:
- "/(databricks)/i"
db2:
- "/(db2)/i"
duckdb:
- "/(duckdb)/i"
exasol:
- "/(exasol)/i"
greenplum:
- "/(greenplum)/i"
hive:
- "/(hive)/i"
impala:
- "/(impala)/i"
mariadb:
- "/(mariadb)/i"
materialize:
- "/(materialize)/i"
mysql:
- "/(mysql)/i"
oracle:
- "/(oracle)/i"
postgres:
- "/(postgres)/i"
redshift:
- "/(redshift)/i"
snowflake:
- "/(snowflake)/i"
soql:
- "/(soql)/i"
sparksql:
- "/(sparksql)/i"
sqlite:
- "/(sqlite)/i"
starrocks:
- "/(starrocks)/i"
t-sql:
- "/(t-sql|tsql)/i"
teradata:
- "/(teradata)/i"
trino:
- "/(trino)/i"
vertica:
- "/(vertica)/i"

18
.github/workflows/add-issue-labels.yaml vendored Normal file
View File

@@ -0,0 +1,18 @@
name: "Add Issue Labels"
on:
issues:
types: [opened]
jobs:
triage:
runs-on: ubuntu-latest
steps:
# Update .github/labeler.yml for new dialects
- uses: github/issue-labeler@v3.2
with:
configuration-path: .github/labeler.yml
include-title: 1
include-body: 0
not-before: 2023-07-06T02:54:32Z
enable-versioned-regex: 0
repo-token: ${{ github.token }}

View File

@@ -7,11 +7,16 @@ on:
branches:
- main
jobs:
release-notes:
draft-release:
runs-on: ubuntu-20.04
if: github.repository == 'sqlfluff/sqlfluff'
steps:
- name: Update release notes
uses: release-drafter/release-drafter@v5
# If it's a release PR, then we should also update
# the header and title here too.
# with:
# name: ${{ }}
# header: ${{ }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,27 +0,0 @@
name: "Check generated YAML files"
on: pull_request
jobs:
ymlchecks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install -Ur requirements.txt -Ur requirements_dev.txt
python setup.py develop
- name: Generate the YAML files
run: |
python test/generate_parse_fixture_yml.py
- name: Test the generated YAML files
run: |
if [ -n "$(git status --porcelain)" ]; then
git diff
echo "Generated YAML files do not match branch."
echo "Please run the following command to generate these:"
echo " python test/generate_parse_fixture_yml.py"
exit 1
fi

107
.github/workflows/ci-pr-comments.yml vendored Normal file
View File

@@ -0,0 +1,107 @@
# This Workflow runs in a more secure context and comments
# on pull requests.
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
name: Comment on the pull request
# Run on completion of the CI job.
# This workflow has access to write comments on PRs event when
# that PR is triggered by a forked repo.
on:
workflow_run:
workflows:
- CI
types:
- completed
jobs:
comment-on-pr:
runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request'
steps:
- name: 'Download txt artifact'
uses: actions/github-script@v6
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "txt-report"
})[0];
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/cov-report.zip', Buffer.from(download.data));
- name: Unzip Downloaded Artifact
run: unzip cov-report.zip
- name: Update PR comment with coverage report.
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// First list the existing comments
const trigger_str = 'Coverage Results';
console.log("Getting existing comments...");
const { promises: fs } = require('fs');
const issue_number = await fs.readFile('pr-number.txt', 'utf8');
console.log("Issue number: " + issue_number);
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: 'sqlfluff',
repo: 'sqlfluff',
issue_number: Number(issue_number)
}
);
let comment_id = null;
console.log("Got %d comments", comments.length);
comments.forEach(comment => {
if (comment.body.indexOf(trigger_str) >= 0) {
console.log("Found target comment ID: %d", comment.id);
comment_id = comment.id;
} else {
console.log("Comment ID %d not valid with body:\n%s.", comment.id, comment.body);
}
});
const previous_outcome = await fs.readFile('outcome.txt', 'utf8');
console.log("Previous coverage step outcome: %s", previous_outcome);
if (previous_outcome == "success\n") {
status_emoji = "✅";
} else {
status_emoji = "⚠️";
}
const content = await fs.readFile('coverage-report.txt', 'utf8');
body = "# " + trigger_str + " " + status_emoji + "\n```\n" + content + "\n```\n";
if (comment_id > 0) {
console.log("Updating comment id: %d", comment_id);
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment_id,
body: body
});
} else {
console.log("No existing comment matched, creating a new one...");
await github.rest.issues.createComment({
issue_number: Number(issue_number),
owner: context.repo.owner,
repo: context.repo.repo,
body: body
});
}

86
.github/workflows/ci-test-dbt.yml vendored Normal file
View File

@@ -0,0 +1,86 @@
#############################
## GitHub Actions CI Tests ##
#############################
#
# This is a reusable workflow to make CI tests more modular.
# See: https://docs.github.com/en/actions/using-workflows/reusing-workflows
#
# Called by ci-tests.yml
# This one does the dbt tests
#
name: Modular SQLFluff dbt test workflow
on:
workflow_call:
inputs:
python-version:
required: true
type: string
dbt-version:
required: true
type: string
coverage:
required: false
type: boolean
default: false
secrets:
gh_token:
required: true
jobs:
modular-python-test:
name: py${{ inputs.python-version }}-${{ inputs.dbt-version }}
runs-on: ubuntu-latest
env:
FORCE_COLOR: 1
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: password
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
cache: 'pip'
cache-dependency-path: |
setup.cfg
requirements_dev.txt
- name: Install dependencies
run: pip install tox
- name: Run the tests (with coverage)
if: ${{ inputs.coverage }}
run: tox -e ${{ inputs.dbt-version }} -- --cov=sqlfluff_templater_dbt plugins/sqlfluff-templater-dbt
- name: Run the tests (without coverage)
if: ${{ !inputs.coverage }}
run: tox -e ${{ inputs.dbt-version }} -- plugins/sqlfluff-templater-dbt
- name: Upload coverage data (github)
uses: actions/upload-artifact@v4
if: ${{ inputs.coverage }}
with:
name: coverage-data-py${{ inputs.python-version }}-${{ inputs.dbt-version }}
path: ".coverage.*"
if-no-files-found: ignore
include-hidden-files: true

90
.github/workflows/ci-test-python.yml vendored Normal file
View File

@@ -0,0 +1,90 @@
#############################
## GitHub Actions CI Tests ##
#############################
#
# This is a reusable workflow to make CI tests more modular.
# See: https://docs.github.com/en/actions/using-workflows/reusing-workflows
#
# Called by ci-tests.yml
# This one does the python tests
#
name: Modular SQLFluff python test workflow
on:
workflow_call:
inputs:
python-version:
required: true
type: string
marks:
required: false
type: string
default: "not integration"
coverage:
required: false
type: boolean
default: false
secrets:
gh_token:
required: true
jobs:
modular-python-test:
runs-on: ubuntu-latest
name: py${{ inputs.python-version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
cache: 'pip'
cache-dependency-path: |
setup.cfg
requirements_dev.txt
- name: Install dependencies
run: pip install tox
- name: Parse Python Version
id: py_version
run: |
PYVERSION=$(echo "${{ inputs.python-version }}" | sed -e 's/\.//g')
echo "PYVERSION=$PYVERSION" >> $GITHUB_OUTPUT
# Run test process (with or without coverage).
# Arguments after the "--" are passed through to pytest:
# --cov=... The library to include in coverage reporting.
# -n 2 Runs with two parallel processes.
# test The path to detect tests within.
# -m ... The pytest marks to filter tests.
# --durations=16 Displays the 16 slowest runs to help with performance debugging.
- name: Run the tests (with coverage)
# NOTE: We have a separate job for coverage reporting because
# it impacts performance and slows the test suite significantly.
if: ${{ inputs.coverage }}
run: tox -e py${{ steps.py_version.outputs.PYVERSION }} -- --cov=sqlfluff -n 2 test -m "${{ inputs.marks }}" --durations=16
- name: Run the tests (without coverage)
if: ${{ !inputs.coverage }}
run: tox -e py${{ steps.py_version.outputs.PYVERSION }} -- -n 2 test -m "${{ inputs.marks }}" --durations=16
- name: Rename coverage files with suffix
# NOTE: We do this because we're using the same tox environment for multiple
# test jobs and we need to make sure that their coverage files don't collide.s
id: cov_suffix
if: ${{ inputs.coverage }}
run: |
COVSUFFIX=$(echo "${{ inputs.marks }}" | sed -e 's/ /-/g')
echo "COVSUFFIX=$COVSUFFIX" >> $GITHUB_OUTPUT
for file in .coverage.*; do mv "$file" "$file.$COVSUFFIX"; done;
- name: Upload coverage data (github)
uses: actions/upload-artifact@v4
if: ${{ inputs.coverage }}
with:
name: coverage-data-py${{ inputs.python-version }}-${{ inputs.marks }}
path: ".coverage.*"
if-no-files-found: ignore
include-hidden-files: true

View File

@@ -2,118 +2,195 @@
## GitHub Actions CI Tests ##
#############################
#
# Based on our old CircleCI config
#
# This can be kicked off manually in the Actions tab of GitHub
# It will also run nightly at 2pm
# It will run on any pull request, except non-code changes
# (images, markdown files, )
#
name: CI Tests
name: CI
on:
workflow_dispatch:
schedule:
# 2am each night
- cron: '00 2 * * *'
# Don't use pull_request_target here. See:
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
pull_request:
push:
branches:
- main
merge_group:
# Merge Queue checks requested. This feature is still in beta
# from Github and so may need updating later.
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#merge_group
types: [checks_requested]
jobs:
linting:
runs-on: ubuntu-latest
strategy:
matrix:
jobs: [ 'linting', 'doclinting', 'docbuild', 'yamllint' ]
name: ${{ matrix.jobs }} tests
job:
[
"linting",
"doclinting",
"docbuild",
"yamllint",
"mypy",
"mypyc",
"doctests",
]
include:
# Default to most recent python version
- python-version: "3.13"
# As at 2024-10-10, docbuild fails on 3.13, so fall back to 3.12
- job: docbuild
python-version: "3.12"
name: ${{ matrix.job }} tests
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install tox
- name: Run the tests
run: |
tox -e ${{ matrix.jobs }}
ruleslinting:
runs-on: ubuntu-latest
name: Rules critical errors tests
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install tox
pip install .
- name: Run the tests
run: |
tox -e ruleslinting
python-version-tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.7', '3.8', '3.9', '3.10' ]
name: Python ${{ matrix.python-version }} tests
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install tox
- name: Set Tox Python Param
run: |
echo 'TOXENV<<EOF' >> $GITHUB_ENV
echo "${{ matrix.python-version }}" | sed "s/\.//" | sed "s/^/py/" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
run: pip install tox
- name: Run the tests
run: |
tox -e ${{ env.TOXENV }} -- -n 2 test
- name: Upload Coverage Report
uses: codecov/codecov-action@v1
with:
files: ./coverage.xml
other-tests:
runs-on: ubuntu-latest
run: tox -e ${{ matrix.job }}
# Test with coverage tracking on most recent python (py313).
python-version-tests:
name: Python Tests
strategy:
matrix:
jobs: [ 'bench', 'mypy' ]
name: ${{ matrix.jobs }} tests
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12", "3.13" ]
include:
# Default to test without coverage tracking on older python versions.
# This saves time, as testing without coverage tracking is faster.
- coverage: false
# Override coverage to be true for most recent python version.
- python-version: "3.13"
coverage: true
permissions:
contents: read
pull-requests: write
uses: ./.github/workflows/ci-test-python.yml
with:
python-version: ${{ matrix.python-version }}
coverage: ${{ matrix.coverage }}
secrets:
gh_token: ${{ secrets.github_token }}
dbt-tests:
name: dbt Plugin Tests
strategy:
fail-fast: false
matrix:
dbt-version:
- dbt140
- dbt150
- dbt160
- dbt170
- dbt180
- dbt190
include:
# Default to python 3.12 for dbt tests.
# * Python 3.13 not supported yet.
# * Looks like it's due to psycopg2 support as of 2024-10-10
- python-version: "3.12"
# For dbt 1.4 - 1.6 override to python 3.11
- dbt-version: dbt140
python-version: "3.11"
- dbt-version: dbt150
python-version: "3.11"
- dbt-version: dbt160
python-version: "3.11"
permissions:
contents: read
pull-requests: write
uses: ./.github/workflows/ci-test-dbt.yml
with:
python-version: ${{ matrix.python-version }}
dbt-version: ${{ matrix.dbt-version }}
coverage: true
secrets:
gh_token: ${{ secrets.github_token }}
dialect-tests:
name: Dialect ${{ matrix.marks }}
strategy:
matrix:
include:
# This runs the bulk of the dialect _parsing_ tests.
#
# It's run as a separate job as takes longer than the CI jobs and allows
# them to be rerun separately if GitHub Actions or Coverage is experiencing
# issues.
- marks: "parse_suite"
# We test coverage here for some parsing routines.
coverage: true
# This lints all our dialect fixtures to check rules can handle a variety
# of SQL and don't error out badly.
#
# It's run as a separate job as takes longer than the CI jobs and allows
# them to be rerun separately if GitHub Actions or Coverage is experiencing
# issues.
- marks: "fix_suite"
coverage: false
# This lints all our rules fixtures to check rules.
#
# It's run as a separate job as takes longer than the CI jobs and allows
# them to be rerun separately if GitHub Actions or Coverage is experiencing
# issues.
- marks: "rules_suite"
coverage: true
permissions:
contents: read
pull-requests: write
uses: ./.github/workflows/ci-test-python.yml
with:
python-version: "3.13"
marks: ${{ matrix.marks }}
coverage: ${{ matrix.coverage }}
secrets:
gh_token: ${{ secrets.github_token }}
ymlchecks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.13'
- name: Install dependencies
run: |
pip install tox
- name: Set Tox Params
pip install -r requirements_dev.txt
pip install -e .
- name: Generate the YAML files
run: |
echo "TOXENV=${{ matrix.jobs }}" >> $GITHUB_ENV
- name: Run the tests
env:
SQLFLUFF_BENCHMARK_API_KEY: ${{ secrets.SQLFLUFF_BENCHMARK_API_KEY }}
python test/generate_parse_fixture_yml.py
- name: Test the generated YAML files
run: |
tox -e ${{ env.TOXENV }}
if [ -n "$(git status --porcelain)" ]; then
git diff
echo "Generated YAML files do not match branch."
echo "Please run the following command to generate these:"
echo " python test/generate_parse_fixture_yml.py"
exit 1
fi
examples:
runs-on: ubuntu-latest
name: example tests
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.13'
- name: Install dependencies
run: |
pip install -e .
@@ -125,66 +202,27 @@ jobs:
echo "Running $file"
python "$file"
done
dbt-tests:
runs-on: ubuntu-latest
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: password
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
strategy:
matrix:
dbt-version: [ 'dbt020', 'dbt021', 'dbt100' ]
name: DBT Plugin ${{ matrix.dbt-version }} tests
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install dependencies
run: |
pip install tox
- name: Run the tests
run: |
tox -e ${{ matrix.dbt-version }} -- plugins/sqlfluff-templater-dbt
- name: Upload Coverage Report
uses: codecov/codecov-action@v1
with:
files: ./coverage.xml
python-windows-tests:
runs-on: windows-latest
name: Python 3.8 Windows tests
name: Python 3.13 Windows tests
steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: "3.13"
- name: List Env
shell: bash
run: |
env | sort
- name: Install dependencies
shell: bash
run: |
pip install tox
run: pip install tox
- name: Run the tests
shell: bash
# Set python temp dir in working dir as on GitHub Actions Windows
@@ -192,14 +230,18 @@ jobs:
# working dir on D drive which causes problems.
run: |
mkdir temp_pytest
python -m tox -e winpy -- -n 2 test
- name: Upload Coverage Report
uses: codecov/codecov-action@v1
python -m tox -e winpy -- --cov=sqlfluff -n 2 test -m "not integration"
- name: Upload coverage data (github)
uses: actions/upload-artifact@v4
with:
files: ./coverage.xml
name: coverage-data-winpy3.13
path: ".coverage.*"
if-no-files-found: ignore
include-hidden-files: true
python-windows-dbt-tests:
runs-on: windows-latest
name: DBT Plugin Python 3.8 Windows tests
name: dbt Plugin Python 3.12 Windows tests
steps:
- name: Start PostgreSQL on Windows
run: |
@@ -213,25 +255,22 @@ jobs:
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.8'
# NOTE: As of 2024-10-10, dbt does not yet support python 3.13.
python-version: "3.12"
- name: Install dependencies
shell: bash
run: |
pip install tox
run: pip install tox
- name: Run the tests
shell: bash
# Do not set explicitly temp dir for dbt as causes problems
# None of these test need temp dir set
run: |
python -m tox -e dbt100-winpy -- plugins/sqlfluff-templater-dbt
- name: Upload Coverage Report
uses: codecov/codecov-action@v1
with:
files: ./coverage.xml
python -m tox -e dbt180-winpy -- plugins/sqlfluff-templater-dbt
pip-test-pull-request:
# Test that using pip install works as we've missed
# some dependencies in the past - see #1842
@@ -240,10 +279,10 @@ jobs:
name: pip install tests
steps:
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: actions/checkout@v2
python-version: "3.13"
- uses: actions/checkout@v4
- name: Install dependencies
run: |
pip install .
@@ -252,13 +291,69 @@ jobs:
sqlfluff --version
- name: Run a simple select parse test via stdin
run: |
echo "select 1" | sqlfluff parse -
echo "select 1" | sqlfluff parse --dialect=ansi -
- name: Run a simple select lint test via stdin
run: |
echo "select 1" | sqlfluff lint -
echo "select 1" | sqlfluff lint --dialect=ansi -
- name: Run a simple select parse test via file
run: |
sqlfluff parse <(echo "select 1")
sqlfluff parse --dialect=ansi <(echo "select 1")
- name: Run a simple select lint test via file
run: |
sqlfluff lint <(echo "select 1")
sqlfluff lint --dialect=ansi <(echo "select 1")
coverage_check:
name: Combine & check 100% coverage.
runs-on: ubuntu-latest
needs: [python-version-tests, dbt-tests, python-windows-tests, dialect-tests]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- run: python -m pip install --upgrade coverage[toml]
- name: Download coverage data.
uses: actions/download-artifact@v4
with:
pattern: coverage-data-*
merge-multiple: true
- name: Combine coverage & fail if it's <100%.
id: report_coverage
# NOTE: Setting the pipefail option here means that even when
# piping the output to `tee`, we still get the exit code of the
# `coverage report` command.
run: |
set -o pipefail
python -m coverage combine
python -m coverage html --skip-covered --skip-empty
python -m coverage report --fail-under=100 --skip-covered --skip-empty -m | tee coverage-report.txt
- name: Upload HTML report if check failed.
uses: actions/upload-artifact@v4
with:
name: html-report
path: htmlcov
if: failure() && github.event_name == 'pull_request'
- name: Stash PR Number.
if: always() && github.event_name == 'pull_request'
# NOTE: We do this so we know what PR to comment on when we pick up the report.
run: |
echo ${{ github.event.number }} > ./pr-number.txt
echo ${{ steps.report_coverage.outcome }} > ./outcome.txt
- name: Upload TXT report always (to add as comment to PR).
# NOTE: We don't actually comment on the PR from here, we'll do that in
# a more secure way by triggering a more secure workflow.
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
uses: actions/upload-artifact@v4
with:
name: txt-report
path: |
coverage-report.txt
pr-number.txt
outcome.txt
if: always() && github.event_name == 'pull_request'

View File

@@ -0,0 +1,71 @@
name: Create release pull request
on:
workflow_dispatch:
inputs:
newVersionNumber:
description: 'New version number'
required: true
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Abort if branch already exists
run: |
_check_branch=$(git ls-remote --heads origin prep-${{ github.event.inputs.newVersionNumber }})
if [[ -z ${_check_branch} ]]; then
echo "Release branch doesn't exist yet, continuing"
else
echo "Release branch already exists, aborting. Run the Python release script locally."
exit 1
fi
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install requests click pyyaml ghapi
- name: Prepare release
run: |
python util.py release ${{ github.event.inputs.newVersionNumber }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY_OWNER: ${{ secrets.GITHUB_REPOSITORY_OWNER }}
- name: Create pull request
uses: peter-evans/create-pull-request@v4
with:
delete-branch: true
branch: prep-${{ github.event.inputs.newVersionNumber }}
commit-message: "Bump to version ${{ github.event.inputs.newVersionNumber }}"
title: Prep version ${{ github.event.inputs.newVersionNumber }}
body: |
Prepare version ${{ github.event.inputs.newVersionNumber }}
Please add all merged changes from [Release Draft][1] to
the CHANGELOG.md file
- Auto-generated by [create-pull-request][2] GitHub Action
[1]: https://github.com/sqlfluff/sqlfluff/releases
[2]: https://github.com/peter-evans/create-pull-request
labels: |
release
skip-changelog
- name: Update release title and tag
uses: release-drafter/release-drafter@v5
with:
# NOTE: We should eventually actually populate the date here, but that
# will most likely change before the new pull request actually gets
# merged, so we just add "YYYY-MM-DD" for now as a placeholder.
name: "[${{ github.event.inputs.newVersionNumber }}] - YYYY-MM-DD"
tag: ${{ github.event.inputs.newVersionNumber }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

53
.github/workflows/pre-commit.yml vendored Normal file
View File

@@ -0,0 +1,53 @@
---
name: pre-commit
on:
pull_request:
push:
jobs:
pre-commit:
runs-on: ubuntu-latest
env:
RAW_LOG: pre-commit.log
CS_XML: pre-commit.xml
SKIP: no-commit-to-branch
steps:
- run: sudo apt-get update && sudo apt-get install cppcheck
if: false
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
if: false
with:
cache: pip
python-version: 3.12.1
- run: python -m pip install pre-commit
- uses: actions/cache/restore@v4
with:
path: ~/.cache/pre-commit/
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml')
}}
- name: Run pre-commit hooks
run: |
set -o pipefail
pre-commit gc
pre-commit run --show-diff-on-failure --color=always --all-files | tee ${RAW_LOG}
- name: Convert Raw Log to Checkstyle format (launch action)
uses: mdeweerd/logToCheckStyle@v2024.3.5
if: ${{ failure() }}
with:
in: ${{ env.RAW_LOG }}
out: ${{ env.CS_XML }}
- uses: actions/cache/save@v4
if: ${{ ! cancelled() }}
with:
path: ~/.cache/pre-commit/
key: pre-commit-4|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml')
}}
- name: Provide log as artifact
uses: actions/upload-artifact@v4
if: ${{ ! cancelled() }}
with:
name: precommit-logs
path: |
${{ env.RAW_LOG }}
${{ env.CS_XML }}
retention-days: 2

View File

@@ -10,10 +10,10 @@ jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.7"
python-version: "3.10"
- name: Install Dependencies
run: |
@@ -28,8 +28,8 @@ jobs:
run: cp -r plugins/sqlfluff-templater-dbt/dist/. dist/
- name: Publish Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_DBT_TEMPLATER_TOKEN }}
skip_existing: true
skip-existing: true

View File

@@ -25,15 +25,15 @@ jobs:
# Setup QEMU and Buildx to allow for multi-platform builds.
- name: Set up QEMU
id: docker_qemu
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: docker_buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
# Authenticate with DockerHub.
- name: Login to DockerHub
id: docker_login
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
@@ -41,7 +41,7 @@ jobs:
# Build amd64 image to use in the integration test.
- name: Build and export to Docker
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
load: true
tags: ${{ env.TEST_TAG }}
@@ -53,13 +53,13 @@ jobs:
id: docker_test
run: |
echo "SELECT 1" > test.sql
docker run --rm -i -v $PWD:/sql ${{ env.TEST_TAG }} lint /sql/test.sql
docker run --rm -i -v $PWD:/sql ${{ env.TEST_TAG }} lint --dialect ansi /sql/test.sql
# Build arm64 image (amd64 is cached from docker_build step) and export to DockerHub.
# N.B. We tag this image as both latest and with its version number.
- name: Build and push
id: docker_build_push
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
push: true
platforms: linux/amd64,linux/arm64

View File

@@ -10,10 +10,10 @@ jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.7"
python-version: "3.10"
- name: Install Dependencies
run: |
@@ -23,8 +23,8 @@ jobs:
run: tox -e build-dist
- name: Publish Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
skip_existing: true
skip-existing: true

18
.gitignore vendored
View File

@@ -13,6 +13,7 @@ build
_build
dist
.pytest_cache
/sqlfluff-*
# Ignore the Environment
env
@@ -34,15 +35,30 @@ test-reports
# Ignore root testing sql & python files
/test*.sql
/test*.py
/test*.txt
/.hypothesis/
# Ignore dbt outputs from testing
/target
# Ignore any timing outputs
/*.csv
# Ignore conda environment.yml contributors might be using and direnv config
environment.yml
.envrc
**/*FIXED.sql
*.prof
# Ignore temp packages.yml generated during testing.
plugins/sqlfluff-templater-dbt/test/fixtures/dbt/dbt_project/packages.yml
# VSCode
.vscode
*.code-workspace
# Emacs
*~
# Mypyc outputs
*.pyd
*.so

View File

@@ -1,49 +1,95 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.5.0
hooks:
- id: no-commit-to-branch
args: [--branch, main]
# If adding any exceptions here, make sure to add them to .editorconfig as well
- id: end-of-file-fixer
exclude: (.*\.sql$|test/fixtures/linter/sqlfluffignore/path_c)
exclude: |
(?x)^
(
test/fixtures/templater/jinja_l_metas/0(0[134578]|11).sql|
test/fixtures/linter/sqlfluffignore/[^/]*/[^/]*.sql|
test/fixtures/config/inheritance_b/(nested/)?example.sql|
(.*)/trailing_newlines.sql|
plugins/sqlfluff-templater-dbt/test/fixtures/dbt.*/dbt_project/models/my_new_project/multiple_trailing_newline.sql|
plugins/sqlfluff-templater-dbt/test/fixtures/dbt.*/templated_output/macro_in_macro.sql|
plugins/sqlfluff-templater-dbt/test/fixtures/dbt.*/templated_output/(dbt_utils_0.8.0/)?last_day.sql|
test/fixtures/linter/indentation_errors.sql|
test/fixtures/templater/jinja_d_roundtrip/test.sql
)$
- id: trailing-whitespace
exclude: (.*\.sql$|test/fixtures/linter/sqlfluffignore/path_c)
exclude: |
(?x)^(
test/fixtures/linter/indentation_errors.sql|
test/fixtures/templater/jinja_d_roundtrip/test.sql|
test/fixtures/config/inheritance_b/example.sql|
test/fixtures/config/inheritance_b/nested/example.sql|
plugins/sqlfluff-templater-dbt/test/fixtures/dbt.*/templated_output/macro_in_macro.sql|
plugins/sqlfluff-templater-dbt/test/fixtures/dbt.*/templated_output/last_day.sql|
plugins/sqlfluff-templater-dbt/test/fixtures/dbt.*/templated_output/dbt_utils_0.8.0/last_day.sql|
test/fixtures/linter/sqlfluffignore/
)$
- repo: https://github.com/psf/black
rev: 22.1.0
rev: 24.2.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.931
rev: v1.13.0
hooks:
- id: mypy
args: [--ignore-missing-imports]
additional_dependencies: [
types-toml,
types-pkg_resources,
types-chardet,
types-appdirs,
types-colorama,
types-pyyaml,
types-regex,
]
additional_dependencies:
# NOTE: These dependencies should be the same as the `types-*` dependencies in
# `requirements_dev.txt`. If you update these, make sure to update those too.
[
types-toml,
types-chardet,
types-colorama,
types-pyyaml,
types-regex,
types-tqdm,
# Type stubs are obvious to import, but some dependencies also define their own
# types directly (e.g. jinja). pre-commit doesn't actually install the python
# package, and so doesn't automatically install the dependencies from
# `pyproject.toml` either. We include them here to make sure mypy can function
# properly.
jinja2,
pathspec,
pytest, # and by extension... pluggy
click,
platformdirs
]
files: ^src/sqlfluff/.*
# The mypy pre-commit hook by default sets a few arguments that we don't normally
# use. To undo that we reset the `args` to be empty here. This is important to
# ensure we don't get conflicting results from the pre-commit hook and from the
# CI job.
args: []
- repo: https://github.com/pycqa/flake8
rev: 4.0.1
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies: [
flake8-black>=0.2.4,
flake8-docstrings,
]
additional_dependencies: [flake8-black>=0.3.6]
- repo: https://github.com/pycqa/doc8
rev: 0.10.1
rev: v1.1.1
hooks:
- id: doc8
args: [
--file-encoding,
utf8,
]
args: [--file-encoding, utf8]
files: docs/source/.*\.rst$
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.26.3
rev: v1.35.1
hooks:
- id: yamllint
args: [-c=.yamllint]
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: "v0.3.2"
hooks:
- id: ruff
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
exclude: (?x)^(test/fixtures/.*|pyproject.toml)$
additional_dependencies: [tomli]

View File

@@ -1,19 +1,26 @@
- id: sqlfluff-lint
name: sqlfluff-lint
entry: sqlfluff lint
# Set `--processes 0` to use maximum parallelism
# - `--disable-progress-bar` pre-commit suppresses logging already
# this can cause an unneeded slow down.
entry: sqlfluff lint --processes 0 --disable-progress-bar
language: python
description: 'Lints sql files with `SQLFluff`'
description: "Lints sql files with `SQLFluff`"
types: [sql]
require_serial: true
additional_dependencies: []
- id: sqlfluff-fix
name: sqlfluff-fix
# Needs to use "--force" to disable confirmation
# By default all the rules are applied
entry: sqlfluff fix --force
# Set a couple of default flags:
# - `--show-lint-violations` shows issues to not require running `sqlfluff lint`
# - `--processes 0` to use maximum parallelism
# - `--disable-progress-bar` pre-commit suppresses logging already
# this can cause an unneeded slow down.
# By default, this hook applies all rules.
entry: sqlfluff fix --show-lint-violations --processes 0 --disable-progress-bar
language: python
description: 'Fixes sql lint errors with `SQLFluff`'
description: "Fixes sql lint errors with `SQLFluff`"
types: [sql]
require_serial: true
additional_dependencies: []

View File

@@ -15,9 +15,16 @@ formats: []
# Optionally set the version of Python and requirements required to build your docs.
# In our case we need both the docs requirements and the package itself.
python:
version: 3.7
install:
- requirements: requirements.txt
- requirements: docs/requirements.txt
- method: setuptools
- method: pip
path: .
build:
os: ubuntu-22.04
tools:
python: "3.11"
jobs:
# Before building, generate the rule & dialect docs
pre_build:
- python docs/generate-auto-docs.py

File diff suppressed because it is too large Load Diff

View File

@@ -6,7 +6,7 @@
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
identity and expression, level of experience, education, socioeconomic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.

View File

@@ -25,12 +25,11 @@ for the wiki.
:star2: **Fifth** - if you are so inclined - pull requests on the core codebase
are always welcome. Dialect additions are often a good entry point for new
contributors, and we have
[a wiki page](https://github.com/sqlfluff/sqlfluff/wiki/Contributing-Dialect-Changes)
contributors, and we have [a set of guides](https://docs.sqlfluff.com/en/stable/perma/guides.html)
to help you through your first contribution. Bear in mind that all the tests
should pass, and test coverage should not decrease unduly as part of the
changes which you make. You may find it useful to familiarise yourself with the
[architectural principles here](https://docs.sqlfluff.com/en/latest/architecture.html)
[architectural principles here](https://docs.sqlfluff.com/en/stable/perma/architecture.html)
and with the [current documentation here](https://docs.sqlfluff.com).
## How The Community Works
@@ -82,13 +81,25 @@ changes.
### Developing and Running SQLFluff Locally
The simplest way to set up a development environment is to use `tox`.
First ensure that you have tox installed (windows users may have to replace `python3` with `py`):
```shell
python3 -m pip install -U tox
```
#### Requirements
A virtual environment can then be created and activated by running:
The simplest way to set up a development environment is to use `tox`.
First ensure that you have tox installed:
```shell
python3.8 -m pip install -U tox
```
**IMPORTANT:** `tox` must be installed with a minimum of Python 3.8 as
the `mypy` checks are incompatible with 3.7. Those using newer versions of
Python may replace `python3.8` as necessary (the test suite runs primarily
under 3.12 for example).
Note: Unfortunately tox does not currently support setting just a minimum
Python version (though this may be be coming in tox 4!).
#### Creating a virtual environment
A virtual environment can then be created and activated by running (check
the [requirements](#requirements) before running this):
```shell
tox -e dbt021-py38 --devenv .venv
source .venv/bin/activate
@@ -102,14 +113,15 @@ choose one of the dbt environments.)
Windows users should call `.venv\Scripts\activate` rather than `source .venv/bin/activate`.
This virtual environment will already have the package installed in editable mode for you, as well as
`requirements_dev.txt` and `plugins/sqlfluff-plugin-example`. Additionally if a dbt virtual environment
was specified, you will also have `dbt-core`, `dbt-postgres`, and `plugins/sqlfluff-templater-dbt` available.
This virtual environment will already have the package installed in editable
mode for you, as well as `requirements_dev.txt` and `plugins/sqlfluff-plugin-example`.
Additionally if a dbt virtual environment was specified, you will also have
`dbt-core`, `dbt-postgres`, and `plugins/sqlfluff-templater-dbt` available.
### Wiki
We have a [GitHub wiki](https://github.com/sqlfluff/sqlfluff/wiki) with some
more long form tutorials for contributors, particualrly those new to SQLFluff
more long form tutorials for contributors, particularly those new to SQLFluff
or contributing to open source. We welcome
[contributions, suggestions or requests](https://github.com/sqlfluff/sqlfluff/issues/2104)
for the wiki.
@@ -124,13 +136,14 @@ but you'll need to do each one explicitly. e.g.
pip install -e plugins/sqlfluff-templater-dbt/.
```
> NOTE: For packages intended to be installed like this, the source code must be directy
> NOTE: For packages intended to be installed like this, the source code must be directly
> within a subdirectory with the name of the package and not in a subdirectory such as
> src. This is due to a restriction in the implementation of setup.py in editable mode.
### Testing
To test locally, SQLFluff uses `tox`. The test suite can be run via:
To test locally, SQLFluff uses `tox` (check the [requirements](#requirements)!).
The test suite can be run via:
```shell
tox
@@ -160,7 +173,7 @@ faster while working on an issue, before running full tests at the end.
For example, you can run specific tests by making use of the `-k` option in `pytest`:
```
tox -e py38 -- -k L012 test
tox -e py38 -- -k AL02 test
```
Alternatively, you can also run tests from a specific directory or file only:
@@ -175,9 +188,67 @@ sqlfluff parse test.sql
```
(ensure your virtual environment is activated first).
#### How to use and understand the test suite
When developing for SQLFluff, you may not need (or wish) to run the whole test
suite, depending on what you are working on. Here are a couple of scenarios
for development, and which parts of the test suite you may find most useful.
1. For dialect improvements (i.e. changes to anything in [src/sqlfluff/dialects](./src/sqlfluff/dialects))
you should not need to continuously run the full core test suite. Running
either `tox -e generate-fixture-yml` (if using tox), or setting up a python
virtualenv and running `test/generate_parse_fixture_yml.py` directly will
usually be sufficient. Both of these options accept arguments to restrict
runs to specific dialects to further improve iteration speed. e.g.
- `tox -e generate-fixture-yml -- -d mysql` will run just the mysql tests.
- `python test/generate_parse_fixture_yml.py -d mysql` will do the same.
2. Developing for the dbt templater should only require running the dbt test
suite (see below).
3. Developing rules and rule plugins there are a couple of scenarios.
- When developing a new rule or working with a more isolated rule, you
should only need to run the tests for that rule. These are usually what
are called the _yaml tests_. This refers to a body of example sql
statements and potential fixes defined in a large set of yaml files
found in [test/fixtures/rules/std_rule_cases](./test/fixtures/rules/std_rule_cases).
The easiest way to run these is by calling that part of the suite
directly and filtering to just that rule. For example:
- `tox -e py39 -- test/rules/yaml_test_cases_test.py -k AL01`
- `pytest test/rules/yaml_test_cases_test.py -k AL01`
- When developing on some more complicated rules, or ones known to
have interactions with other rules, there are a set of rule fixing
tests which apply a set combination of those rules. These are best
run via the `autofix` tests. For example:
- `tox -e py39 -- test/rules/std_fix_auto_test.py`
- `pytest test/rules/std_fix_auto_test.py`
- Potentially even the full rules suite `tox -e py39 -- test/rules`
- A small number of core rules are also used in making sure that inner
parts of SQLFluff are also functioning. This isn't great isolation
but does mean that occasionally you may find side effects of your
changes in the wider test suite. These can usually be caught by
running the full `tox -e py39` suite as a final check (or using the
test suite on GitHub when posting your PR).
4. When developing the internals of SQLFluff (i.e. anything not
already mentioned above), the test suite typically mirrors the structure
of the internal submodules of sqlfluff:
- When working with the CLI, the `sqlfluff.cli` module has a test suite
called via `tox -e py39 -- test/cli`.
- When working with the templaters (i.e. `sqlfluff.core.templaters`), the
corresponding test suite is found via `tox -e py39 -- test/core/templaters`.
- This rough guidance and may however not apply for all of the internals.
For example, changes to the internals of the parsing module (`sqlfluff.core.parser`)
are very likely to have knock-on implications across the rest of the test
suite and it may be necessary to run the whole thing. In these
situations however you can usually work slowly outward, for example:
1. If your change is to the `AnyOf()` grammar, first running `tox -e py39 -- test/core/parser/grammar_test.py` would be wise.
2. ...followed by `tox -e py39 -- test/core/parser` once the above is passing.
3. ...and then `tox -e py39 -- test/core`.
4. ...and finally the full suite `tox -e py39`.
#### dbt templater tests
The dbt templater tests require a locally running Postgres instance. See the required connection parameters in `plugins/sqlfluff-templater-dbt/test/fixtures/dbt/profiles.yml`. We recommend using https://postgresapp.com/.
The dbt templater tests require a locally running Postgres instance. See the
required connection parameters in `plugins/sqlfluff-templater-dbt/test/fixtures/dbt/profiles.yml`.
We recommend using https://postgresapp.com/.
To run the dbt-related tests you will have to explicitly include these tests:
@@ -199,8 +270,8 @@ Docker Compose environment. It's a simple two-container configuration:
Steps to use the Docker Compose environment:
* Install Docker on your machine.
* Run `plugins/sqlfluff-templater-dbt/docker/startup` to create the containers.
* Run `plugins/sqlfluff-templater-dbt/docker/shell` to start a bash session in the `app` container.
* Manually edit the `host` value in `plugins/sqlfluff-templater-dbt/test/fixtures/dbt/profiles_yml/profiles.yml`, changing it to `postgres`. (This will likely be automated somehow in the future.)
* Run `plugins/sqlfluff-templater-dbt/docker/shell` to start a bash session
in the `app` container.
Inside the container, run:
```
@@ -209,12 +280,23 @@ py.test -v plugins/sqlfluff-templater-dbt/test/
### Pre-Commit Config
For development convenience we also provide a `.pre-commit-config.yaml` file to allow the user to install a selection of pre-commit hooks via `tox -e pre-commit -- install`. These hooks can help the user identify and fix potential linting/typing violations prior to committing their code and therefore reduce having to deal with these sort of issues during code review.
For development convenience we also provide a `.pre-commit-config.yaml` file
to allow the user to install a selection of pre-commit hooks by running (check
the [requirements](#requirements) before running this):
```
tox -e pre-commit -- install
```
These hooks can help the user identify and fix potential linting/typing
violations prior to committing their code and therefore reduce having to deal
with these sort of issues during code review.
### Documentation Website
Documentation is built using Sphinx with some pages being built based on the source code.
See the [Documentation Website README.md](./docs/README.md) file for more information on how to build and test this.
Documentation is built using Sphinx with some pages being built based on the
source code. See the [Documentation Website README.md](./docs/README.md) file
for more information on how to build and test this.
### Building Package
@@ -224,26 +306,81 @@ whenever a new release is published to GitHub.
#### Release checklist:
The [release page](https://github.com/sqlfluff/sqlfluff/releases) shows maintainers all merges since last release. Once we have a long enough list, we should prepare a release, following below checklist:
The [release page](https://github.com/sqlfluff/sqlfluff/releases) shows
maintainers all merges since last release. Once we have a long enough list,
we should prepare a release.
- [ ] Change the version in `setup.cfg` and `plugins/sqlfluff-templator-dbt/setup.cfg`
A release PR can be created by maintainers via the
["Create release pull request" GitHub Action](https://github.com/sqlfluff/sqlfluff/actions/workflows/create-release-pull-request.yaml).
As further PRs are merged, we may need to rerun the release script again
(or alternatively just manually updating the branch). This can only be rerun
locally (the GitHub Action will exit error if the branch already exists to
prevent overwriting it).
Check out the release branch created by the GitHub Action locally and run
the script. It will preserve any `Highlights` you have added and update the
other sections with new contributions. It can be run as follows (you will
need a [GitHub Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) with "repo" permission):
```shell
source .venv/bin/activate
export GITHUB_REPOSITORY_OWNER=sqlfluff
export GITHUB_TOKEN=gho_xxxxxxxx # Change to your token with "repo" permissions.
python util.py release 2.0.3 # Change to your release number
```
Below is the old list of release steps, but many are automated by the process
described above.
- [ ] Change the version in `setup.cfg` and `plugins/sqlfluff-templater-dbt/setup.cfg`
- [ ] Update the stable_version in the `[sqlfluff_docs]` section of `setup.cfg`
- [ ] Copy the draft releases from https://github.com/sqlfluff/sqlfluff/releases to [CHANGELOG.md](CHANGELOG.md). These draft release notes have been created by a GitHub Action on each PR merge.
- [ ] If you pretend to create a new draft in GitHub and hit "Auto Generate Release Notes", then it will basically recreate these notes (though in a slightly different format), but also add a nice "First contributors" section, so can copy that "First contributors" section too and then abandon that new draft ([an issues](https://github.com/release-drafter/release-drafter/issues/1001) has been raised to ask for this in Release Drafter GitHub Action).
- [ ] Add markdown links to PRs as annoyingly GitHub doesn't do this automatically when displaying Markdown files, like it does for comments. You can use regex in most code editors to replace `\(#([0-9]*)\) @([^ ]*)$` to `[#$1](https://github.com/sqlfluff/sqlfluff/pull/$1) [@$2](https://github.com/$2)`, or if using the GitHub generated release notes then can replace `by @([^ ]*) in https://github.com/sqlfluff/sqlfluff/pull/([0-9]*)$` to `[#$2](https://github.com/sqlfluff/sqlfluff/pull/$2) [@$1](https://github.com/$1)`.
- [ ] For the new contributors section, you can replace `\* @([^ ]*) made their first contribution in https://github.com/sqlfluff/sqlfluff/pull/([0-9]*)$` with `* [@$1](https://github.com/$1) made their first contribution in [#$2](https://github.com/sqlfluff/sqlfluff/pull/$2)` to do this automatically).
- [ ] Check each issue title is clear, and if not edit issue title (which will automatically update Release notes on next PR merged, as the Draft one is recreated in full each time). We also don't use [conventional commit PR titles](https://www.conventionalcommits.org/en/v1.0.0/) (e.g. `feat`) so make them more English readible. Make same edits locally in [CHANGELOG.md](CHANGELOG.md).
- [ ] Copy the draft releases from https://github.com/sqlfluff/sqlfluff/releases
to [CHANGELOG.md](CHANGELOG.md). These draft release notes have been created
by a GitHub Action on each PR merge.
- [ ] If you pretend to create a new draft in GitHub and hit "Auto Generate Release
Notes", then it will basically recreate these notes (though in a slightly
different format), but also add a nice "First contributors" section, so can
copy that "First contributors" section too and then abandon that new draft
([an issues](https://github.com/release-drafter/release-drafter/issues/1001)
has been raised to ask for this in Release Drafter GitHub Action).
- [ ] Add markdown links to PRs as annoyingly GitHub doesn't do this automatically
when displaying Markdown files, like it does for comments. You can use regex
in most code editors to replace `\(#([0-9]*)\) @([^ ]*)$` to
`[#$1](https://github.com/sqlfluff/sqlfluff/pull/$1) [@$2](https://github.com/$2)`,
or if using the GitHub generated release notes then can replace
`by @([^ ]*) in https://github.com/sqlfluff/sqlfluff/pull/([0-9]*)$` to
`[#$2](https://github.com/sqlfluff/sqlfluff/pull/$2) [@$1](https://github.com/$1)`.
- [ ] For the new contributors section, you can replace
`\* @([^ ]*) made their first contribution in https://github.com/sqlfluff/sqlfluff/pull/([0-9]*)$`
with `* [@$1](https://github.com/$1) made their first contribution in [#$2](https://github.com/sqlfluff/sqlfluff/pull/$2)` to do this automatically).
- [ ] Check each issue title is clear, and if not edit issue title (which will
automatically update Release notes on next PR merged, as the Draft one is
recreated in full each time). We also don't use
[conventional commit PR titles](https://www.conventionalcommits.org/en/v1.0.0/)
(e.g. `feat`) so make them more English readable. Make same edits locally
in [CHANGELOG.md](CHANGELOG.md).
- [ ] Add a comment at the top to highlight the main things in this release.
- [ ] If this is a non-patch release then update the `Notable changes` section in `index.rst` with a brief summary of the new features added that made this a non-patch release.
- [ ] View the CHANGELOG in this branch on GitHub to ensure you didn't miss any link conversions or other markup errors.
- [ ] Open draft PR with those change a few days in advance to give contributors notice. Tag those with open PRs in the PR in GitHub to give them time to merge their work before the new release
- [ ] If this is a non-patch release then update the `Notable changes` section in
`index.rst` with a brief summary of the new features added that made this a
non-patch release.
- [ ] View the CHANGELOG in this branch on GitHub to ensure you didn't miss any
link conversions or other markup errors.
- [ ] Open draft PR with those change a few days in advance to give contributors
notice. Tag those with open PRs in the PR in GitHub to give them time to merge
their work before the new release
- [ ] Comment in #contributing slack channel about release candidate.
- [ ] Update the draft PR as more changes get merged.
- [ ] Get another contributor to approve the PR.
- [ ] Merge the PR when looks like we've got all were gonna get for this release.
- [ ] Go to the [releases page](https://github.com/sqlfluff/sqlfluff/releases), edit the release to be same as [CHANGELOG.md](CHANGELOG.md) (remember to remove your release PR which doesnt need to go in this). Add version tag and a title and click “Publish release”.
- [ ] Announce the release in the #general channel, with shout outs to those who contributed many, or big items.
- [ ] Announce the release on Twitter (@tunetheweb can do this or let him know your Twitter handle if you want access to Tweet on SQLFluffs behalf).
- [ ] Merge the PR when looks like we've got all were going to get for this release.
- [ ] Go to the [releases page](https://github.com/sqlfluff/sqlfluff/releases), edit
the release to be same as [CHANGELOG.md](CHANGELOG.md) (remember to remove your
release PR which doesnt need to go in this). Add version tag and a title and
click “Publish release”.
- [ ] Announce the release in the #general channel, with shout outs to those who
contributed many, or big items.
- [ ] Announce the release on Twitter (@tunetheweb can do this or let him know your
Twitter handle if you want access to Tweet on SQLFluffs behalf).
:warning: **Before creating a new release, ensure that
[setup.cfg](setup.cfg) is up-to-date with a new version** :warning:.

View File

@@ -7,23 +7,24 @@ WORKDIR /app
ENV VIRTUAL_ENV /app/.venv
RUN python -m venv $VIRTUAL_ENV
ENV PATH $VIRTUAL_ENV/bin:$PATH
RUN pip install --upgrade pip setuptools wheel
RUN pip install --no-cache-dir --upgrade pip setuptools wheel pip-tools
# Install requirements seperately
# Install requirements separately
# to take advantage of layer caching.
# N.B. we extract the requirements from setup.cfg
COPY setup.cfg .
RUN python -c "import configparser; c = configparser.ConfigParser(); c.read('setup.cfg'); print(c['options']['install_requires'])" > requirements.txt
RUN pip install --upgrade -r requirements.txt
# N.B. we extract the requirements from pyproject.toml
COPY pyproject.toml .
# Use piptools to extract requirements from pyproject.toml as described in
# https://github.com/pypa/pip/issues/11584
RUN pip-compile -o requirements.txt pyproject.toml -v --strip-extras
RUN pip install --no-cache-dir --upgrade -r requirements.txt
# Copy minimal set of SQLFluff package files.
COPY MANIFEST.in .
COPY README.md .
COPY setup.py .
COPY src ./src
# Install sqlfluff package.
RUN pip install --no-dependencies .
RUN pip install --no-cache-dir --no-dependencies .
# Switch to non-root user.
USER 5000

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2018 Alan Cruickshank
Copyright (c) 2023 Alan Cruickshank
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

137
README.md
View File

@@ -8,45 +8,96 @@
[![PyPi Status](https://img.shields.io/pypi/status/sqlfluff.svg?style=flat-square)](https://pypi.org/project/sqlfluff/)
[![PyPi Downloads](https://img.shields.io/pypi/dm/sqlfluff?style=flat-square)](https://pypi.org/project/sqlfluff/)
[![codecov](https://img.shields.io/codecov/c/gh/sqlfluff/sqlfluff.svg?style=flat-square&logo=Codecov)](https://codecov.io/gh/sqlfluff/sqlfluff)
[![CI Tests](https://github.com/sqlfluff/sqlfluff/workflows/CI%20Tests/badge.svg)](https://github.com/sqlfluff/sqlfluff/actions?query=workflow%3A%22CI+Tests%22)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/sqlfluff/sqlfluff/.github/workflows/ci-tests.yml?logo=github&style=flat-square)](https://github.com/sqlfluff/sqlfluff/actions/workflows/ci-tests.yml?query=branch%3Amain)
[![ReadTheDocs](https://img.shields.io/readthedocs/sqlfluff?style=flat-square&logo=Read%20the%20Docs)](https://sqlfluff.readthedocs.io)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/psf/black)
[![Docker Pulls](https://img.shields.io/docker/pulls/sqlfluff/sqlfluff?logo=docker&style=flat-square)](https://hub.docker.com/r/sqlfluff/sqlfluff)
[![Gurubase](https://img.shields.io/badge/Gurubase-Ask%20SQLFluff%20Guru-006BFF?style=flat-square)](https://gurubase.io/g/sqlfluff)
**SQLFluff** is a dialect-flexible and configurable SQL linter. Designed with ELT applications in mind, **SQLFluff** also works with Jinja templating and dbt. **SQLFluff** will auto-fix most linting errors, allowing you to focus your time on what matters.
**SQLFluff** is a dialect-flexible and configurable SQL linter. Designed
with ELT applications in mind, **SQLFluff** also works with Jinja templating
and dbt. **SQLFluff** will auto-fix most linting errors, allowing you to focus
your time on what matters.
## Table of Contents
1. [Dialects Supported](#dialects-supported)
2. [Templates Supported](#templates-supported)
3. [VS Code Extension](#vs-code-extension)
4. [Getting Started](#getting-started)
5. [Documentation](#documentation)
6. [Releases](#releases)
7. [SQLFluff on Slack](#sqlfluff-on-slack)
8. [SQLFluff on Twitter](#sqlfluff-on-twitter)
9. [Contributing](#contributing)
10. [Sponsors](#sponsors)
## Dialects Supported
Although SQL is reasonably consistent in its implementations, there are several different dialects available with variations of syntax and grammar. **SQLFluff** currently supports the following SQL dialects (though perhaps not in full):
Although SQL is reasonably consistent in its implementations, there are several
different dialects available with variations of syntax and grammar. **SQLFluff**
currently supports the following SQL dialects (though perhaps not in full):
- ANSI SQL - this is the base version and on occasion may not strictly follow the ANSI/ISO SQL definition
- ANSI SQL - this is the base version and on occasion may not strictly follow
the ANSI/ISO SQL definition
- [Athena](https://aws.amazon.com/athena/)
- [BigQuery](https://cloud.google.com/bigquery/)
- [ClickHouse](https://clickhouse.com/)
- [Databricks](https://databricks.com/) (note: this extends the `sparksql` dialect with
[Unity Catalog](https://docs.databricks.com/data-governance/unity-catalog/index.html) syntax).
- [Db2](https://www.ibm.com/analytics/db2)
- [DuckDB](https://duckdb.org/)
- [Exasol](https://www.exasol.com/)
- [Greenplum](https://greenplum.org/)
- [Hive](https://hive.apache.org/)
- [Impala](https://impala.apache.org/)
- [Materialize](https://materialize.com/)
- [MySQL](https://www.mysql.com/)
- [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/index.html)
- [PostgreSQL](https://www.postgresql.org/) (aka Postgres)
- [Redshift](https://docs.aws.amazon.com/redshift/index.html)
- [Snowflake](https://www.snowflake.com/)
- [Spark3](https://spark.apache.org/docs/latest/)
- [SOQL](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm)
- [SparkSQL](https://spark.apache.org/docs/latest/)
- [SQLite](https://www.sqlite.org/)
- [StarRocks](https://www.starrocks.io)
- [Teradata](https://www.teradata.com/)
- [Transact-SQL](https://docs.microsoft.com/en-us/sql/t-sql/language-reference) (aka T-SQL)
- [Trino](https://trino.io/)
- [Vertica](https://www.vertica.com/)
We aim to make it easy to expand on the support of these dialects and also add other, currently unsupported, dialects. Please [raise issues](https://github.com/sqlfluff/sqlfluff/issues) (or upvote any existing issues) to let us know of demand for missing support.
We aim to make it easy to expand on the support of these dialects and also
add other, currently unsupported, dialects. Please [raise issues](https://github.com/sqlfluff/sqlfluff/issues)
(or upvote any existing issues) to let us know of demand for missing support.
Pull requests from those that know the missing syntax or dialects are especially welcomed and are the question way for you to get support added. We are happy to work with any potential contributors on this to help them add this support. Please raise an issue first for any large feature change to ensure it is a good fit for this project before spending time on this work.
Pull requests from those that know the missing syntax or dialects are especially
welcomed and are the question way for you to get support added. We are happy
to work with any potential contributors on this to help them add this support.
Please raise an issue first for any large feature change to ensure it is a good
fit for this project before spending time on this work.
## Templates Supported
SQL itself does not lend itself well to [modularity](https://docs.getdbt.com/docs/viewpoint#section-modularity), so to introduce some flexibility and reusability it is often [templated](https://en.wikipedia.org/wiki/Template_processor) as discussed more in [our modularity documentation](https://docs.sqlfluff.com/en/stable/realworld.html#modularity).
SQL itself does not lend itself well to [modularity](https://docs.getdbt.com/docs/viewpoint#section-modularity),
so to introduce some flexibility and reusability it is often [templated](https://en.wikipedia.org/wiki/Template_processor)
as discussed more in [our modularity documentation](https://docs.sqlfluff.com/en/stable/perma/modularity.html).
**SQLFluff** supports the following templates:
- [Jinja](https://jinja.palletsprojects.com/) (aka Jinja2)
- [dbt](https://www.getdbt.com/)
- SQL placeholders (e.g. SQLAlchemy parameters)
- [Python format strings](https://docs.python.org/3/library/string.html#format-string-syntax)
- [dbt](https://www.getdbt.com/) (requires plugin)
Again, please raise issues if you wish to support more templating languages/syntaxes.
## VS Code Extension
We also have a VS Code extension:
- [Github Repository](https://github.com/sqlfluff/vscode-sqlfluff)
- [Extension in VS Code marketplace](https://marketplace.visualstudio.com/items?itemName=dorzey.vscode-sqlfluff)
# Getting Started
To get started, install the package and run `sqlfluff lint` or `sqlfluff fix`.
@@ -54,39 +105,77 @@ To get started, install the package and run `sqlfluff lint` or `sqlfluff fix`.
```shell
$ pip install sqlfluff
$ echo " SELECT a + b FROM tbl; " > test.sql
$ sqlfluff lint test.sql
$ sqlfluff lint test.sql --dialect ansi
== [test.sql] FAIL
L: 1 | P: 1 | L003 | Single indentation uses a number of spaces not a multiple of 4
L: 1 | P: 14 | L006 | Operators should be surrounded by a single space unless at the start/end of a line
L: 1 | P: 27 | L001 | Unnecessary trailing whitespace
L: 1 | P: 1 | LT01 | Expected only single space before 'SELECT' keyword.
| Found ' '. [layout.spacing]
L: 1 | P: 1 | LT02 | First line should not be indented.
| [layout.indent]
L: 1 | P: 1 | LT13 | Files must not begin with newlines or whitespace.
| [layout.start_of_file]
L: 1 | P: 11 | LT01 | Expected only single space before binary operator '+'.
| Found ' '. [layout.spacing]
L: 1 | P: 14 | LT01 | Expected only single space before naked identifier.
| Found ' '. [layout.spacing]
L: 1 | P: 27 | LT01 | Unnecessary trailing whitespace at end of file.
| [layout.spacing]
L: 1 | P: 27 | LT12 | Files must end with a single trailing newline.
| [layout.end_of_file]
All Finished 📜 🎉!
```
Alternatively, you can use the [**Official SQLFluff Docker Image**](https://hub.docker.com/r/sqlfluff/sqlfluff) or have a play using [**SQLFluff online**](https://online.sqlfluff.com/).
Alternatively, you can use the [**Official SQLFluff Docker Image**](https://hub.docker.com/r/sqlfluff/sqlfluff)
or have a play using [**SQLFluff online**](https://online.sqlfluff.com/).
For full [CLI usage](https://docs.sqlfluff.com/en/stable/cli.html) and [rules reference](https://docs.sqlfluff.com/en/stable/rules.html), see [the SQLFluff docs](https://docs.sqlfluff.com/en/stable/).
For full [CLI usage](https://docs.sqlfluff.com/en/stable/perma/cli.html) and
[rules reference](https://docs.sqlfluff.com/en/stable/perma/rules.html), see
[the SQLFluff docs](https://docs.sqlfluff.com/en/stable/).
# Documentation
For full documentation visit [docs.sqlfluff.com](https://docs.sqlfluff.com/en/stable/). This documentation is generated from this repository so please raise [issues](https://github.com/sqlfluff/sqlfluff/issues) or pull requests for any additions, corrections, or clarifications.
For full documentation visit [docs.sqlfluff.com](https://docs.sqlfluff.com/en/stable/).
This documentation is generated from this repository so please raise
[issues](https://github.com/sqlfluff/sqlfluff/issues) or pull requests
for any additions, corrections, or clarifications.
# Releases
**SQLFluff** is in beta phase - expect the tool to change significantly with potentially non-backwards compatible API and configuration changes in future releases. If you would like to join in please consider [contributing](CONTRIBUTING.md).
**SQLFluff** adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
so breaking changes should be restricted to major versions releases. Some
elements (such as the python API) are in a less stable state and may see more
significant changes more often. For details on breaking changes and how
to migrate between versions, see our
[release notes](https://docs.sqlfluff.com/en/latest/perma/releasenotes.html). See the
[changelog](CHANGELOG.md) for more details. If you would like to join in, please
consider [contributing](CONTRIBUTING.md).
New releases are made monthly. For more information, visit [Releases](https://github.com/sqlfluff/sqlfluff/releases).
New releases are made monthly. For more information, visit
[Releases](https://github.com/sqlfluff/sqlfluff/releases).
# SQLFluff on Slack
We have a fast-growing community [on Slack](https://join.slack.com/t/sqlfluff/shared_invite/zt-o1f4x0e8-pZzarAIlQmKj_6ZwD16w0g), come and join us!
We have a fast-growing community
[on Slack](https://join.slack.com/t/sqlfluff/shared_invite/zt-2qtu36kdt-OS4iONPbQ3aCz2DIbYJdWg),
come and join us!
# SQLFluff on Twitter
Follow us [on Twitter @SQLFluff](https://twitter.com/SQLFluff) for announcements and other related posts.
Follow us [on Twitter @SQLFluff](https://twitter.com/SQLFluff) for announcements
and other related posts.
# Contributing
We are grateful to all our [contributors](https://github.com/sqlfluff/sqlfluff/graphs/contributors). There is a lot to do in this project, and we are just getting started.
We are grateful to all our [contributors](https://github.com/sqlfluff/sqlfluff/graphs/contributors).
There is a lot to do in this project, and we are just getting started.
If you want to understand more about the architecture of **SQLFluff**, you can find [more here](https://docs.sqlfluff.com/en/latest/architecture.html).
If you want to understand more about the architecture of **SQLFluff**, you can
find [more here](https://docs.sqlfluff.com/en/latest/perma/architecture.html).
If you would like to contribute, check out the [open issues on GitHub](https://github.com/sqlfluff/sqlfluff/issues). You can also see the guide to [contributing](CONTRIBUTING.md).
If you would like to contribute, check out the
[open issues on GitHub](https://github.com/sqlfluff/sqlfluff/issues). You can also see
the guide to [contributing](CONTRIBUTING.md).
# Sponsors
<img src="images/datacoves.png" alt="Datacoves" width="150"/><br>
The turnkey analytics stack, find out more at [Datacoves.com](https://datacoves.com/).

View File

@@ -1,92 +0,0 @@
-- Package model
{{
config(
materialized = "table",
)
}}
with
wer as (
SELECT
sp.sergvsdrvs,
sp.sdtrsbnt,
trim(LTRIM(sp.sresgdr, 'asecesf')) as srebstrgserg,
sp.bdfgsrg,
sp.sfnsfdgnfd,
sp.vsdfbvsdfv,
sp.sdbsdr,
sp.srgdsrbsfcgb,
s.sdrgsdrbsd,
s.sdrgngf,
s.cvyjhcth,
tspc.fgyjmgbhmv,
tspc.cgh,
tspc.ghftdnftbcfhcgnc,
tspc.ynvgnmbjmvb,
s.vgbhm,
fhdtdtnyjftgjyumh,
sp.fgufghjfghjf
FROM {{ ref('wetrghdxfh') }} as sp
inner join {{ ref('strghtdfh') }} s using(sergvsdrvs)
left join {{ ref('sdrtghsdtrh') }} as tspc
on (sp.sdtrsbnt = tspc.sdtrsbnt)
),
qwe as (
select
servsdrfvsdzrv,
min(dsfgsergsrdg) as sftgbnsbgvszd
from {{ ref('sdfgsre') }}
group by servsdrfvsdzrv
),
ert as (
SELECT
p.sdfsdgsdfg,
MAX(IFF(ce.ts is not null, 1, 0)) = 1 as has_events,
min(ce.ts) as first_event,
max(ce.ts) as last_event
FROM sdfsgdfg p
LEFT JOIN {{ ref('dsrgsdrg') }} ce
on (p.dfgsd = trim(ce.lpn)
and ce.ts > p.sdfg - interval '30 days'
and ce.ts < p.sdfg + interval '60 days'
and ce.ts < CURRENT_DATE + interval '78 hours')
GROUP BY p.sdfsdgsdfg
),
dsfg as (
SELECT
p.rfgsrdsrd,
MAX(IFF(t.success = 0, 1, 0)) = 1 as sergsdrg
FROM wer p
LEFT JOIN {{ ref('ncvbncbvnvcn') }} t
ON (p.dfg = t.dfg AND t.ertwretwetr = 'purchase')
GROUP BY p.rfgsrdsrd
)
select
p.sdfgsdg,
p.wertwert,
p.nfghncvn,
p.fgsgdfg,
p.dfgsncn,
p.sdfhgdg,
p.ghdstrh,
p.dgnsfnstrh,
p.srthsdhfgh,
p.fgdfhgdfgn,
p.dfgnhdndtf,
p.dfthstghsreg,
qwe.sdfbsrb,
qwe.sdfbsfdb,
qwe.dfdfgdr,
billing_events.ahreagre,
p.fsdgseag,
p.fb,
p.fsgfdg,
od.xcbrdbrbsdrbsg,
p.sdfgsrbsrebs,
p.sdfgsdfbsdrg,
p.sdgsdrgrgrdgs
from packages p
inner join qwe using(sdrgsrdg)
inner join ert using(sdfasef)
INNER JOIN dsfg od ON p.shipment_id = od.shipment_id

View File

@@ -1,34 +0,0 @@
[sqlfluff]
verbose = 0
nocolor = False
dialect = bigquery
templater = jinja
rules = None
exclude_rules = None
recurse = 0
[sqlfluff:templater:jinja:macros]
# Some rules can be configured directly from the config common to other rules.
[sqlfluff:rules]
tab_space_size = 4
# Some rules have their own specific config.
[sqlfluff:rules:L010]
capitalisation_policy = consistent
[sqlfluff:templater:jinja:context]
dataset=dataset
gcp_project=gcp_project
benchmark_user_map_project=project
benchmark_user_map_dataset=summary
benchmark_user_map_table=benchmark_user_map
benchmark_summaries_project=project
benchmark_summaries_dataset=summary
benchmark_summaries_table=benchmark_summaries
campaign_performance_project=project
campaign_performance_dataset=summary
campaign_performance_table=campaign_performance
user_average_project=project
user_average_dataset=summary
user_average_table=average_user_performance

View File

@@ -1,246 +0,0 @@
-- This query generated by script/generate_corr_queries.py and should probably not be
-- modified manually. Instead, make changes to that script and rerun it.
WITH
raw_effect_sizes AS (
SELECT
COUNT(1) AS campaign_count,
state_user_v_peer_open
,business_type
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_small_subject_line to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_small_subject_line), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_small_subject_line)) AS open_uses_small_subject_line
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_personal_subject to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_personal_subject), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_personal_subject)) AS open_uses_personal_subject
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_timewarp to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_timewarp), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_timewarp)) AS open_uses_timewarp
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_small_preview to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_small_preview), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_small_preview)) AS open_uses_small_preview
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_personal_to to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_personal_to), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_personal_to)) AS open_uses_personal_to
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_ab_test_subject to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_ab_test_subject), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_ab_test_subject)) AS open_uses_ab_test_subject
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_ab_test_content to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_ab_test_content), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_ab_test_content)) AS open_uses_ab_test_content
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_preview_text to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_preview_text), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_preview_text)) AS open_uses_preview_text
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_sto to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_sto), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_sto)) AS open_uses_sto
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_freemail_from to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_freemail_from), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_freemail_from)) AS open_uses_freemail_from
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_resend_non_openers to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_resend_non_openers), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_resend_non_openers)) AS open_uses_resend_non_openers
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_promo_code to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_promo_code), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_promo_code)) AS open_uses_promo_code
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_prex to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_prex), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_prex)) AS open_uses_prex
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_ab_test_from to be the "x variable" in terms of the regression line.
,SAFE_DIVIDE(SAFE_MULTIPLY(CORR(open_rate_su, uses_ab_test_from), STDDEV_POP(open_rate_su)), STDDEV_POP(uses_ab_test_from)) AS open_uses_ab_test_from
FROM
`{{gcp_project}}.{{dataset}}.global_actions_states`
GROUP BY
state_user_v_peer_open
,business_type),
imputed_effect_sizes AS (
SELECT
campaign_count,
state_user_v_peer_open
,business_type
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_small_subject_line), 0, open_uses_small_subject_line), 0) AS open_uses_small_subject_line
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_personal_subject), 0, open_uses_personal_subject), 0) AS open_uses_personal_subject
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_timewarp), 0, open_uses_timewarp), 0) AS open_uses_timewarp
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_small_preview), 0, open_uses_small_preview), 0) AS open_uses_small_preview
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_personal_to), 0, open_uses_personal_to), 0) AS open_uses_personal_to
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_ab_test_subject), 0, open_uses_ab_test_subject), 0) AS open_uses_ab_test_subject
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_ab_test_content), 0, open_uses_ab_test_content), 0) AS open_uses_ab_test_content
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_preview_text), 0, open_uses_preview_text), 0) AS open_uses_preview_text
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_sto), 0, open_uses_sto), 0) AS open_uses_sto
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_freemail_from), 0, open_uses_freemail_from), 0) AS open_uses_freemail_from
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_resend_non_openers), 0, open_uses_resend_non_openers), 0) AS open_uses_resend_non_openers
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_promo_code), 0, open_uses_promo_code), 0) AS open_uses_promo_code
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_prex), 0, open_uses_prex), 0) AS open_uses_prex
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
,COALESCE(IF(IS_NAN(open_uses_ab_test_from), 0, open_uses_ab_test_from), 0) AS open_uses_ab_test_from
FROM
raw_effect_sizes
),
action_states AS (
SELECT
has_used_small_subject_line
,has_used_personal_subject
,has_used_timewarp
,has_used_small_preview
,has_used_personal_to
,has_used_ab_test_subject
,has_used_ab_test_content
,has_used_preview_text
,has_used_sto
,has_used_freemail_from
,has_used_resend_non_openers
,has_used_promo_code
,has_used_prex
,has_used_ab_test_from
FROM `{{gcp_project}}.{{dataset}}.global_state_space`
GROUP BY has_used_small_subject_line
,has_used_personal_subject
,has_used_timewarp
,has_used_small_preview
,has_used_personal_to
,has_used_ab_test_subject
,has_used_ab_test_content
,has_used_preview_text
,has_used_sto
,has_used_freemail_from
,has_used_resend_non_openers
,has_used_promo_code
,has_used_prex
,has_used_ab_test_from)
SELECT
imputed_effect_sizes.*,
has_used_small_subject_line
,has_used_personal_subject
,has_used_timewarp
,has_used_small_preview
,has_used_personal_to
,has_used_ab_test_subject
,has_used_ab_test_content
,has_used_preview_text
,has_used_sto
,has_used_freemail_from
,has_used_resend_non_openers
,has_used_promo_code
,has_used_prex
,has_used_ab_test_from
FROM
imputed_effect_sizes
CROSS JOIN action_states
ORDER BY campaign_count DESC

View File

@@ -1,370 +0,0 @@
-- This query generated by script/generate_corr_queries.py and should probably not be
-- modified manually. Instead, make changes to that script and rerun it.
WITH
raw_effect_sizes AS (
SELECT
state_user_v_peer_open,
business_type,
COUNT(*) AS campaign_count,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_small_subject_line to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_small_subject_line),
STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_small_subject_line)
) AS open_uses_small_subject_line,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_personal_subject to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_personal_subject),
STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_personal_subject)
) AS open_uses_personal_subject,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_timewarp to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_timewarp), STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_timewarp)
) AS open_uses_timewarp,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_small_preview to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_small_preview), STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_small_preview)
) AS open_uses_small_preview,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_personal_to to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_personal_to), STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_personal_to)
) AS open_uses_personal_to,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_ab_test_subject to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_ab_test_subject),
STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_ab_test_subject)
) AS open_uses_ab_test_subject,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_ab_test_content to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_ab_test_content),
STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_ab_test_content)
) AS open_uses_ab_test_content,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_preview_text to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_preview_text), STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_preview_text)
) AS open_uses_preview_text,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_sto to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_sto), STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_sto)
) AS open_uses_sto,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_freemail_from to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_freemail_from), STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_freemail_from)
) AS open_uses_freemail_from,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_resend_non_openers to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_resend_non_openers),
STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_resend_non_openers)
) AS open_uses_resend_non_openers,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_promo_code to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_promo_code), STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_promo_code)
) AS open_uses_promo_code,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_prex to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_prex), STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_prex)
) AS open_uses_prex,
-- The following is the slope of the regression line. Note that CORR (which is the Pearson's correlation
-- coefficient is symmetric in its arguments, but since STDDEV_POP(open_rate_su) appears in the
-- numerator this is the slope of the regression line considering STDDEV_POP(open_rate_su) to be
-- the "y variable" and uses_ab_test_from to be the "x variable" in terms of the regression line.
SAFE_DIVIDE(
SAFE_MULTIPLY(
CORR(open_rate_su, uses_ab_test_from), STDDEV_POP(open_rate_su)
),
STDDEV_POP(uses_ab_test_from)
) AS open_uses_ab_test_from
FROM
`{{gcp_project}}.{{dataset}}.global_actions_states`
GROUP BY
state_user_v_peer_open,
business_type),
imputed_effect_sizes AS (
SELECT
campaign_count,
state_user_v_peer_open,
business_type,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(
IS_NAN(open_uses_small_subject_line),
0,
open_uses_small_subject_line
),
0
) AS open_uses_small_subject_line,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(
IS_NAN(open_uses_personal_subject),
0,
open_uses_personal_subject
),
0
) AS open_uses_personal_subject,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(IS_NAN(open_uses_timewarp), 0, open_uses_timewarp), 0
) AS open_uses_timewarp,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(IS_NAN(open_uses_small_preview), 0, open_uses_small_preview), 0
) AS open_uses_small_preview,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(IS_NAN(open_uses_personal_to), 0, open_uses_personal_to), 0
) AS open_uses_personal_to,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(
IS_NAN(open_uses_ab_test_subject), 0, open_uses_ab_test_subject
),
0
) AS open_uses_ab_test_subject,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(
IS_NAN(open_uses_ab_test_content), 0, open_uses_ab_test_content
),
0
) AS open_uses_ab_test_content,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(IS_NAN(open_uses_preview_text), 0, open_uses_preview_text), 0
) AS open_uses_preview_text,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(IS_NAN(open_uses_sto), 0, open_uses_sto), 0
) AS open_uses_sto,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(IS_NAN(open_uses_freemail_from), 0, open_uses_freemail_from), 0
) AS open_uses_freemail_from,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(
IS_NAN(open_uses_resend_non_openers),
0,
open_uses_resend_non_openers
),
0
) AS open_uses_resend_non_openers,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(IS_NAN(open_uses_promo_code), 0, open_uses_promo_code), 0
) AS open_uses_promo_code,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(IS_NAN(open_uses_prex), 0, open_uses_prex), 0
) AS open_uses_prex,
-- We now impute the value of the effect size to 0 if it was NaN or NULL. This is to
-- take into account states where all campaigns either did or did not perform an
-- action. In these cases, we assume that campaign outcome is uncorrelated with
-- the action because we do not have evidence otherwise.
COALESCE(
IF(IS_NAN(open_uses_ab_test_from), 0, open_uses_ab_test_from), 0
) AS open_uses_ab_test_from
FROM
raw_effect_sizes
),
action_states AS (
SELECT
has_used_small_subject_line,
has_used_personal_subject,
has_used_timewarp,
has_used_small_preview,
has_used_personal_to,
has_used_ab_test_subject,
has_used_ab_test_content,
has_used_preview_text,
has_used_sto,
has_used_freemail_from,
has_used_resend_non_openers,
has_used_promo_code,
has_used_prex,
has_used_ab_test_from
FROM `{{gcp_project}}.{{dataset}}.global_state_space`
GROUP BY has_used_small_subject_line,
has_used_personal_subject,
has_used_timewarp,
has_used_small_preview,
has_used_personal_to,
has_used_ab_test_subject,
has_used_ab_test_content,
has_used_preview_text,
has_used_sto,
has_used_freemail_from,
has_used_resend_non_openers,
has_used_promo_code,
has_used_prex,
has_used_ab_test_from)
SELECT
imputed_effect_sizes.*,
has_used_small_subject_line,
has_used_personal_subject,
has_used_timewarp,
has_used_small_preview,
has_used_personal_to,
has_used_ab_test_subject,
has_used_ab_test_content,
has_used_preview_text,
has_used_sto,
has_used_freemail_from,
has_used_resend_non_openers,
has_used_promo_code,
has_used_prex,
has_used_ab_test_from
FROM
imputed_effect_sizes
CROSS JOIN action_states
ORDER BY campaign_count DESC

View File

@@ -1,8 +0,0 @@
benchmarks:
- name: 004_L003_indentation_3
cmd: ['sqlfluff', 'parse', '--bench', 'test/fixtures/linter/autofix/ansi/004_indentation/before.sql']
- name: B_001_package
cmd: ['sqlfluff', 'parse', '--bench', 'benchmarks/bench_001_package.sql']
- name: B_002_pearson
cmd: ['sqlfluff', 'fix', '-f', '--bench',
'--fixed-suffix', '_fix', 'benchmarks/bench_002/bench_002_pearson.sql']

2
constraints/dbt140.txt Normal file
View File

@@ -0,0 +1,2 @@
dbt-core~=1.4.1
dbt-postgres~=1.4.1

View File

@@ -0,0 +1,2 @@
dbt-core~=1.5.0
dbt-postgres~=1.5.0

2
constraints/dbt150.txt Normal file
View File

@@ -0,0 +1,2 @@
dbt-core~=1.5.0
dbt-postgres~=1.5.0

2
constraints/dbt160.txt Normal file
View File

@@ -0,0 +1,2 @@
dbt-core~=1.6.0
dbt-postgres~=1.6.0

2
constraints/dbt170.txt Normal file
View File

@@ -0,0 +1,2 @@
dbt-core~=1.7.0
dbt-postgres~=1.7.0

View File

@@ -0,0 +1,2 @@
dbt-core~=1.8.0
dbt-postgres~=1.8.0

2
constraints/dbt180.txt Normal file
View File

@@ -0,0 +1,2 @@
dbt-core~=1.8.0
dbt-postgres~=1.8.0

View File

@@ -0,0 +1,2 @@
dbt-core~=1.9.0b1
dbt-postgres~=1.9.0b1

2
constraints/dbt190.txt Normal file
View File

@@ -0,0 +1,2 @@
dbt-core~=1.9.0b1
dbt-postgres~=1.9.0b1

View File

@@ -20,4 +20,5 @@ help:
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
python generate-auto-docs.py
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

155
docs/generate-auto-docs.py Normal file
View File

@@ -0,0 +1,155 @@
"""Generate some documentation automatically.
This script generates partial documentation sections (i.e. the content of
`/docs/source/_partials/`) by importing SQLFluff and extracting data about
rules and dialects.
It should run before every docs generation so that those partial .rst files
can then be correctly referenced by other sections of the docs. For example
this file builds the file `/docs/source/_partials/rule_summaries.rst`, which
is then inserted into `/docs/source/reference/rules.rst` using the directive
`.. include:: ../_partials/rule_summaries.rst`.
This script is referenced in the `Makefile` and the `make.bat` file to ensure
it is run at the appropriate moment.
"""
import json
from collections import defaultdict
from pathlib import Path
import sqlfluff
from sqlfluff.core.plugin.host import get_plugin_manager
base_path = Path(__file__).parent.absolute()
##########################################
# Generate rule documentation dynamically.
##########################################
autogen_header = """..
NOTE: This file is generated by the conf.py script.
Don't edit this by hand
"""
table_header = f"""
+{'-' * 42}+{'-' * 50}+{'-' * 30}+{'-' * 20}+
|{'Bundle' : <42}|{'Rule Name' : <50}|{'Code' : <30}|{'Aliases' : <20}|
+{'=' * 42}+{'=' * 50}+{'=' * 30}+{'=' * 20}+
"""
# Extract all the rules.
print("Rule Docs Generation: Reading Rules...")
rule_bundles = defaultdict(list)
rule_list = []
for plugin_rules in get_plugin_manager().hook.get_rules():
for rule in plugin_rules:
_bundle_name = rule.name.split(".")[0]
rule_bundles[_bundle_name].append(rule)
rule_list.append((rule.code, rule.name))
# Write them into a json file for use by redirects.
print("Rule Docs Generation: Writing Rule JSON...")
with open(base_path / "source/_partials/rule_list.json", "w", encoding="utf8") as f:
json.dump(rule_list, f)
# Write them into the table. Bundle by bundle.
print("Rule Docs Generation: Writing Rule Table...")
with open(base_path / "source/_partials/rule_table.rst", "w", encoding="utf8") as f:
f.write(autogen_header)
f.write(table_header)
for bundle in sorted(rule_bundles.keys()):
# Set the bundle name to the ref.
_bundle_name = f":ref:`bundle_{bundle}`"
for idx, rule in enumerate(rule_bundles[bundle]):
step = 1 # The number of aliases per line.
aliases = ", ".join(rule.aliases[:step]) + (
"," if len(rule.aliases) > step else ""
)
name_ref = f":sqlfluff:ref:`{rule.name}`"
code_ref = f":sqlfluff:ref:`{rule.code}`"
f.write(
f"| {_bundle_name : <40} | {name_ref : <48} "
f"| {code_ref : <28} | {aliases : <18} |\n"
)
j = 1
while True:
if not rule.aliases[j:]:
break
aliases = ", ".join(rule.aliases[j : j + step]) + (
"," if len(rule.aliases[j:]) > step else ""
)
f.write(f"|{' ' * 42}|{' ' * 50}|{' ' * 30}| {aliases : <18} |\n")
j += step
if idx + 1 < len(rule_bundles[bundle]):
f.write(f"|{' ' * 42}+{'-' * 50}+{'-' * 30}+{'-' * 20}+\n")
else:
f.write(f"+{'-' * 42}+{'-' * 50}+{'-' * 30}+{'-' * 20}+\n")
# Unset the bundle name so we don't repeat it.
_bundle_name = ""
f.write("\n\n")
# Write each of the summary files.
print("Rule Docs Generation: Writing Rule Summaries...")
with open(base_path / "source/_partials/rule_summaries.rst", "w", encoding="utf8") as f:
f.write(autogen_header)
for bundle in sorted(rule_bundles.keys()):
if "sql" in bundle:
# This accounts for things like "TSQL"
header_name = bundle.upper()
else:
header_name = bundle.capitalize()
# Write the bundle header.
f.write(
f".. _bundle_{bundle}:\n\n"
f"{header_name} bundle\n"
f"{'-' * (len(bundle) + 7)}\n\n"
)
for rule in rule_bundles[bundle]:
f.write(
f".. sqlfluff:rule:: {rule.code}\n"
f" {rule.name}\n\n"
)
# Separate off the heading so we can bold it.
heading, _, doc_body = rule.__doc__.partition("\n")
underline_char = '"'
f.write(f" {heading}\n")
f.write(f" {underline_char * len(heading)}\n\n")
f.write(" " + doc_body)
f.write("\n\n")
print("Rule Docs Generation: Done")
# Extract all the dialects.
print("Dialect Docs Generation: Reading Dialects...")
# We make a dictionary of all of them first, because we want to force the ANSI
# one to be first.
dialect_dict = {dialect.label: dialect for dialect in sqlfluff.list_dialects()}
dialect_list = [dialect_dict["ansi"]] + [
dialect for dialect_name, dialect in dialect_dict.items() if dialect_name != "ansi"
]
# Write each of the summary files.
print("Dialect Docs Generation: Writing Dialect Summaries...")
with open(
base_path / "source/_partials/dialect_summaries.rst", "w", encoding="utf8"
) as f:
f.write(autogen_header)
for dialect in dialect_list:
f.write(
f".. _{dialect.label}_dialect_ref:\n\n"
f"{dialect.name}\n{'-' * len(dialect.name)}\n\n"
f"**Label**: ``{dialect.label}``\n\n"
)
if dialect.label != "ansi":
f.write(
f"**Inherits from**: :ref:`{dialect.inherits_from}_dialect_ref`\n\n"
)
if dialect.docstring:
f.write(dialect.docstring + "\n\n")

View File

@@ -25,6 +25,9 @@ if errorlevel 9009 (
exit /b 1
)
REM Generate the rule & dialect docs
python generate-auto-docs.py
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

View File

@@ -1,5 +1,8 @@
# Requirements for building docs
sphinx>=2.4.1
# 2.13.0 added the sql+jinja syntax
pygments>=2.13.0
sphinx-click
sphinx-reredirects
doc8
tqdm

View File

@@ -0,0 +1,147 @@
"""The sqlfluff domain for documenting rules."""
from sphinx import addnodes
from sphinx.directives import ObjectDescription
from sphinx.domains import Domain, ObjType
from sphinx.roles import XRefRole
from sphinx.util.nodes import make_refnode
class SQLFluffRule(ObjectDescription):
"""SQLFluff rule directive for sphinx.
Rule directives can be used as shown below.
.. code-block:: rst
.. sqlfluff:rule:: AM01
ambiguous.distinct
Write the documentation for the rule here.
To cross reference (i.e. refer to) objects defined like this
both the code and name reference is available:
.. code-block:: rst
:sqlfluff:ref:`CP02`
:sqlfluff:ref:`capitalisation.identifiers`
"""
def handle_signature(self, sig, signode):
"""Handle the initial signature of the node.
This formats the header of the section.
"""
raw_obj_type = "code" if len(sig) == 4 else "rule"
obj_type = raw_obj_type.capitalize() + " "
signode += addnodes.desc_type(obj_type, obj_type)
signode += addnodes.desc_name(sig, sig)
fullname = obj_type + sig
signode["type"] = raw_obj_type
signode["sig"] = sig
signode["fullname"] = fullname
return (fullname, raw_obj_type, sig)
def add_target_and_index(self, name_cls, sig, signode):
"""Hook to add the permalink and index entries."""
# Add an ID for permalinks
node_id = "rule" + "-" + sig
signode["ids"].append(node_id)
if len(sig) == 4:
# If it's a code, add support for legacy links too.
# Both of these formats have been used in the past.
signode["ids"].append(f"sqlfluff.rules.Rule_{sig}")
signode["ids"].append(f"sqlfluff.rules.sphinx.Rule_{sig}")
# Add to domain for xref resolution
fluff = self.env.get_domain("sqlfluff")
fluff.add_rule(sig)
# Add to index
self.indexnode["entries"].append(("single", sig, node_id, "", None))
def _object_hierarchy_parts(self, sig_node):
return ("bundle", "name")
def _toc_entry_name(self, sig_node) -> str:
# NOTE: toctree unpacking issues are due to incorrectly
# setting _toc_parts.
sig_node["_toc_parts"] = (
"bundle",
sig_node["sig"],
)
if len(sig_node["sig"]) == 4:
# It's a code - don't return TOC entry.
return ""
else:
# It's a name
return sig_node["sig"]
class SQLFluffDomain(Domain):
"""SQLFluff domain."""
name = "sqlfluff"
label = "sqlfluff"
object_types = {
"rule": ObjType("rule", "rule", "obj"),
}
roles = {
"ref": XRefRole(),
}
directives = {
"rule": SQLFluffRule,
}
initial_data = {
"rules": [], # object list
}
def get_full_qualified_name(self, node):
"""Get the fully qualified name of the rule."""
return f"rule.{node.arguments[0]}"
def get_objects(self):
"""Hook to get all the rules."""
yield from self.data["rules"]
def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
"""Hook to resolve xrefs.
References can be made by code or by name, e.g.
- :sqlfluff:ref:`LT01`
- :sqlfluff:ref:`layout.spacing`
"""
match = [
(docname, anchor)
for _, sig, _, docname, anchor, _ in self.get_objects()
if sig == target
]
if len(match) > 0:
todocname = match[0][0]
targ = match[0][1]
return make_refnode(builder, fromdocname, todocname, targ, contnode, targ)
else:
print(f"Failed to match xref: {target!r}")
return None
def add_rule(self, signature):
"""Add a new recipe to the domain."""
name = f"rule.{signature}"
anchor = f"rule-{signature}"
# name, dispname, type, docname, anchor, priority
self.data["rules"].append(
(name, signature, "Rule", self.env.docname, anchor, 0)
)
def setup(app):
"""Setup the domain."""
app.add_domain(SQLFluffDomain)

4
docs/source/_partials/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
rule_table.rst
rule_summaries.rst
rule_list.json
dialect_summaries.rst

View File

@@ -0,0 +1,9 @@
This folder is ignored from the main build and intended
only for files included in others via the `.. include::`
directive.
Some of those files are also auto-generated by scripts,
in which case they should be included in the `.gitignore`
and not edited by hand.
See [generate-auto-docs.py](https://github.com/sqlfluff/sqlfluff/blob/main/docs/generate-auto-docs.py) for more info.

View File

@@ -0,0 +1,68 @@
[sqlfluff]
# Supported dialects https://docs.sqlfluff.com/en/stable/perma/dialects.html
# Or run 'sqlfluff dialects'
dialect = snowflake
# One of [raw|jinja|python|placeholder]
templater = jinja
# Comma separated list of rules to exclude, or None
# See https://docs.sqlfluff.com/en/stable/perma/rule_disabling.html
# AM04 (ambiguous.column_count) and ST06 (structure.column_order) are
# two of the more controversial rules included to illustrate usage.
exclude_rules = ambiguous.column_count, structure.column_order
# The standard max_line_length is 80 in line with the convention of
# other tools and several style guides. Many projects however prefer
# something a little longer.
# Set to zero or negative to disable checks.
max_line_length = 120
# CPU processes to use while linting.
# The default is "single threaded" to allow easy debugging, but this
# is often undesirable at scale.
# If positive, just implies number of processes.
# If negative or zero, implies number_of_cpus - specified_number.
# e.g. -1 means use all processors but one. 0 means all cpus.
processes = -1
# If using the dbt templater, we recommend setting the project dir.
[sqlfluff:templater:dbt]
project_dir = ./
[sqlfluff:indentation]
# While implicit indents are not enabled by default. Many of the
# SQLFluff maintainers do use them in their projects.
allow_implicit_indents = True
[sqlfluff:rules:aliasing.length]
min_alias_length = 3
# The default configuration for capitalisation rules is "consistent"
# which will auto-detect the setting from the rest of the file. This
# is less desirable in a new project and you may find this (slightly
# more strict) setting more useful.
# Typically we find users rely on syntax highlighting rather than
# capitalisation to distinguish between keywords and identifiers.
# Clearly, if your organisation has already settled on uppercase
# formatting for any of these syntax elements then set them to "upper".
# See https://stackoverflow.com/questions/608196/why-should-i-capitalize-my-sql-keywords-is-there-a-good-reason
[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = lower
[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = lower
[sqlfluff:rules:capitalisation.functions]
extended_capitalisation_policy = lower
[sqlfluff:rules:capitalisation.literals]
capitalisation_policy = lower
[sqlfluff:rules:capitalisation.types]
extended_capitalisation_policy = lower
# The default configuration for the not equal convention rule is "consistent"
# which will auto-detect the setting from the rest of the file. This
# is less desirable in a new project and you may find this (slightly
# more strict) setting more useful.
[sqlfluff:rules:convention.not_equal]
# Default to preferring the "c_style" (i.e. `!=`)
preferred_not_equal_style = c_style

View File

@@ -1,36 +0,0 @@
.. _apiref:
API Reference
=============
SQLFluff exposes a public api for other python applications to use.
A basic example of this usage is given here, with the documentation
for each of the methods below.
.. literalinclude:: ../../examples/01_basic_api_usage.py
:language: python
Simple API commands
-------------------
.. automodule:: sqlfluff
:members: lint, fix, parse
Advanced API usage
------------------
The simple API presents only a fraction of the functionality present
within the core SQLFluff library. For more advanced use cases, users
can import the :code:`Linter()` and :code:`FluffConfig()` classes from
:code:`sqlfluff.core`. As of version 0.4.0 this is considered as
*experimental only* as the internals may change without warning in any
future release. If you come to rely on the internals of SQLFluff, please
post an issue on GitHub to share what you're up to. This will help shape
a more reliable, tidy and well documented public API for use.
.. automodule:: sqlfluff.core
:members: Linter, Lexer, Parser, FluffConfig

View File

@@ -1,130 +0,0 @@
Architecture
============
It is recommended that the following is read in conjunction with exploring
the codebase. `dialect_ansi.py` in particular is helpful to understand the
recursive structure of segments and grammars. Some more detail is also given
on our Wiki_ including a `Contributing Dialect Changes`_ guide.
.. _Wiki: https://github.com/sqlfluff/sqlfluff/wiki/
.. _`Contributing Dialect Changes`: https://github.com/sqlfluff/sqlfluff/wiki/Contributing-Dialect-Changes
Stage 1, the templater
----------------------
This stage only applies to templated SQL, most commonly Jinja and dbt. Vanilla
SQL is sent straight to stage 2, the lexer.
In order to lint templated SQL, SQLFluff must first convert the 'raw' or
pre-templated code into valid SQL, which can then be parsed. The templater
returns both the raw and post-templated SQL so that any rule violations which
occur in templated sections can be ignored and the rest mapped to their
original line location for user feedback.
.. _Jinja: https://jinja.palletsprojects.com/
.. _dbt: https://docs.getdbt.com/
*SQLFluff* supports two templating engines: Jinja_ and dbt_.
Under the hood dbt also uses Jinja, but in *SQLFluff* uses a separate
mechanism which interfaces directly with the dbt python package.
For more details on how to configure the templater see :ref:`templateconfig`.
Stage 2, the lexer
------------------
The lexer takes SQL and separates it into segments of whitespace and
code. No meaning is imparted; that is the job of the parser.
Stage 3, the parser
-------------------
The parser is arguably the most complicated element of SQLFluff, and is
relied on by all the other elements of the tool to do most of the heavy
lifting.
#. The lexed segments are parsed using the specified dialect's grammars. In
SQLFluff, grammars describe the shape of SQL statements (or their
components). The parser attempts to apply each potential grammar to the
lexed segments until all the segments have been matched.
#. In SQLFluff, segments form a tree-like structure. The top-level segment is
a :code:`FileSegment`, which contains zero or more
:code:`StatementSegment`\ s, and so on. Before the segments have been parsed
and named according to their type, they are 'raw', meaning they have no
classification other than their literal value.
#. The three key components to the parser are segments,
:code:`match_grammar`\ s and :code:`parse_grammar`\ s. A segment can be a
leaf in the parse tree, such as a :code:`NumericLiteralSegment`, which is
simply a number, or can contain many other segments, such as a
:code:`SelectStatementSegment`. Each segment can specify a
:code:`parse_grammar`, and a :code:`match_grammar`. If both a
:code:`match_grammar` and :code:`parse_grammar` are defined in a segment,
:code:`match_grammar` is used to quickly prune the tree for branches which
do not match segments being parsed, and the :code:`parse_grammar` is then
used to refine the branch identified as correct. If only a
:code:`match_grammar` is defined, then it serves the purpose of both pruning
and refining.
#. A segment's :code:`.parse()` method uses the :code:`parse_grammar`, on
which :code:`.match()` is called. The *match* method of this grammar will
return a potentially refined structure of the segments within the
segment in greater detail. In the example of a :code:`FileSegment`, it
first divides up the query into statements and then finishes.
* *Segments* must implement a :code:`match_grammar`. When :code:`.match()`
is called on a segment, this is the grammar which is used to decide
whether there is a match.
* *Grammars* combine *segments* or other *grammars* together in a
pre-defined way. For example the :code:`OneOf` grammar will match if any
one of its child elements match.
#. Regardless of whether the :code:`parse_grammar` was used, the next step
is to recursively call the :code:`.parse()` method of each of the child
segments of the grammar. This operation is wrapped in a method called
:code:`.expand()`. In the :code:`FileSegment`, the first step will have
transformed a series of raw tokens into :code:`StatementSegment`
segments, and the *expand* step will let each of those segments refine
the content within them.
#. During the recursion, the parser eventually reaches segments which have
no children (raw segments containing a single token), and so the
recursion naturally finishes.
#. If no match is found for a segment, the contents will be wrapped in an
:code:`UnparsableSegment` which is picked up as a *parsing* error later.
When working on the parser there are a couple of design principles
to keep in mind.
- Grammars are contained in *dialects*, the root dialect being
the *ansi* dialect. The ansi dialect is used to host logic common
to all dialects, and so does not necessarily adhere to the formal
ansi specification. Other SQL dialects inherit from the ansi dialect,
replacing or patching any segments they need to. One reason for the *Ref*
grammar is that it allows name resolution of grammar elements at runtime
and so a *patched* grammar with some elements overriden can still rely on
lower-level elements which haven't been redeclared within the dialect
- All grammars and segments attempt to match as much as they can and will
return partial matches where possible. It is up to the calling grammar
or segment to decide whether a partial or complete match is required
based on the context it is matching in.
Stage 4, the linter
-------------------
Given the complete parse tree, rule classes check for linting errors by
traversing the tree, looking for segments and patterns of concern. If
the rule discovers a violation, it returns a :code:`LintResult` pointing
to the segment which caused the violation.
Some rules are able to *fix* the problems they find. If this is the case,
the rule will return a list of fixes, which describe changes to be made to
the tree. This can include edits, inserts, or deletions. Once the fixes
have been applied, the updated tree is written to the original file.

View File

@@ -5,28 +5,34 @@ list see the documentation:
https://www.sphinx-doc.org/en/master/usage/configuration.html
"""
import configparser
import json
import os
import sys
# tomllib is only in the stdlib from 3.11+
if sys.version_info >= (3, 11):
import tomllib
else: # pragma: no cover
import toml as tomllib
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
sys.path.append(os.path.abspath("./_ext"))
# Get the global config info as currently stated
# (we use the config file to avoid actually loading any python here)
config = configparser.ConfigParser()
config.read(["../../setup.cfg"])
stable_version = config.get("sqlfluff_docs", "stable_version")
with open("../../pyproject.toml", "rb") as config_file:
config = tomllib.load(config_file)
stable_version = config.get("tool.sqlfluff_docs", "stable_version")
# -- Project information -----------------------------------------------------
project = "SQLFluff"
copyright = "2019, Alan Cruickshank"
copyright = "2024, Alan Cruickshank"
author = "Alan Cruickshank"
# The full version, including alpha/beta/rc tags
@@ -45,6 +51,10 @@ extensions = [
"sphinx.ext.napoleon",
# Documenting click commands
"sphinx_click.ext",
# Redirects
"sphinx_reredirects",
# SQLFluff domain
"sqlfluff_domain",
]
# Add any paths that contain templates here, relative to this directory.
@@ -53,7 +63,11 @@ templates_path = ["_templates"]
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []
exclude_patterns = [
# Exclude the partials folder, which is made up of files intended
# to be included in others.
"_partials",
]
# Master doc
master_doc = "index"
@@ -86,14 +100,76 @@ html_theme_options = {
"touch_icon": "images/sqlfluff-sm2-sq.png",
"github_user": "sqlfluff",
"github_repo": "sqlfluff",
# GitHub Fork button
"github_banner": True,
# GitHub Fork button (points at a broken link, so disabling it)
"github_banner": False,
# GitHub star button
"github_type": "star",
# Use `"true"` instead of `True` for counting GitHub star, see https://ghbtns.com
"github_count": "true",
# Codecov button
"codecov_button": True,
}
# -- Options for redirects ---------------------------------------------
# https://documatt.gitlab.io/sphinx-reredirects/usage.html
# Load the rule lists to generate rule permalinks
with open("_partials/rule_list.json", "r") as rule_file:
rule_list = json.load(rule_file)
redirects = {
# Where there are references to the docs in any of the codebase (whether in
# places like the README or in error messages), they should all reference
# a perma link (to redirect). This ensures we can support a consistent
# link location even if the docs move around.
"perma/layout": "../configuration/layout.html",
"perma/indent_locations": (
"../configuration/layout.html#configuring-indent-locations"
),
"perma/hanging_indents": "../configuration/layout.html#hanging-indents",
"perma/layout_spacing": (
"../configuration/layout.html#configuring-layout-and-spacing"
),
"perma/configuration": "../configuration/index.html",
"perma/dbt": "../configuration/templating/dbt.html",
"perma/cli": "../reference/cli.html",
"perma/rules": "../reference/rules.html",
"perma/dialects": "../reference/dialects.html",
"perma/architecture": "../guides/contributing/architecture.html",
"perma/rule_disabling": (
"../configuration/rule_configuration.html#enabling-and-disabling-rules"
),
"perma/internals": "../reference/internals/index.html",
"perma/modularity": "../why_sqlfluff.html#modularity",
"perma/indentation": "../configuration/layout.html#configuring-indent-locations",
"perma/releasenotes": "../reference/releasenotes.html",
"perma/why": "../why_sqlfluff.html",
"perma/plugin_dev": "../guides/contributing/plugins.html",
"perma/plugin_guide": "../guides/setup/developing_custom_rules.html",
"perma/variables": "../configuration/templating/index.html",
"perma/python_templating": "../configuration/templating/python.html",
"perma/guides": "../guides/index.html",
"perma/contribute_dialect_keywords": (
"../guides/contributing/dialect.html#dialect_keywords"
),
# Add permalinks for rule codes
**{
f"perma/rule/{code}": (
f"../../reference/rules.html#sqlfluff.rules.sphinx.Rule_{code}"
)
for code, _ in rule_list
},
# These are legacy links which used to exist in different parts of the
# SQLFluff code base, and which we continue to support so those links
# aren't dead ends. They should redirect to permalinks.
"indentation": "perma/indentation.html",
"architecture": "perma/architecture.html",
"dialects": "perma/dialects.html",
"internals": "perma/internals.html",
"layout": "perma/layout.html",
"releasenotes": "perma/releasenotes.html",
"realworld": "perma/why.html",
# This is a legacy link to support older versions of the VSCode plugin.
# https://github.com/sqlfluff/vscode-sqlfluff/blob/master/src/features/providers/linter/actions/hover.ts
"rules": "perma/rules.html",
}

View File

@@ -1,755 +0,0 @@
.. _config:
Configuration
=============
SQLFluff accepts configuration either through the command line or
through configuration files. There is *rough* parity between the
two approaches with the exception that *templating* configuration
must be done via a file, because it otherwise gets slightly complicated.
For details of what's available on the command line check out
the :ref:`cliref`.
For file based configuration *SQLFluff* will look for the following
files in order. Later files will (if found) will be used to overwrite
any vales read from earlier files.
- :code:`setup.cfg`
- :code:`tox.ini`
- :code:`pep8.ini`
- :code:`.sqlfluff`
- :code:`pyproject.toml`
Within these files, the first four will be read like a `cfg file`_, and
*SQLFluff* will look for sections which start with :code:`sqlfluff`, and where
subsections are delimited by a semicolon. For example the *jinjacontext*
section will be indicated in the section started with
:code:`[sqlfluff:jinjacontext]`.
For example, a snippet from a :code:`.sqlfluff` file (as well as any of the
supported cfg file types):
.. code-block:: cfg
[sqlfluff]
templater = "jinja"
sql_file_exts = ".sql,.sql.j2,.dml,.ddl"
[sqlfluff:indentation]
indented_joins = false
indented_using_on = true
template_blocks_indent = false
[sqlfluff:templater]
unwrap_wrapped_queries = true
[sqlfluff:templater:jinja]
apply_dbt_builtins = true
For the `pyproject.toml file`_, all valid sections start with
:code:`tool.sqlfluff` and subsections are delimited by a dot. For example the
*jinjacontext* section will be indicated in the section started with
:code:`[tool.sqlfluff.jinjacontext]`.
For example, a snippet from a :code:`pyproject.toml` file:
.. code-block:: cfg
[tool.sqlfluff.core]
templater = "jinja"
sql_file_exts = ".sql,.sql.j2,.dml,.ddl"
[tool.sqlfluff.indentation]
indented_joins = false
indented_using_on = true
template_blocks_indent = false
[tool.sqlfluff.templater]
unwrap_wrapped_queries = true
[tool.sqlfluff.templater.jinja]
apply_dbt_builtins = true
.. _`cfg file`: https://docs.python.org/3/library/configparser.html
.. _`pyproject.toml file`: https://www.python.org/dev/peps/pep-0518/
Nesting
-------
**SQLFluff** uses **nesting** in its configuration files, with files
closer *overriding* (or *patching*, if you will) values from other files.
That means you'll end up with a final config which will be a patchwork
of all the values from the config files loaded up to that path. The exception
to this is the value for `templater`, which cannot be set in config files in
subdirectories of the working directory.
You don't **need** any config files to be present to make *SQLFluff*
work. If you do want to override any values though SQLFluff will use
files in the following locations in order, with values from later
steps overriding those from earlier:
0. *[...and this one doesn't really count]* There's a default config as
part of the SQLFluff package. You can find this below, in the
:ref:`defaultconfig` section.
1. It will look in the user's os-specific app config directory. On OSX this is
`~/Library/Preferences/sqlfluff`, Unix is `~/.config/sqlfluff`, Windows is
`<home>\\AppData\\Local\\sqlfluff\\sqlfluff`, for any of the filenames
above in the main :ref:`config` section. If multiple are present, they will
*patch*/*override* each other in the order above.
2. It will look for the same files in the user's home directory (~).
3. It will look for the same files in the current working directory.
4. *[if parsing a file in a subdirectory of the current working directory]*
It will look for the same files in every subdirectory between the
current working dir and the file directory.
5. It will look for the same files in the directory containing the file
being linted.
This whole structure leads to efficient configuration, in particular
in projects which utilise a lot of complicated templating.
.. _ruleconfig:
Rule Configuration
------------------
Rules can be configured with the :code:`.sqlfluff` config files.
Common rule configurations can be set in the :code:`[sqlfluff:rules]` section.
For example:
.. code-block:: cfg
[sqlfluff:rules]
tab_space_size = 4
max_line_length = 80
indent_unit = space
comma_style = trailing
allow_scalar = True
single_table_references = consistent
unquoted_identifiers_policy = all
Rule specific configurations are set in rule specific subsections.
For example, enforce that keywords are upper case by configuring the rule
:class:`L010 <sqlfluff.core.rules.Rule_L010>`:
.. code-block:: cfg
[sqlfluff:rules:L010]
# Keywords
capitalisation_policy = upper
All possible options for rule sections are documented in :ref:`ruleref`.
For an overview of the most common rule configurations that you may want to
tweak, see `Default Configuration`_ (and use :ref:`ruleref` to find the
available alternatives).
Enabling and Disabling Rules
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
To disable individual rules, set :code:`exclude_rules` in the top level section
of sqlfluff configuration. The value is a comma separated list of rule ids.
For example, to disable the rules :class:`L022 <sqlfluff.core.rules.Rule_L022>`
and :class:`L027 <sqlfluff.core.rules.Rule_L027>`:
.. code-block:: cfg
[sqlfluff]
exclude_rules = L022, L027
To enable individual rules, configure :code:`rules`, respectively.
For example, to enable :class:`L027 <sqlfluff.core.rules.Rule_L027>`:
.. code-block:: cfg
[sqlfluff]
rules = L027
If both :code:`exclude_rules` and :code:`rules` have non-empty value, then the
excluded rules are removed from the rules list. This allows for example
enabling common rules on top level but excluding some on subdirectory level.
Additionally, some rules have a special :code:`force_enable` configuration
option, which allows to enable the given rule even for dialects where it is
disabled by default. The rules that support this can be found in the
:ref:`ruleref`.
The default values can be seen in `Default Configuration`_.
See also: `Ignoring Errors & Files`_.
.. _templateconfig:
Jinja Templating Configuration
------------------------------
When thinking about Jinja templating there are two different kinds of things
that a user might want to fill into a templated file, *variables* and
*functions/macros*. Currently *functions* aren't implemented in any
of the templaters.
Variable Templating
^^^^^^^^^^^^^^^^^^^
Variables are available in the *jinja*, *python* and *placeholder* templaters.
By default the templating engine will expect variables for templating to be
available in the config, and the templater will be look in the section
corresponding to the context for that templater. By convention, the config for
the *jinja* templater is found in the *sqlfluff:templater:jinja:context
section, the config for the *python* templater is found in the
*sqlfluff:templater:python:context* section, the one for the *placeholder*
templater is found in the *sqlfluff:templater:placeholder:context* section
For example, if passed the following *.sql* file:
.. code-block:: jinja
SELECT {{ num_things }} FROM {{ tbl_name }} WHERE id > 10 LIMIT 5
...and the following configuration in *.sqlfluff* in the same directory:
.. code-block:: cfg
[sqlfluff:templater:jinja:context]
num_things=456
tbl_name=my_table
...then before parsing, the sql will be transformed to:
.. code-block:: sql
SELECT 456 FROM my_table WHERE id > 10 LIMIT 5
.. note::
If there are variables in the template which cannot be found in
the current configuration context, then this will raise a `SQLTemplatingError`
and this will appear as a violation without a line number, quoting
the name of the variable that couldn't be found.
Placeholder templating
^^^^^^^^^^^^^^^^^^^^^^
Libraries such as SQLAlchemy or Psycopg use different parameter placeholder
styles to mark where a parameter has to be inserted in the query.
For example a query in SQLAlchemy can look like this:
.. code-block:: sql
SELECT * FROM table WHERE id = :myid
At runtime `:myid` will be replace by a value provided by the application and
escaped as needed, but this is not standard SQL and cannot be parsed as is.
In order to parse these queries is then necessary to replace these
placeholders with sample values, and this is done with the placeholder
templater.
Placeholder templating can be enabled in the config using:
.. code-block:: cfg
[sqlfluff]
templater = placeholder
A few common styles are supported:
.. code-block:: sql
:force:
-- colon
WHERE bla = :my_name
-- numeric_colon
WHERE bla = :2
-- pyformat
WHERE bla = %(my_name)s
-- dollar
WHERE bla = $my_name
-- question_mark
WHERE bla = ?
-- numeric_dollar
WHERE bla = $3
-- percent
WHERE bla = %s
-- ampersand
WHERE bla = &s or WHERE bla = &{s} or USE DATABASE MARK_{ENV}
These can be configured by setting `param_style` to the names above:
.. code-block:: cfg
[sqlfluff:templater:placeholder]
param_style = colon
my_name = 'john'
then it is necessary to set sample values for each parameter, like `my_name`
above. Notice that the value needs to be escaped as it will be replaced as a
string during parsing.
When parameters are positional, like `question_mark`, then their name is
simply the order in which they appear, starting with `1`.
.. code-block:: cfg
[sqlfluff:templater:placeholder]
param_style = question_mark
1 = 'john'
In case you need a parameter style different from the ones above, you can pass
a custom regex.
.. code-block:: cfg
[sqlfluff:templater:placeholder]
param_regex = __(?P<param_name>[\w_]+)__
my_name = 'john'
N.B. quotes around `param_regex` in the config are
interpreted literally by the templater.
e.g. `param_regex='__(?P<param_name>[\w_]+)__'` matches
`'__some_param__'` not `__some_param__`
the named parameter `param_name` will be used as the key to replace, if
missing, the parameter is assumed to be positional and numbers are used insead.
Also consider making a pull request to the project to have your style added,
it may be useful to other people and simplify your configuration.
Complex Variable Templating
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Two more advanced features of variable templating are *case sensitivity*
and *native python types*. Both are illustrated in the following example:
.. code-block:: cfg
[sqlfluff:templater:jinja:context]
my_list = ['a', 'b', 'c']
MY_LIST = ("d", "e", "f")
my_where_dict = {"field_1": 1, "field_2": 2}
.. code-block:: jinja
SELECT
{% for elem in MY_LIST %}
'{{elem}}' {% if not loop.last %}||{% endif %}
{% endfor %} as concatenated_list
FROM tbl
WHERE
{% for field, value in my_where_dict.items() %}
{{field}} = {{value}} {% if not loop.last %}and{% endif %}
{% endfor %}
...will render as...
.. code-block:: sql
SELECT
'd' || 'e' || 'f' as concatenated_list
FROM tbl
WHERE
field_1 = 1 and field_2 = 2
Note that the variable was replaced in a case sensitive way and that the
settings in the config file were interpreted as native python types.
Macro Templating
^^^^^^^^^^^^^^^^
Macros (which also look and feel like *functions* are available only in the
*jinja* templater. Similar to `Variable Templating`_, these are specified in
config files, what's different in this case is how they are named. Similar to
the *context* section above, macros are configured separately in the *macros*
section of the config. Consider the following example.
If passed the following *.sql* file:
.. code-block:: jinja
SELECT {{ my_macro(6) }} FROM some_table
...and the following configuration in *.sqlfluff* in the same directory (note
the tight control of whitespace):
.. code-block:: cfg
[sqlfluff:templater:jinja:macros]
a_macro_def = {% macro my_macro(n) %}{{ n }} + {{ n * 2 }}{% endmacro %}
...then before parsing, the sql will be transformed to:
.. code-block:: sql
SELECT 6 + 12 FROM some_table
Note that in the code block above, the variable name in the config is
*a_macro_def*, and this isn't apparently otherwise used anywhere else.
Broadly this is accurate, however within the configuration loader this will
still be used to overwrite previous *values* in other config files. As such
this introduces the idea of config *blocks* which could be selectively
overwritten by other configuration files downstream as required.
In addition to macros specified in the config file, macros can also be
loaded from files or folders. This is specified in the config file:
.. code-block:: cfg
[sqlfluff:templater:jinja]
load_macros_from_path = my_macros
`load_macros_from_path` is a comma-separated list of files or folders. SQLFluff
will load macros from any :code:`.sql` file found in the specified locations.
Locations are *relative to the config file*. For example, if the config file
above was found at :code:`/home/my_project/.sqlfluff` then SQLFluff will look
for macros in the folder :code:`/home/my_project/my_macros/` (but not
subfolders). Alternatively, the path can also be a :code:`.sql` itself. Any
macros defined in the config will always take precedence over a macro defined
in the path.
**Note:** The `load_macros_from_path` also defines the search path for Jinja
[include](https://jinja.palletsprojects.com/en/3.0.x/templates/#include) or
[import](https://jinja.palletsprojects.com/en/3.0.x/templates/#import).
Unlike with macros (as noted above), subdirectories are supported. For example,
if `load_macros_from_path` is set to `my_macros`, and there is a file
`my_macros/subdir/my_file.sql`, you can do:
.. code-block:: jinja
{% include 'subdir/include_comment.sql' %}
.. note::
Throughout the templating process **whitespace** will still be treated
rigorously, and this includes **newlines**. In particular you may choose
to provide *dummy* macros in your configuration different from the actual
macros used in production.
**REMEMBER:** The reason SQLFluff supports macros is to *enable* it to parse
templated sql without it being a blocker. It shouldn't be a requirement that
the *templating* is accurate - it only needs to work well enough that
*parsing* and *linting* are helpful.
Builtin Macro Blocks
^^^^^^^^^^^^^^^^^^^^
One of the main use cases which inspired *SQLFluff* as a project was `dbt`_.
It uses jinja templating extensively and leads to some users maintaining large
repositories of sql files which could potentially benefit from some linting.
.. note::
*SQLFluff* has now a tighter integration with dbt through the "dbt" templater.
It is the recommended templater for dbt projects. If used, it eliminates the
need for the overrides described in this section.
To use the dbt templater, go to `dbt Project Configuration`_.
*SQLFluff* anticipates this use case and provides some built in macro blocks
in the `Default Configuration`_ which assist in getting started with `dbt`_
projects. In particular it provides mock objects for:
* *ref*: The mock version of this provided simply returns the model reference
as the name of the table. In most cases this is sufficient.
* *config*: A regularly used macro in `dbt`_ to set configuration values. For
linting purposes, this makes no difference and so the provided macro simply
returns nothing.
.. note::
If there are other builtin macros which would make your life easier,
consider submitting the idea (or even better a pull request) on `github`_.
.. _`dbt`: https://www.getdbt.com/
.. _`github`: https://www.github.com/sqlfluff/sqlfluff
Library Templating
^^^^^^^^^^^^^^^^^^
If using *SQLFluff* for dbt with jinja as your templater, you may have library
function calls within your sql files that can not be templated via the
normal macro templating mechanisms:
.. code-block:: jinja
SELECT foo, bar FROM baz {{ dbt_utils.group_by(2) }}
To template these libraries, you can use the `sqlfluff:jinja:library_path`
config option:
.. code-block:: cfg
[sqlfluff:templater:jinja]
library_path = sqlfluff_libs
This will pull in any python modules from that directory and allow sqlfluff
to use them in templates. In the above example, you might define a file at
`sqlfluff_libs/dbt_utils.py` as:
.. code-block:: python
def group_by(n):
return "GROUP BY 1,2"
If an `__init__.py` is detected, it will be loaded alongside any modules and
submodules found within the library path.
.. code-block:: jinja
SELECT
{{ custom_sum('foo', 'bar') }},
{{ foo.bar.another_sum('foo', 'bar') }}
FROM
baz
`sqlfluff_libs/__init__.py`:
.. code-block:: python
def custom_sum(a: str, b: str) -> str:
return a + b
`sqlfluff_libs/foo/__init__.py`:
.. code-block:: python
# empty file
`sqlfluff_libs/foo/bar.py`:
.. code-block:: python
def another_sum(a: str, b: str) -> str:
return a + b
dbt Project Configuration
-------------------------
.. note::
From sqlfluff version 0.7.0 onwards, the dbt templater has been moved
to a separate plugin and python package. Projects that were already using
the dbt templater may initially fail after an upgrade to 0.7.0+. See the
installation instructions below to install the dbt templater.
dbt templating is still a relatively new feature added in 0.4.0 and
is still in very active development! If you encounter an issue, please
let us know in a GitHub issue or on the SQLFluff slack workspace.
dbt is not the default templater for *SQLFluff* (it is Jinja). For using
*SQLFluff* with a dbt project, users can either use the `jinja` templater
(which may be slightly faster, but will not support the full spectrum of
macros) or the `dbt` templater, which uses dbt itself to render the
sql (meaning that there is a much more reliable representation of macros,
but a potential performance hit accordingly). At this stage we recommend
that users try both approaches and choose according to the method that
they intend to use *SQLFluff*.
A simple rule of thumb might be:
- If you are using *SQLFluff* in a CI/CD context, where speed is not
critical but accuracy in rendering sql is, then the `dbt` templater
may be more appropriate.
- If you are using *SQLFluff* in an IDE or on a git hook, where speed
of response may be more important, then the `jinja` templater may
be more appropriate.
Installation & Configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
In order to get started using *SQLFluff* with a dbt project you will
first need to install the relevant `dbt adapter`_ for your dialect
and the :code:`sqlfluff-templater-dbt` package using
your package manager of choice (e.g.
:code:`pip install dbt-postgres sqlfluff-templater-dbt`) and then will need the
following configuration:
.. _`dbt adapter`: https://docs.getdbt.com/docs/available-adapters
In *.sqlfluff*:
.. code-block:: cfg
[sqlfluff]
templater = dbt
In *.sqlfluffignore*:
.. code-block:: text
target/
# dbt <1.0.0
dbt_modules/
# dbt >=1.0.0
dbt_packages/
macros/
You can set the dbt project directory, profiles directory and profile with:
.. code-block:: cfg
[sqlfluff:templater:dbt]
project_dir = <relative or absolute path to dbt_project directory>
profiles_dir = <relative or absolute path to the directory that contains the profiles.yml file>
profile = <dbt profile>
target = <dbt target>
.. note::
If the `profiles_dir` setting is omitted, SQLFluff will look for the profile
in the default location, which varies by operating system. On Unix-like
operating systems (e.g. Linux or macOS), the default profile directory is
`~/.dbt/`. On Windows, you can determine your default profile directory by
running `dbt debug --config-dir`.
Known Caveats
^^^^^^^^^^^^^
- To use the dbt templater, you must set `templater = dbt` in the `.sqlfluff`
config file in the directory where sqlfluff is run. The templater cannot
be changed in `.sqlfluff` files in subdirectories.
- In SQLFluff 0.4.0 using the dbt templater requires that all files
within the root and child directories of the dbt project must be part
of the project. If there are deployment scripts which refer to SQL files
not part of the project for instance, this will result in an error.
You can overcome this by adding any non-dbt project SQL files to
.sqlfluffignore.
CLI Arguments
-------------
You already know you can pass arguments (:code:`--verbose`,
:code:`--exclude-rules`, etc.) through the CLI commands (:code:`lint`,
:code:`fix`, etc.):
.. code-block:: text
$ sqlfluff lint my_code.sql -v --exclude-rules L022,L027
You might have arguments that you pass through every time, e.g rules you
*always* want to ignore. These can also be configured:
.. code-block:: cfg
[sqlfluff]
verbose = 1
exclude_rules = L022,L027
Note that while the :code:`exclude_rules` config looks similar to the
above example, the :code:`verbose` config has an integer value. This is
because :code:`verbose` is *stackable* meaning there are multiple levels
of verbosity that are available for configuration. See :ref:`cliref` for
more details about the available CLI arguments. For more details about rule
exclusion, see `Enabling and Disabling Rules`_.
Ignoring Errors & Files
-----------------------
Ignoring individual lines
^^^^^^^^^^^^^^^^^^^^^^^^^
Similar to `flake8's ignore`_, individual lines can be ignored by adding
:code:`-- noqa` to the end of the line. Additionally, specific rules can
be ignored by quoting their code or the category.
.. code-block:: sql
-- Ignore all errors
SeLeCt 1 from tBl ; -- noqa
-- Ignore rule L014 & rule L030
SeLeCt 1 from tBl ; -- noqa: L014,L030
-- Ignore all parsing errors
SeLeCt from tBl ; -- noqa: PRS
.. _`flake8's ignore`: https://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html#in-line-ignoring-errors
Ignoring line ranges
^^^^^^^^^^^^^^^^^^^^
Similar to `pylint's "pylint" directive"`_, ranges of lines can be ignored by
adding :code:`-- noqa:disable=<rule>[,...] | all` to the line. Following this
directive, specified rules (or all rules, if "all" was specified) will be
ignored until a corresponding `-- noqa:enable=<rule>[,...] | all` directive.
.. code-block:: sql
-- Ignore rule L012 from this line forward
SELECT col_a a FROM foo -- noqa: disable=L012
-- Ignore all rules from this line forward
SELECT col_a a FROM foo -- noqa: disable=all
-- Enforce all rules from this line forward
SELECT col_a a FROM foo -- noqa: enable=all
.. _`pylint's "pylint" directive"`: http://pylint.pycqa.org/en/latest/user_guide/message-control.html
.. _sqlfluffignore:
Ignoring types of errors
^^^^^^^^^^^^^^^^^^^^^^^^
General *categories* of errors can be ignored using the ``--ignore`` command
line option or the ``ignore`` setting in ``.sqlfluffignore``. Types of errors
that can be ignored include:
* ``lexing``
* ``linting``
* ``parsing``
* ``templating``
.sqlfluffignore
^^^^^^^^^^^^^^^
Similar to `Git's`_ :code:`.gitignore` and `Docker's`_ :code:`.dockerignore`,
SQLFluff supports a :code:`.sqlfluffignore` file to control which files are and
aren't linted. Under the hood we use the python `pathspec library`_ which also
has a brief tutorial in their documentation.
An example of a potential :code:`.sqlfluffignore` placed in the root of your
project would be:
.. code-block:: cfg
# Comments start with a hash.
# Ignore anything in the "temp" path
/temp/
# Ignore anything called "testing.sql"
testing.sql
# Ignore any ".tsql" files
*.tsql
Ignore files can also be placed in subdirectories of a path which is being
linted and the sub files will also be applied within that subdirectory.
.. _`Git's`: https://git-scm.com/docs/gitignore#_pattern_format
.. _`Docker's`: https://docs.docker.com/engine/reference/builder/#dockerignore-file
.. _`pathspec library`: https://python-path-specification.readthedocs.io/
.. _defaultconfig:
Default Configuration
---------------------
The default configuration is as follows, note the `Builtin Macro Blocks`_ in
section *[sqlfluff:templater:jinja:macros]* as referred to above.
.. literalinclude:: ../../src/sqlfluff/core/default_config.cfg
:language: cfg
:linenos:

View File

@@ -0,0 +1,36 @@
.. _defaultconfig:
Default Configuration
---------------------
The default configuration is as follows, note the :ref:`builtin_jinja_blocks`
in section :code:`[sqlfluff:templater:jinja:macros]` as referred to above.
.. note::
This shows the *entire* default config. **We do not recommend that users**
**copy this whole config as the starter config file for their project**.
This is for two reasons:
#. The config file should act as a form of *documentation* for your team.
A record of what decisions you've made which govern how your format your
sql. By having a more concise config file, and only defining config settings
where they differ from the defaults - you are more clearly stating to your
team what choices you've made.
#. As the project evolves, the structure of the config file may change
and we will attempt to make changes as backward compatible as possible.
If you have not overridden a config setting in your project, we can
easily update the default config to match your expected behaviour over time.
We may also find issues with the default config which we can also fix
in the background. *However*, the longer your local config file, the
more work it will be to update and migrate your config file between
major versions.
If you are starting a fresh project and are looking for a good *starter config*,
check out the :ref:`starter_config` section above.
.. literalinclude:: ../../../src/sqlfluff/core/default_config.cfg
:language: cfg

View File

@@ -0,0 +1,100 @@
.. _ignoreconfig:
Ignoring Errors & Files
-----------------------
.. _inline_ignoring_errors:
Ignoring individual lines
^^^^^^^^^^^^^^^^^^^^^^^^^
Similar to `flake8's ignore`_, individual lines can be ignored by adding
:code:`-- noqa` to the end of the line. Additionally, specific rules can
be ignored by quoting their code or the category.
.. code-block:: sql
-- Ignore all errors
SeLeCt 1 from tBl ; -- noqa
-- Ignore rule CP02 & rule CP03
SeLeCt 1 from tBl ; -- noqa: CP02,CP03
-- Ignore all parsing errors
SeLeCt from tBl ; -- noqa: PRS
.. note::
It should be noted that ignoring ``TMP`` and ``PRS`` errors can lead to
incorrect ``sqlfluff lint`` and ``sqfluff fix`` results as `SQLFluff` can
misinterpret the SQL being analysed.
.. _`flake8's ignore`: https://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html#in-line-ignoring-errors
.. _inline_ignoring_ranges:
Ignoring line ranges
^^^^^^^^^^^^^^^^^^^^
Similar to `pylint's "pylint" directive"`_, ranges of lines can be ignored by
adding :code:`-- noqa:disable=<rule>[,...] | all` to the line. Following this
directive, specified rules (or all rules, if "all" was specified) will be
ignored until a corresponding `-- noqa:enable=<rule>[,...] | all` directive.
.. code-block:: sql
-- Ignore rule AL02 from this line forward
SELECT col_a a FROM foo -- noqa: disable=AL02
-- Ignore all rules from this line forward
SELECT col_a a FROM foo -- noqa: disable=all
-- Enforce all rules from this line forward
SELECT col_a a FROM foo -- noqa: enable=all
.. _`pylint's "pylint" directive"`: http://pylint.pycqa.org/en/latest/user_guide/message-control.html
.. _sqlfluffignore:
:code:`.sqlfluffignore`
^^^^^^^^^^^^^^^^^^^^^^^
Similar to `Git's`_ :code:`.gitignore` and `Docker's`_ :code:`.dockerignore`,
SQLFluff supports a :ref:`sqlfluffignore` file to control which files are and
aren't linted. Under the hood we use the python `pathspec library`_ which also
has a brief tutorial in their documentation.
An example of a potential :ref:`sqlfluffignore` placed in the root of your
project would be:
.. code-block:: cfg
# Comments start with a hash.
# Ignore anything in the "temp" path
/temp/
# Ignore anything called "testing.sql"
testing.sql
# Ignore any ".tsql" files
*.tsql
Ignore files can also be placed in subdirectories of a path which is being
linted and the sub files will also be applied within that subdirectory.
.. _`Git's`: https://git-scm.com/docs/gitignore#_pattern_format
.. _`Docker's`: https://docs.docker.com/engine/reference/builder/#dockerignore-file
.. _`pathspec library`: https://python-path-specification.readthedocs.io/
Ignoring types of errors
^^^^^^^^^^^^^^^^^^^^^^^^
General *categories* of errors can be ignored using the ``--ignore`` command
line option or the ``ignore`` setting in :ref:`sqlfluffignore`. Types of errors
that can be ignored include:
* :code:`lexing`
* :code:`linting`
* :code:`parsing`
* :code:`templating`

View File

@@ -0,0 +1,14 @@
.. _config:
Configuration
=============
.. toctree::
:maxdepth: 2
setting_configuration
rule_configuration
layout
templating/index
ignoring_configuration
default_configuration

View File

@@ -0,0 +1,769 @@
.. _layoutref:
Layout & Whitespace Configuration
=================================
If there is one part of building a linter that is going to be controversial
it's going to be **whitespace** (closely followed by **cApiTaLiSaTiOn** 😁).
More specifically, **whitespace** divides into three key themes:
#. **Spacing**: The amount of whitespace between elements on the same line.
#. **Line Breaks**: The choice of where within the code it is inappropriate,
appropriate or even compulsory to have a line break.
#. **Indentation**: Given a line break, how much whitespace should precede
the first code element on that line.
*SQLFluff* aims to be *opinionated* on this theme, but also *configurable*
(see :ref:`layoutconfig`). The tool will have a default viewpoint and will aim
to have views on all of the important aspects of SQL layout, but if you
(or your organisation) don't like those views then we aim to allow enough
configuration that you can lint in line with your views, and still use
*SQLFluff*. For more information on how to configure rules to your own
viewpoint see :ref:`config`.
.. note::
This section of the docs handles the intent and reasoning behind how
layout is handled by SQLFluff. For a deeper look at how this is achieved
internally see :ref:`reflowinternals`.
Spacing
-------
Of the different elements of whitespace, spacing is likely the least
controversial. By default, all elements are separated by a single space
character. Except for very specific circumstances (see section on
:ref:`alignedelements`), any additional space between elements is
usually unwanted and a distraction for the reader. There are however
several common cases where *no whitespace* is more appropriate, which
fall into two cases (for more details on where to configure these see
:ref:`layoutspacingconfig`).
#. *No whitespace but a newline is allowed.* This option is configured
using the :code:`touch` option in the :code:`spacing_*` configuration
settings. The most common example of this is the spacing around commas.
For example :code:`SELECT a , b` would be unusual and more normally be
written :code:`SELECT a, b`. Inserting a newline between the :code:`a`
and comma would not cause issues and may even be desired, for example:
.. code-block:: sql
SELECT
col_a
, col_b
-- Newline present before column
, col_c
-- When inline, comma should still touch element before.
, GREATEST(col_d, col_e) as col_f
FROM tbl_a
#. *No whitespace and a newline is not allowed.* This option is
configured using the :code:`inline` option in the :code:`spacing_*`
configuration settings. The most common example of this is spacing
within the parts of qualified identifier e.g. :code:`my_schema.my_table`.
If a newline were present between the :code:`.` and either
:code:`my_schema` or :code:`my_table`, then the expression would not
parse and so no newlines should be allowed.
.. _alignedelements:
Aligned elements
^^^^^^^^^^^^^^^^
A special case of spacing is where elements are set to be aligned
within some limits. This is not enabled by default, but can be
be configured to achieve layouts like:
.. code-block:: sql
SELECT
a AS first_column,
b AS second_column,
(a + b) / 2 AS third_column
FROM foo AS bar
In this example, the alias expressions are all aligned with each other.
To configure this, SQLFluff needs to know what elements to
align and how far to search to find elements which should be aligned
with each other. The configuration to achieve this layout is:
.. code-block:: ini
[sqlfluff:layout:type:alias_expression]
# We want non-default spacing _before_ the alias expressions.
spacing_before = align
# We want to align them within the next outer select clause.
# This means for example that alias expressions within the FROM
# or JOIN clause would _not_ be aligned with them.
align_within = select_clause
# The point at which to stop searching outward for siblings, which
# in this example would likely be the boundary of a CTE. Stopping
# when we hit brackets is usually a good rule of thumb for this
# configuration.
align_scope = bracketed
Of these configuration values, the :code:`align_scope` is potentially
the least obvious. The following example illustrates the impact it has.
.. code-block:: sql
-- With
-- align_scope = bracketed
-- align_within = select_clause
WITH foo as (
SELECT
a,
b,
c AS first_column
d + e AS second_column
)
SELECT
a AS first_column,
(a + b) / 2 AS third_column
FROM foo AS bar;
-- With
-- align_scope = bracketed
-- align_within = statement
WITH foo as (
SELECT
a,
b,
c AS first_column
d + e AS second_column
)
SELECT
a AS first_column,
(a + b) / 2 AS third_column
FROM foo AS bar -- Now the FROM alias is also aligned.
-- With
-- align_scope = file
-- align_within = select_clause
WITH foo as (
SELECT
a,
b,
c AS first_column -- Now the aliases here are aligned
d + e AS second_column -- with the outer query.
)
SELECT
a AS first_column,
(a + b) / 2 AS third_column
FROM foo AS bar
-- With
-- align_scope = file
-- align_within = statement
WITH foo as (
SELECT
a,
b,
c AS first_column
d + e AS second_column
)
SELECT
a AS first_column,
(a + b) / 2 AS third_column
FROM foo AS bar
Line Breaks
-----------
When controlling line breaks, we are trying to achieve a few different things:
#. Do we have *enough* line breaks that *line length* doesn't become
excessive. Long lines are hard to read, especially given that readers
may be on varying screen sizes or have multiple windows open. This is
(of course) configurable, but the default is 80 characters (in line with
the `dbt Labs SQL style guide`_.)
#. Is the positioning of *blank lines* (i.e. lines with nothing other
than whitespace on them) appropriate. There are some circumstances
where a blank line is *desired* (e.g. between CTEs). There are others
where they are not, in particular *multiple blank lines*, for example
at the beginning of a file.
#. Where we do have line breaks, are they positioned appropriately and
consistently with regards to other elements around them. This is most
common when it comes to *commas*, and whether they should be *leading*
(e.g. :code:`, my_column`) or *trailing* (e.g. :code:`my_column,`). In
less common cases, it may also be desirable for some elements to have both
a line break *before and after* (e.g. a set operator such as `UNION`).
Indentation
-----------
Lastly, given we have multiple lines of SQL, to what extent should we indent
some lines to provide visual cues to the structure of that SQL. It's
important to note that SQL is *not* whitespace sensitive in its
interpretation and that means that any principles we apply here are entirely
for the benefit of humans. *Your database doesn't care*.
The indentation therefore should be treated as a *hint* to the reader of
the structure of the code. This explains the common practice within most
languages that nested elements (for example the contents of a set of brackets
in a function call) should be indented one step from the outer elements. It's
also convention that elements *with the same level* in a nested structure
should have *the same indentation*, at least with regards to their local
surroundings. As an example:
.. code-block:: sql
SELECT
nested_within_select AS first_column,
some_function(
nested_within_function,
also_nested_within_function
) AS indented_the_same_as_opening_bracket
FROM indented_the_same_as_select
Comment Indents
^^^^^^^^^^^^^^^
.. note::
The notes here about block comments are not implemented prior
to 2.0.x. They should be coming in that release or soon after.
**Comments** are dealt with differently, depending on whether they're
*block* comments (:code:`/* like this */`), which might optionally
include newlines, or *inline* comments (:code:`-- like this`) which
are necessarily only on one line.
* *Block comments* cannot share a line with any code elements (so
in effect they must start on their own new line), they cannot be
followed by any code elements on the same line (and so in effect
must be followed by a newline, if we are to avoid trailing
whitespace). None of the lines within the block comment may have
an indent less than the first line of the block comment (although
additional indentation within a comment is allowed), and that first
line should be aligned with the first code element *following*
the block comment.
.. code-block:: sql
SELECT
/* This is a block comment starting on a new line
which contains a newline (continuing with at least
the same indent.
- potentially containing greater indents
- having no other code following it in the same line
- and aligned with the line of code following it */
this_column as what_we_align_the_column_to
FROM my_table
* *Inline comments* can be on the same line as other code, but are
subject to the same line-length restrictions. If they don't fit
on the same line (or if it just looks nicer) they can also be
the only element on a line. In this latter case, they should be
aligned with the first code element *following* the comment.
.. code-block:: sql
SELECT
-- This is fine
this_column as what_we_align_to,
another_column as something_short, -- Is ok
case
-- This is aligned correctly with below
when indented then take_care
else try_harder
end as the_general_guidance
-- Even here we align with the line below
FROM my_table
.. note::
When fixing issues with comment indentation, SQLFluff
will attempt to keep comments in their original position
but if line length concerns make this difficult, it will
either abandon the fix, or move *same line* comments up and
*before* the line they are currently on. This is in line
with the assumption that comments on their own line refer
to the elements of code which they come *before*, not *after*.
.. _hangingindents:
Hanging Indents
^^^^^^^^^^^^^^^
One approach to indenting nested elements is a layout called a
*hanging indent*. In this layout, there is no line break before the
first nested element, but subsequent elements are indented to
match the line position of that first element. Two examples might be:
.. code-block:: sql
-- A select statement with two hanging indents:
SELECT no_line_break_before_me,
indented_to_match_the_first,
1 + (a
+ b) AS another_more_complex_example
FROM my_table;
-- This TSQL example is also in essence a hanging indent:
DECLARE @prv_qtr_1st_dt DATETIME,
@last_qtr INT,
@last_qtr_first_mn INT,
@last_qtr_yr INT;
In some circumstances this layout can be quite neat (the
:code:`DECLARE` statement is a good example of this), however
once indents are nested or indentation styles are mixed it
can rapidly become confusing (as partially shown in the first
example). Additionally, unless the leading element of the first
line is very short, hanging indents use much *larger indents*
than a traditional simple indent where a line break is used before
the first element.
Hanging indents have been supported in SQLFluff up to the 1.x
versions, however **they will no longer by supported from 2.0.0**
onwards. This is due to the ambiguity which they bring to
fixing poorly formatted SQL. Take the following code:
.. code-block:: sql
SELECT this_is,
badly_formatted, code_and,
not_obvious,
what_was,
intended FROM my_table
Given the lack of line break between :code:`SELECT` and
:code:`this_is`, it would appear that the user is intending
a hanging indent, however it is also plausible that they did
not and they just forgot to add a line break between them.
This ambiguity is unhelpful, both for SQLFluff as a tool,
but also for people who write SQL that there two ways of
indenting their SQL. Given SQLFluff aims to provide consistency
in SQL layout and remove some of the burden of needing to make
choices like this - and that it would be very unusual to keep
*only hanging indents and disable traditional ones* - the only
route left to consistency is to **not allow hanging indents**.
Starting in 2.0.0, any hanging indents detected will be
converted to traditional indents.
.. _implicitindents:
Implicit Indents
^^^^^^^^^^^^^^^^
A close cousin of the hanging indent is the *implicit indent*.
While it does look a little like a hanging indent, it's much
more consistent in its behaviour and is supported from SQLFluff
2.0.0 onwards.
An implicit indent is exactly like a normal indent, but doesn't
have to be actually *taken* to influence the indentation of lines
after it - it just needs to be left un-closed before the end of
the line. These are normally available in clauses which take the
form of :code:`KEYWORD <expression>`, like :code:`WHERE` clauses
or :code:`CASE` expressions.
.. code-block:: sql
-- This WHERE clause here takes advantage of an implicit indent.
SELECT *
FROM my_table
WHERE condition_a
AND condition_b;
-- With implicit indents disabled (which is currently the
-- default), the above formulation is not allowed, and instead
-- there should be a newline immediately after `WHERE` (which
-- is the location of the _implicit_ indent).
SELECT *
FROM my_table
WHERE
condition_a
AND condition_b;
When addressing both indentation and line-length, implicit
indents allow a slightly more compact layout, without significant
drawbacks in legibility. They also enable a style much closer to
some established style guides.
They are however not recommended by many of the major style guides
at time of writing (including the `dbt Labs SQL style guide`_
and the `Mozilla SQL style guide`_), and so are disabled by default.
To enable them, set the :code:`allow_implicit_indents` flag in
:code:`sqluff.indentation` to :code:`True`.
.. _templatedindents:
Templated Indents
^^^^^^^^^^^^^^^^^
SQLFluff supports templated elements in code, such as those
offered by jinja2 (or dbt which relies on it). For simple
cases, templated elements are handled as you would expect
by introducing additional indents into the layout.
.. code-block:: SQL+Jinja
SELECT
a,
{% for n in ['b', 'c', 'd'] %}
-- This section is indented relative to 'a' because
-- it is inside a jinja for loop.
{{ n }},
{% endfor %}
e
FROM my_table
This functionality can be turned off if you wish using the
:code:`template_blocks_indent` option in your :ref:`config`.
It's important to note here, that SQLFluff lints the code after
it has been rendered, and so only has access to code which is
still present after that process.
.. code-block:: SQL+Jinja
SELECT
a,
{% if False %}
-- This section of the code cannot be linted because
-- it is never rendered due to the `if False` condition.
my + poorly
+ spaced - and/indented AS section_of_code
{% endif %}
e
FROM my_table
More complex templated cases are usually characterised by templated
tags *cutting across the parse tree*. This more formally is where the
opening and closing tags of a templated section exist at different
levels in the parsed structure. Starting in version 2.x, these will
be treated differently (Prior to version 2.x, situations like this were sometimes
handled inconsistently or incorrectly).
Indentation should act as a visual cue to the structure of the
written SQL, and as such, the most important thing is that template tags
belonging to the same block structure use the same indentation.
In the example below, this is the opening and closing elements of the
second :code:`if` statement. If treated as a simple case, these tags
would have different indents, because they are at different levels of
the parse tree and so clearly there is a conflict to be resolved.
The view SQLFluff takes on how to resolve this conflict is to pull
all of the tags in this section down to the indent of the
*least indented* (in the example below that would be the closing
:code:`endif` tag). This is similar to the treatment of
`C Preprocessor Directives`_, which are treated somewhat as being
outside the structure of the rest of the file. In these cases,
the content is also *not further indented* as in the simple case
because it makes it harder to line up elements within the affected
section and outside (in the example below the :code:`SELECT` and
:code:`FROM` are a good illustration).
.. code-block:: SQL+Jinja
SELECT
a,
{% if True %}
-- This is a simple case. The opening and closing tag are
-- both at the same level within the SELECT clause.
simple_case AS example,
{% endif %}
b,
{% if True %}
-- This is a complex case. The opening tag is within the SELECT
-- clause, but the closing tag is outside the statement
-- entirely.
complex_case AS example
FROM table_option_one
{% else %}
complex_case_two AS example
FROM table_option_two
{% endif %}
.. _layoutconfig:
Configuring Layout
------------------
Configuration for layout is spread across three places:
#. Indent behavior for particular dialect elements is controlled by the parser.
This is because in the background SQLFluff inserts :code:`Indent`
and :code:`Dedent` tokens into the parse tree where those things
are expected. For more detail see :ref:`layoutindentconfig`.
#. Configuration for the spacing and line position of particular
types of element (such as commas or operators) is set in the
:code:`layout` section of the config file. For more detail see
:ref:`layoutspacingconfig`.
#. Some elements of layout are still controlled by rules directly.
These are usually very specific cases, see :ref:`ruleref` for
more details.
.. _layoutindentconfig:
Configuring indent locations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
One of the key areas for this is the indentation of the
:code:`JOIN` expression, which we'll use as an example.
Semantically, a :code:`JOIN` expression is part of the :code:`FROM` expression
and therefore would be expected to be indented. However according to many
of the most common SQL style guides (including the `dbt Labs SQL style guide`_
and the `Mozilla SQL style guide`_) the :code:`JOIN` keyword is expected to at
the same indent as the :code:`FROM` keyword. By default, *SQLFluff* sides with
the current consensus, which is to *not* indent the :code:`JOIN` keyword,
however this is one element which is configurable.
By setting values in the :code:`sqlfluff:indentation` section of your config
file you can control how this is parsed.
For example, the default indentation would be as follows:
.. code-block:: sql
SELECT
a,
b
FROM my_table
JOIN another_table
ON
condition1
AND condition2
By setting your config file to:
.. code-block:: cfg
[sqlfluff:indentation]
indented_joins = True
Then the expected indentation will be:
.. code-block:: sql
SELECT
a,
b
FROM my_table
JOIN another_table
ON
condition1
AND condition2
There is a similar :code:`indented_using_on` config (defaulted to :code:`True`)
which can be set to :code:`False` to prevent the :code:`USING` or :code:`ON`
clause from being indented, in which case the original SQL would become:
.. code-block:: sql
SELECT
a,
b
FROM my_table
JOIN another_table
ON
condition1
AND condition2
It's worth noting at this point, that for some users, the additional line
break after :code:`ON` is unexpected, and this is a good example of an
:ref:`implicit indent <implicitindents>`. By setting your config to:
.. code-block:: cfg
[sqlfluff:indentation]
indented_using_on = False
allow_implicit_indents = True
Then the expected indentation will be:
.. code-block:: sql
SELECT
a,
b
FROM my_table
JOIN another_table
ON condition1
AND condition2
There is also a similar :code:`indented_on_contents` config (defaulted to
:code:`True`) which can be set to :code:`False` to align any :code:`AND`
subsections of an :code:`ON` block with each other. If set to :code:`False`
(assuming implicit indents are still enabled) the original SQL would become:
.. code-block:: sql
SELECT
a,
b
FROM my_table
JOIN another_table
ON condition1
AND condition2
These can also be combined, so if :code:`indented_using_on` config is set to
:code:`False`, :code:`indented_on_contents` is also set to :code:`False`, and
:code:`allow_implicit_indents` is set tot :code:`True` then the SQL would
become:
.. code-block:: sql
SELECT
a,
b
FROM my_table
JOIN another_table
ON condition1
AND condition2
There is also a similar :code:`indented_ctes` config (defaulted to
:code:`False`) which can be set to :code:`True` to enforce CTEs to be
indented within the :code:`WITH` clause:
.. code-block:: sql
WITH
some_cte AS (
SELECT 1 FROM table1
),
some_other_cte AS (
SELECT 1 FROM table1
)
SELECT 1 FROM some_cte
There is also a similar :code:`indented_then` config (defaulted to
:code:`True`) which can be set to :code:`False` to allow :code:`THEN`
without an indent after :code:`WHEN`:
.. code-block:: sql
SELECT
a,
CASE
WHEN b >= 42 THEN
1
ELSE 0
END AS c
FROM some_table
By default, *SQLFluff* aims to follow the most common approach
to indentation. However, if you have other versions of indentation which are
supported by published style guides, then please submit an issue on GitHub
to have that variation supported by *SQLFluff*.
.. _layoutspacingconfig:
Configuring layout and spacing
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The :code:`[sqlfluff:layout]` section of the config controls the treatment of
spacing and line breaks across all rules. The syntax of this section is very
expressive; however in normal use, only very small alterations should be
necessary from the :ref:`defaultconfig`.
The syntax of the section headings here select by *type*, which corresponds
to the :code:`type` defined in the dialect. For example the following section
applies to elements of the *type* :code:`comma`, i.e. :code:`,`.
.. code-block:: cfg
[sqlfluff:layout:type:comma]
spacing_before = touch
line_position = trailing
Within these configurable sections there are a few key elements which are
available:
* **Spacing Elements**: :code:`spacing_before`, :code:`spacing_after` and
:code:`spacing_within`. For each of these options, there are a few possible
settings:
* The default spacing for all elements is :code:`single` unless otherwise
specified. In this state, elements will be spaced with a single space
character unless there is a line break between them.
* The value of :code:`touch` allows line breaks, but if no line break is
present, then no space should be present. A great example of this is
the spacing before commas (as shown in the config above), where line
breaks may be allowed, but if not they should *touch* the element before.
* Both of the above can be qualified with the :code:`:inline` modifier -
which prevents newlines within the segment. This is best illustrated
by the spacing found in a qualified identifier like
:code:`my_schema.my_table` which uses `touch:inline` or other clauses
where we want to force some elements to be on the same line.
* **Line Position**: set using the :code:`line_position` option. By default
this is unset, which implies no particular line position requirements. The
available options are:
* :code:`trailing` and :code:`leading`, which are most common in the
placement of commas. Both of these settings *also* allow the option
of a comma on its own on a line, or in the middle of a line, *but*
if there is a line break on *either side* then they make sure it's
on the *correct side*. By default we assume *trailing* commas, but if
you (or your organisation) have settled on *leading* commas then
you should add the following section to your config:
.. code-block:: cfg
[sqlfluff:layout:type:comma]
line_position = leading
* :code:`alone`, which means if there is a line break on either side,
then there must be a line break on *both sides* (i.e. that it should
be the only thing on that line.
* All of the above options can be qualified with the :code:`:strict`
modifier - which prevents the *inline* case. For example:
.. code-block:: sql
-- Setting line_position to just `alone`
-- within [sqlfluff:layout:type:set_operator]
-- would not allow:
SELECT a
UNION SELECT b;
-- ...or...
SELECT a UNION
SELECT b;
-- but *would* allow both of the following:
SELECT a UNION SELECT b;
SELECT a
UNION
SELECT b;
-- However the default is set to `alone:strict`
-- then the *only* acceptable configuration is:
SELECT a
UNION
SELECT b;
.. _`C Preprocessor Directives`: https://www.cprogramming.com/reference/preprocessor/
.. _`dbt Labs SQL style guide`: https://github.com/dbt-labs/corp/blob/main/dbt_style_guide.md
.. _`Mozilla SQL style guide`: https://docs.telemetry.mozilla.org/concepts/sql_style.html#joins

View File

@@ -0,0 +1,173 @@
.. _ruleconfig:
Rule Configuration
------------------
Rules can be configured with the :code:`.sqlfluff` config files.
Common rule configurations can be set in the :code:`[sqlfluff:rules]` section.
For example:
.. code-block:: cfg
[sqlfluff:rules]
allow_scalar = True
single_table_references = consistent
unquoted_identifiers_policy = all
Rule specific configurations are set in rule specific subsections.
For example, enforce that keywords are upper case by configuring the rule
:sqlfluff:ref:`CP01`:
.. code-block:: cfg
[sqlfluff:rules:capitalisation.keywords]
# Keywords
capitalisation_policy = upper
All possible options for rule sections are documented in :ref:`ruleref`.
For an overview of the most common rule configurations that you may want to
tweak, see :ref:`defaultconfig` (and use :ref:`ruleref` to find the
available alternatives).
.. _ruleselection:
Enabling and Disabling Rules
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The decision as to which rules are applied to a given file is applied on a file
by file basis, by the effective configuration for that file. There are two
configuration values which you can use to set this:
* :code:`rules`, which explicitly *enables* the specified rules. If this
parameter is unset or empty for a file, this implies "no selection" and
so "all rules" is taken to be the meaning.
* :code:`exclude_rules`, which explicitly *disables* the specified rules.
This parameter is applied *after* the :code:`rules` parameter so can be
used to *subtract* from the otherwise enabled set.
Each of these two configuration values accept a comma separated list of
*references*. Each of those references can be:
* a rule *code* e.g. :code:`LN01`
* a rule *name* e.g. :code:`layout.indent`
* a rule *alias*, which is often a deprecated *code* e.g. :code:`L003`
* a rule *group* e.g. :code:`layout` or :code:`capitalisation`
These different references can be mixed within a given expression, which
results in a very powerful syntax for selecting exactly which rules are
active for a given file.
.. note::
It's worth mentioning here that the application of :code:`rules` and
:code:`exclude_rules`, with *groups*, *aliases* and *names*, in projects
with potentially multiple nested configuration files defining different
rules for different areas of a project can get very confusing very fast.
While this flexibility is intended for users to take advantage of, we do
have some recommendations about how to do this is a way that remains
manageable.
When considering configuration inheritance, each of :code:`rules` and
:code:`exclude_rules` will totally overwrite any values in parent config
files if they are set in a child file. While the subtraction operation
between both of them is calculated *"per file"*, there is no combination
operation between two definitions of :code:`rules` (just one overwrites
the other).
The effect of this is that we recommend one of two approaches:
#. Simply only use :code:`rules`. This has the upshot of each area of
your project being very explicit in which rules are enabled. When
that changes for part of your project you just reset the whole list
of applicable rules for that part of the project.
#. Set a single :code:`rules` value in your master project config file
and then only use :code:`exclude_rules` in sub-configuration files
to *turn off* specific rules for parts of the project where those
rules are inappropriate. This keeps the simplicity of only having
one value which is inherited, but allows slightly easier and simpler
rollout of new rules because we manage by exception.
For example, to disable the rules :sqlfluff:ref:`LT08`
and :sqlfluff:ref:`RF02`:
.. code-block:: cfg
[sqlfluff]
exclude_rules = LT08, RF02
To enable individual rules, configure :code:`rules`, respectively.
For example, to enable :sqlfluff:ref:`RF02`:
.. code-block:: cfg
[sqlfluff]
rules = RF02
Rules can also be enabled/disabled by their grouping. Right now, the only
rule grouping is :code:`core`. This will enable (or disable) a select group
of rules that have been deemed 'core rules'.
.. code-block:: cfg
[sqlfluff]
rules = core
More information about 'core rules' can be found in the :ref:`ruleref`.
Additionally, some rules have a special :code:`force_enable` configuration
option, which allows to enable the given rule even for dialects where it is
disabled by default. The rules that support this can be found in the
:ref:`ruleref`.
The default values can be seen in :ref:`defaultconfig`.
See :ref:`ignoreconfig` for more information on how to turn ignore particular
rules for specific lines, sections or files.
Downgrading rules to warnings
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
To keep displaying violations for specific rules, but not have those
issues lead to a failed run, rules can be downgraded to *warnings*.
Rules set as *warnings* won't cause a file to fail, but will still
be shown in the CLI to warn users of their presence.
The configuration of this behaves very like :code:`exclude_rules`
above:
.. code-block:: cfg
[sqlfluff]
warnings = LT01, LT04
With this configuration, files with no other issues (other than
those set to warn) will pass. If there are still other issues, then
the file will still fail, but will show both warnings and failures.
.. code-block::
== [test.sql] PASS
L: 2 | P: 9 | LT01 | WARNING: Missing whitespace before +
== [test2.sql] FAIL
L: 2 | P: 8 | CP02 | Unquoted identifiers must be consistently upper case.
L: 2 | P: 11 | LT01 | WARNING: Missing whitespace before +
This is particularly useful as a transitional tool when considering
the introduction on new rules on a project where you might want to
make users aware of issues without blocking their workflow (yet).
You can use either rule code or rule name for this setting.
Layout & Spacing Configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The :code:`[sqlfluff:layout]` section of the config controls the
treatment of spacing and line breaks across all rules. To understand
more about this section, see the section of the docs dedicated to
layout: :ref:`layoutconfig`.

View File

@@ -0,0 +1,190 @@
.. _setting_config:
Setting Configuration
=====================
SQLFluff accepts configuration either through the command line or
through configuration files. There is *rough* parity between the
two approaches with the exception that *templating* configuration
must be done via a file, because it otherwise gets slightly complicated.
For details of what's available on the command line check out
the :ref:`cliref`.
.. _`config-files`:
Configuration Files
-------------------
For file based configuration *SQLFluff* will look for the following
files in order. Later files will (if found) will be used to overwrite
any values read from earlier files.
- :code:`setup.cfg`
- :code:`tox.ini`
- :code:`pep8.ini`
- :code:`.sqlfluff`
- :code:`pyproject.toml`
Within these files, the first four will be read like a `cfg file`_, and
*SQLFluff* will look for sections which start with :code:`sqlfluff`, and where
subsections are delimited by a semicolon. For example the *jinjacontext*
section will be indicated in the section started with
:code:`[sqlfluff:jinjacontext]`.
For example, a snippet from a :code:`.sqlfluff` file (as well as any of the
supported cfg file types):
.. code-block:: cfg
[sqlfluff]
templater = jinja
sql_file_exts = .sql,.sql.j2,.dml,.ddl
[sqlfluff:indentation]
indented_joins = False
indented_using_on = True
template_blocks_indent = False
[sqlfluff:templater]
unwrap_wrapped_queries = True
[sqlfluff:templater:jinja]
apply_dbt_builtins = True
For the `pyproject.toml file`_, all valid sections start with
:code:`tool.sqlfluff` and subsections are delimited by a dot. For example the
*jinjacontext* section will be indicated in the section started with
:code:`[tool.sqlfluff.jinjacontext]`.
For example, a snippet from a :code:`pyproject.toml` file:
.. code-block:: toml
[tool.sqlfluff.core]
templater = "jinja"
sql_file_exts = ".sql,.sql.j2,.dml,.ddl"
[tool.sqlfluff.indentation]
indented_joins = false
indented_using_on = true
template_blocks_indent = false
[tool.sqlfluff.templater]
unwrap_wrapped_queries = true
[tool.sqlfluff.templater.jinja]
apply_dbt_builtins = true
# For rule specific configuration, use dots between the names exactly
# as you would in .sqlfluff. In the background, SQLFluff will unpack the
# configuration paths accordingly.
[tool.sqlfluff.rules.capitalisation.keywords]
capitalisation_policy = "upper"
.. _`cfg file`: https://docs.python.org/3/library/configparser.html
.. _`pyproject.toml file`: https://www.python.org/dev/peps/pep-0518/
.. _starter_config:
New Project Configuration
^^^^^^^^^^^^^^^^^^^^^^^^^
When setting up a new project with SQLFluff, we recommend keeping your
configuration file fairly minimal. The config file should act as a form
of *documentation* for your team i.e. a record of what decisions you've
made which govern how your format your SQL. By having a more concise
config file, and only defining config settings where they differ from the
defaults - you are more clearly stating to your team what choices you've made.
*However*, there are also a few places where the *default* configuration
is designed more for *existing projects*, rather than *fresh projects*, and
so there is an opportunity to be a little stricter than you might otherwise
be with an existing codebase.
Here is a simple configuration file which would be suitable for a starter
project:
.. literalinclude:: /_partials/starter_config.cfg
:language: cfg
.. _nesting:
Nesting
^^^^^^^
**SQLFluff** uses **nesting** in its configuration files, with files
closer *overriding* (or *patching*, if you will) values from other files.
That means you'll end up with a final config which will be a patchwork
of all the values from the config files loaded up to that path. The exception
to this is the value for `templater`, which cannot be set in config files in
subdirectories of the working directory.
You don't **need** any config files to be present to make *SQLFluff*
work. If you do want to override any values though SQLFluff will use
files in the following locations in order, with values from later
steps overriding those from earlier:
0. *[...and this one doesn't really count]* There's a default config as
part of the SQLFluff package. You can find this below, in the
:ref:`defaultconfig` section.
1. It will look in the user's os-specific app config directory.
On macOS and Unix this is `~/.config/sqlfluff`, Windows is
`<home>\\AppData\\Local\\sqlfluff\\sqlfluff`, for any of the filenames
above in the main :ref:`setting_config` section. If multiple are present, they will
*patch*/*override* each other in the order above.
2. It will look for the same files in the user's home directory (~).
3. *[if the current working directory is a subdirectory of the user's home directory (~)]*
It will look for the same files in all directories between the
user's home directory (~), and the current working directory.
4. It will look for the same files in the current working directory.
5. *[if parsing a file in a subdirectory of the current working directory]*
It will look for the same files in every subdirectory between the
current working dir and the file directory.
6. It will look for the same files in the directory containing the file
being linted.
This whole structure leads to efficient configuration, in particular
in projects which utilise a lot of complicated templating.
.. _in_file_config:
In-File Configuration Directives
--------------------------------
In addition to configuration files mentioned above, SQLFluff also supports
comment based configuration switching in files. This allows specific SQL
file to modify a default configuration if they have specific needs.
When used, these apply to the whole file, and are parsed from the file in
an initial step before the rest of the file is properly parsed. This means
they can be used for both rule configuration and also for parsing
configuration.
To use these, the syntax must start as an *inline sql comment* beginning
with :code:`sqlfluff` (i.e. :code:`-- sqlfluff`). The line is then interpreted
as a colon-separated address of the configuration value you wish to set.
A few common examples are shown below:
.. code-block:: sql
-- Set Indented Joins
-- sqlfluff:indentation:indented_joins:True
-- Set a smaller indent for this file
-- sqlfluff:indentation:tab_space_size:2
-- Set keywords to be capitalised
-- sqlfluff:rules:capitalisation.keywords:capitalisation_policy:upper
SELECT *
FROM a
JOIN b USING(c)
We recommend only using this configuration approach for configuration that
applies to one file in isolation. For configuration changes for areas of
a project or for whole projects we recommend :ref:`nesting` of configuration
files.
This syntax is very similar to the method for :ref:`inline_ignoring_errors`.

View File

@@ -0,0 +1,146 @@
.. _dbt_templater:
:code:`dbt` templater
^^^^^^^^^^^^^^^^^^^^^
.. note::
From sqlfluff version 0.7.0 onwards, the dbt templater has been moved
to a separate plugin and python package. Projects that were already using
the dbt templater may initially fail after an upgrade to 0.7.0+. See the
installation instructions below to install the dbt templater.
dbt templating is still a relatively new feature added in 0.4.0 and
is still in very active development! If you encounter an issue, please
let us know in a GitHub issue or on the SQLFluff slack workspace.
:code:`dbt` is not the default templater for *SQLFluff* (it is :code:`jinja`).
:code:`dbt` is a complex tool, so using the default :code:`jinja` templater
will be simpler. You should be aware when using the :code:`dbt` templater that
you will be exposed to some of the complexity of :code:`dbt`. Users may wish to
try both templaters and choose according to how they intend to use *SQLFluff*.
A simple rule of thumb might be:
- If you are using *SQLFluff* in a CI/CD context, where speed is not
critical but accuracy in rendering sql is, then the `dbt` templater
may be more appropriate.
- If you are using *SQLFluff* in an IDE or on a git hook, where speed
of response may be more important, then the `jinja` templater may
be more appropriate.
Pros:
* Most (potentially all) macros will work
Cons:
* More complex, e.g. using it successfully may require deeper
understanding of your models and/or macros (including third-party macros)
* More configuration decisions to make
* Best practices are not yet established or documented
* If your :code:`dbt` model files access a database at compile time, using
SQLFluff with the :code:`dbt` templater will **also** require access to a
database.
* Note that you can often point SQLFluff and the :code:`dbt` templater at a
test database (i.e. it doesn't have to be the production database).
* Runs slower
Installation & Configuration
""""""""""""""""""""""""""""
In order to get started using *SQLFluff* with a dbt project you will
first need to install the relevant `dbt adapter`_ for your dialect
and the :code:`sqlfluff-templater-dbt` package using
your package manager of choice (e.g.
:code:`pip install dbt-postgres sqlfluff-templater-dbt`) and then will need the
following configuration:
.. _`dbt adapter`: https://docs.getdbt.com/docs/available-adapters
In *.sqlfluff*:
.. code-block:: cfg
[sqlfluff]
templater = dbt
In *.sqlfluffignore*:
.. code-block:: text
target/
# dbt <1.0.0
dbt_modules/
# dbt >=1.0.0
dbt_packages/
macros/
You can set the dbt project directory, profiles directory and profile with:
.. code-block:: cfg
[sqlfluff:templater:dbt]
project_dir = <relative or absolute path to dbt_project directory>
profiles_dir = <relative or absolute path to the directory that contains the profiles.yml file>
profile = <dbt profile>
target = <dbt target>
.. note::
If the `profiles_dir` setting is omitted, SQLFluff will look for the profile
in the default location, which varies by operating system. On Unix-like
operating systems (e.g. Linux or macOS), the default profile directory is
`~/.dbt/`. On Windows, you can determine your default profile directory by
running `dbt debug --config-dir`.
To use builtin dbt Jinja functions SQLFluff provides a configuration option
that enables usage within templates.
.. code-block:: cfg
[sqlfluff:templater:jinja]
apply_dbt_builtins = True
This will provide dbt macros like `ref`, `var`, `is_incremental()`. If the need
arises builtin dbt macros can be customised via Jinja macros in `.sqlfluff`
configuration file.
.. code-block:: cfg
[sqlfluff:templater:jinja:macros]
# Macros provided as builtins for dbt projects
dbt_ref = {% macro ref(model_ref) %}{{model_ref}}{% endmacro %}
dbt_source = {% macro source(source_name, table) %}{{source_name}}_{{table}}{% endmacro %}
dbt_config = {% macro config() %}{% for k in kwargs %}{% endfor %}{% endmacro %}
dbt_var = {% macro var(variable, default='') %}item{% endmacro %}
dbt_is_incremental = {% macro is_incremental() %}True{% endmacro %}
If your project requires that you pass variables to dbt through command line,
you can specify them in `template:dbt:context` section of `.sqlfluff`.
See below configuration and its equivalent dbt command:
.. code-block:: cfg
[sqlfluff:templater:dbt:context]
my_variable = 1
.. code-block:: text
dbt run --vars '{"my_variable": 1}'
Known Caveats
"""""""""""""
- To use the dbt templater, you must set `templater = dbt` in the `.sqlfluff`
config file in the directory where sqlfluff is run. The templater cannot
be changed in `.sqlfluff` files in subdirectories.
- In SQLFluff 0.4.0 using the dbt templater requires that all files
within the root and child directories of the dbt project must be part
of the project. If there are deployment scripts which refer to SQL files
not part of the project for instance, this will result in an error.
You can overcome this by adding any non-dbt project SQL files to
.sqlfluffignore.

View File

@@ -0,0 +1,100 @@
.. _templateconfig:
Templating Configuration
------------------------
This section explains how to configure templating for SQL files.
When writing SQL files, users might utilise some kind of templating.
The SQL file itself is written with placeholders which get rendered to proper
SQL at run time.
This can range from very simple placeholder templating to complex Jinja
templating.
SQLFluff supports templated sections in SQL, see :ref:`templater`.
This is achieved by the following set of operations:
1. SQLFluff pre-renders the templated SQL
2. SQLFluff applies the lint and fix operations to the rendered file
3. SQLFluff backports the rule violations to the templated section of the SQL.
SQLFluff does not automatically have access to the same environment used in
production template setup. This means it is necessary to either provide that
environment or provide dummy values to effectively render the template and
generate valid SQL. Refer to the templater sections below for details.
SQLFluff natively supports the following templating engines
- :ref:`jinja_templater`
- :ref:`placeholder_templater`
- :ref:`python_templater`
Also, SQLFluff has an integration to use :code:`dbt` as a templater.
- :ref:`dbt_templater` (via plugin which is covered in a different section).
.. note::
Templaters may not be able to generate a rendered SQL that cover
the entire raw file.
For example, if the raw SQL uses a :code:`{% if condition %}` block,
the rendered version of the template will only include either the
:code:`{% then %}` or the :code:`{% else %}` block (depending on the
provided configuration for the templater), but not both.
In this case, because SQLFluff linting can only operate on the output
of the templater, some areas of the raw SQL will never be seen by the
linter and will not be covered by lint rules.
This is functionality we hope to support in future.
.. toctree::
:maxdepth: 2
:caption: Templater Specific Configuration:
jinja
placeholder
python
dbt
.. _generic_variable_templating:
Generic Variable Templating
^^^^^^^^^^^^^^^^^^^^^^^^^^^
Variables are available in all the templaters.
By default the templating engine will expect variables for templating to be
available in the config, and the templater will be look in the section
corresponding to the context for that templater. By convention, the config for
the ``jinja`` templater is found in the ``sqlfluff:templater:jinja:context``
section, the config for the ``python`` templater is found in the
``sqlfluff:templater:python:context`` section, the one for the ``placeholder``
templater is found in the ``sqlfluff:templater:placeholder:context`` section.
For example, if passed the following *.sql* file:
.. code-block:: SQL+Jinja
SELECT {{ num_things }} FROM {{ tbl_name }} WHERE id > 10 LIMIT 5
...and the following configuration in *.sqlfluff* in the same directory:
.. code-block:: cfg
[sqlfluff:templater:jinja:context]
num_things=456
tbl_name=my_table
...then before parsing, the sql will be transformed to:
.. code-block:: sql
SELECT 456 FROM my_table WHERE id > 10 LIMIT 5
.. note::
If there are variables in the template which cannot be found in
the current configuration context, then this will raise a
`SQLTemplatingError` and this will appear as a violation without
a line number, quoting the name of the variable that couldn't be found.

View File

@@ -0,0 +1,417 @@
.. _jinja_templater:
Jinja templater
^^^^^^^^^^^^^^^
The Jinja templater uses Jinja2_ to render templates.
.. _Jinja2: https://jinja.palletsprojects.com/
There are multiple, complementary ways of configuring the Jinja templater.
- Reading variables and Jinja macros directly from the SQLFLuff config file
- Loading macros from a path
- Using a library
.. list-table:: Overview of Jinja templater's configuration options
:header-rows: 1
* - Configuration
- Variables
- Macros
- Filters
- Documentation
* - Config file
- ✅
- ✅
- ❌
- `Complex Jinja Variable Templating`_ and `Jinja Macro Templating (from config)`_
* - Macro Path
- ❌
- ✅
- ❌
- `Jinja Macro Templating (from file)`_
* - Library
- ✅
- ✅
- ✅
- `Library Templating`_
For example, a snippet from a :code:`.sqlfluff` file that uses all config
options:
.. code-block:: cfg
[sqlfluff]
templater = jinja
[sqlfluff:templater:jinja]
apply_dbt_builtins = True
load_macros_from_path = my_macros
loader_search_path = included_templates
library_path = sqlfluff_libs
exclude_macros_from_path = my_macros_exclude
[sqlfluff:templater:jinja:context]
my_list = ['a', 'b', 'c']
MY_LIST = ("d", "e", "f")
my_where_dict = {"field_1": 1, "field_2": 2}
[sqlfluff:templater:jinja:macros]
a_macro_def = {% macro my_macro(n) %}{{ n }} + {{ n * 2 }}{% endmacro %}
Complex Jinja Variable Templating
"""""""""""""""""""""""""""""""""
Apart from the Generic variable templating that is supported for all
templaters, two more advanced features of variable templating are available for
Jinja.
*case sensitivity* and *native python types*.
Both are illustrated in the following example:
.. code-block:: cfg
[sqlfluff:templater:jinja:context]
my_list = ['a', 'b', 'c']
MY_LIST = ("d", "e", "f")
my_where_dict = {"field_1": 1, "field_2": 2}
.. code-block:: SQL+Jinja
SELECT
{% for elem in MY_LIST %}
'{{elem}}' {% if not loop.last %}||{% endif %}
{% endfor %} as concatenated_list
FROM tbl
WHERE
{% for field, value in my_where_dict.items() %}
{{field}} = {{value}} {% if not loop.last %}and{% endif %}
{% endfor %}
...will render as...
.. code-block:: sql
SELECT
'd' || 'e' || 'f' as concatenated_list
FROM tbl
WHERE
field_1 = 1 and field_2 = 2
Note that the variable was replaced in a case sensitive way and that the
settings in the config file were interpreted as native python types.
Jinja Macro Templating (from config)
""""""""""""""""""""""""""""""""""""
Macros (which also look and feel like *functions* are available only in the
*jinja* templater. Similar to :ref:`generic_variable_templating`, these are
specified in config files, what's different in this case is how they are named.
Similar to the *context* section above, macros are configured separately in the
*macros* section of the config.
Consider the following example.
If passed the following *.sql* file:
.. code-block:: SQL+Jinja
SELECT {{ my_macro(6) }} FROM some_table
...and the following configuration in *.sqlfluff* in the same directory (note
the tight control of whitespace):
.. code-block:: cfg
[sqlfluff:templater:jinja:macros]
a_macro_def = {% macro my_macro(n) %}{{ n }} + {{ n * 2 }}{% endmacro %}
...then before parsing, the sql will be transformed to:
.. code-block:: sql
SELECT 6 + 12 FROM some_table
Note that in the code block above, the variable name in the config is
*a_macro_def*, and this isn't apparently otherwise used anywhere else.
Broadly this is accurate, however within the configuration loader this will
still be used to overwrite previous *values* in other config files. As such
this introduces the idea of config *blocks* which could be selectively
overwritten by other configuration files downstream as required.
Jinja Macro Templating (from file)
""""""""""""""""""""""""""""""""""
In addition to macros specified in the config file, macros can also be
loaded from files or folders. This is specified in the config file:
.. code-block:: cfg
[sqlfluff:templater:jinja]
load_macros_from_path = my_macros,other_macros
``load_macros_from_path`` is a comma-separated list of :code:`.sql` files or
folders. Locations are *relative to the config file*. For example, if the
config file above was found at :code:`/home/my_project/.sqlfluff`, then
SQLFluff will look for macros in the folders :code:`/home/my_project/my_macros/`
and :code:`/home/my_project/other_macros/`, including any of their subfolders.
Any macros defined in the config will always take precedence over a macro
defined in the path.
``exclude_macros_from_path`` works in the same manner as ``load_macros_from_path`` but
allows you to have sqlfluff ignore certain macros. This can be useful if you have
custom jinja tags.
Macros loaded from these files are available in every :code:`.sql` file without
requiring a Jinja :code:`include` or :code:`import`. They are loaded into the
`Jinja Global Namespace <https://jinja.palletsprojects.com/en/3.1.x/api/#global-namespace>`_.
**Note:** The :code:`load_macros_from_path` setting also defines the search
path for Jinja
`include <https://jinja.palletsprojects.com/en/3.1.x/templates/#include>`_ or
`import <https://jinja.palletsprojects.com/en/3.1.x/templates/#import>`_.
As with loaded macros, subdirectories are also supported. For example,
if :code:`load_macros_from_path` is set to :code:`my_macros`, and there is a
file :code:`my_macros/subdir/my_file.sql`, you can do:
.. code-block:: jinja
{% include 'subdir/my_file.sql' %}
If you would like to define the Jinja search path without also loading the
macros into the global namespace, use the :code:`loader_search_path` setting
instead.
.. note::
Throughout the templating process **whitespace** will still be treated
rigorously, and this includes **newlines**. In particular you may choose
to provide *dummy* macros in your configuration different from the actual
macros used in production.
**REMEMBER:** The reason SQLFluff supports macros is to *enable* it to parse
templated sql without it being a blocker. It shouldn't be a requirement that
the *templating* is accurate - it only needs to work well enough that
*parsing* and *linting* are helpful.
.. _builtin_jinja_blocks:
Builtin Jinja Macro Blocks
""""""""""""""""""""""""""
One of the main use cases which inspired *SQLFluff* as a project was `dbt`_.
It uses jinja templating extensively and leads to some users maintaining large
repositories of sql files which could potentially benefit from some linting.
.. note::
*SQLFluff* has now a tighter integration with dbt through the "dbt" templater.
It is the recommended templater for dbt projects. If used, it eliminates the
need for the overrides described in this section.
To use the dbt templater, go to :ref:`dbt_templater`.
*SQLFluff* anticipates this use case and provides some built in macro blocks
in the :ref:`defaultconfig` which assist in getting started with `dbt`_
projects. In particular it provides mock objects for:
* *ref*: The mock version of this provided simply returns the model reference
as the name of the table. In most cases this is sufficient.
* *config*: A regularly used macro in `dbt`_ to set configuration values. For
linting purposes, this makes no difference and so the provided macro simply
returns nothing.
.. note::
If there are other builtin macros which would make your life easier,
consider submitting the idea (or even better a pull request) on `github`_.
.. _`dbt`: https://www.getdbt.com/
.. _`github`: https://www.github.com/sqlfluff/sqlfluff
.. _jinja_library_templating:
Library Templating
""""""""""""""""""
If using *SQLFluff* with jinja as your templater, you may have library
function calls within your sql files that can not be templated via the
normal macro templating mechanisms:
.. code-block:: SQL+Jinja
SELECT foo, bar FROM baz {{ dbt_utils.group_by(2) }}
To template these libraries, you can use the `sqlfluff:jinja:library_path`
config option:
.. code-block:: cfg
[sqlfluff:templater:jinja]
library_path = sqlfluff_libs
This will pull in any python modules from that directory and allow sqlfluff
to use them in templates. In the above example, you might define a file at
`sqlfluff_libs/dbt_utils.py` as:
.. code-block:: python
def group_by(n):
return "GROUP BY 1,2"
If an `__init__.py` is detected, it will be loaded alongside any modules and
submodules found within the library path.
.. code-block:: SQL+Jinja
SELECT
{{ custom_sum('foo', 'bar') }},
{{ foo.bar.another_sum('foo', 'bar') }}
FROM
baz
`sqlfluff_libs/__init__.py`:
.. code-block:: python
def custom_sum(a: str, b: str) -> str:
return a + b
`sqlfluff_libs/foo/__init__.py`:
.. code-block:: python
# empty file
`sqlfluff_libs/foo/bar.py`:
.. code-block:: python
def another_sum(a: str, b: str) -> str:
return a + b
Additionally, the library can be used to expose `Jinja Filters <https://jinja.palletsprojects.com/en/3.1.x/templates/#filters>`_
to the Jinja environment used by SQLFluff.
This is achieve by setting a global variable named ``SQLFLUFF_JINJA_FILTERS``.
``SQLFLUFF_JINJA_FILTERS`` is a dictionary where
* dictionary keys map to the Jinja filter name
* dictionary values map to the Python callable
For example, to make the Airflow filter ``ds`` available to SQLFLuff, add
the following to the `__init__.py` of the library:
.. code-block:: python
# https://github.com/apache/airflow/blob/main/airflow/templates.py#L53
def ds_filter(value: datetime.date | datetime.time | None) -> str | None:
"""Date filter."""
if value is None:
return None
return value.strftime("%Y-%m-%d")
SQLFLUFF_JINJA_FILTERS = {"ds": ds_filter}
Now, ``ds`` can be used in SQL
.. code-block:: SQL+Jinja
SELECT "{{ "2000-01-01" | ds }}";
Jinja loader search path
""""""""""""""""""""""""
The Jinja environment can be configured to search for files included with
`include <https://jinja.palletsprojects.com/en/3.1.x/templates/#include>`_ or
`import <https://jinja.palletsprojects.com/en/3.1.x/templates/#import>`_ in a
list of folders. This is specified in the config file:
.. code-block:: cfg
[sqlfluff:templater:jinja]
loader_search_path = included_templates,other_templates
``loader_search_path`` is a comma-separated list of folders. Locations are
*relative to the config file*. For example, if the config file above was found
at :code:`/home/my_project/.sqlfluff`, then SQLFluff will look for included
files in the folders :code:`/home/my_project/included_templates/` and
:code:`/home/my_project/other_templates/`, including any of their subfolders.
For example, this will read from
:code:`/home/my_project/included_templates/my_template.sql`:
.. code-block:: jinja
{% include 'included_templates/my_template.sql' %}
Any folders specified in the :code:`load_macros_from_path` setting are
automatically appended to the ``loader_search_path``. It is not necessary to
specify a given directory in both settings.
Unlike the :code:`load_macros_from_path` setting, any macros within these
folders are *not* automatically loaded into the global namespace. They must be
explicitly imported using the
`import <https://jinja.palletsprojects.com/en/3.1.x/templates/#import>`_ Jinja
directive. If you would like macros to be automatically included in the
global Jinja namespace, use the :code:`load_macros_from_path` setting instead.
Interaction with ``--ignore=templating``
""""""""""""""""""""""""""""""""""""""""
Ignoring Jinja templating errors provides a way for users to use SQLFluff
while reducing or avoiding the need to spend a lot of time adding variables
to ``[sqlfluff:templater:jinja:context]``.
When ``--ignore=templating`` is enabled, the Jinja templater behaves a bit
differently. This additional behavior is *usually* but not *always* helpful
for making the file at least partially parsable and fixable. It definitely
doesnt **guarantee** that every file can be fixed, but its proven useful for
some users.
Here's how it works:
* Within the expanded SQL, undefined variables are automatically *replaced*
with the corresponding string value.
* If you do: ``{% include query %}``, and the variable ``query`` is not
defined, it returns a “file” containing the string ``query``.
* If you do: ``{% include "query_file.sql" %}``, and that file does not exist
or you havent configured a setting for ``load_macros_from_path`` or
``loader_search_path``, it returns a “file” containing the text
``query_file``.
For example:
.. code-block:: SQL+Jinja
select {{ my_variable }}
from {% include "my_table.sql" %}
is interpreted as:
.. code-block:: sql
select my_variable
from my_table
The values provided by the Jinja templater act *a bit* (not exactly) like a
mixture of several types:
* ``str``
* ``int``
* ``list``
* Jinja's ``Undefined`` `class <https://jinja.palletsprojects.com/en/3.1.x/api/#jinja2.Undefined>`_
Because the values behave like ``Undefined``, it's possible to replace them
using Jinja's ``default()`` `filter <https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.default>`_.
For example:
.. code-block:: SQL+Jinja
select {{ my_variable | default("col_a") }}
from my_table
is interpreted as:
.. code-block:: sql
select col_a
from my_table

View File

@@ -0,0 +1,106 @@
.. _placeholder_templater:
Placeholder templater
^^^^^^^^^^^^^^^^^^^^^
Libraries such as SQLAlchemy or Psycopg use different parameter placeholder
styles to mark where a parameter has to be inserted in the query.
For example a query in SQLAlchemy can look like this:
.. code-block:: sql
SELECT * FROM table WHERE id = :myid
At runtime `:myid` will be replace by a value provided by the application and
escaped as needed, but this is not standard SQL and cannot be parsed as is.
In order to parse these queries is then necessary to replace these
placeholders with sample values, and this is done with the placeholder
templater.
Placeholder templating can be enabled in the config using:
.. code-block:: cfg
[sqlfluff]
templater = placeholder
A few common styles are supported:
.. code-block:: sql
:force:
-- colon
WHERE bla = :my_name
-- colon_nospaces
-- (use with caution as more prone to false positives)
WHERE bla = table:my_name
-- colon_optional_quotes
SELECT :"column" FROM :table WHERE bla = :'my_name'
-- numeric_colon
WHERE bla = :2
-- pyformat
WHERE bla = %(my_name)s
-- dollar
WHERE bla = $my_name or WHERE bla = ${my_name}
-- question_mark
WHERE bla = ?
-- numeric_dollar
WHERE bla = $3 or WHERE bla = ${3}
-- percent
WHERE bla = %s
-- ampersand
WHERE bla = &s or WHERE bla = &{s} or USE DATABASE MARK_{ENV}
These can be configured by setting `param_style` to the names above:
.. code-block:: cfg
[sqlfluff:templater:placeholder]
param_style = colon
my_name = 'john'
then you can set sample values for each parameter, like `my_name`
above. Notice that the value needs to be escaped as it will be replaced as a
string during parsing. When the sample values aren't provided, the templater
will use parameter names themselves by default.
When parameters are positional, like `question_mark`, then their name is
simply the order in which they appear, starting with `1`.
.. code-block:: cfg
[sqlfluff:templater:placeholder]
param_style = question_mark
1 = 'john'
In case you need a parameter style different from the ones above, you can pass
a custom regex.
.. code-block:: cfg
[sqlfluff:templater:placeholder]
param_regex = __(?P<param_name>[\w_]+)__
my_name = 'john'
N.B. quotes around `param_regex` in the config are
interpreted literally by the templater.
e.g. `param_regex='__(?P<param_name>[\w_]+)__'` matches
`'__some_param__'` not `__some_param__`
the named parameter `param_name` will be used as the key to replace, if
missing, the parameter is assumed to be positional and numbers are used
instead.
Also consider making a pull request to the project to have your style added,
it may be useful to other people and simplify your configuration.

View File

@@ -0,0 +1,58 @@
.. _python_templater:
Python templater
^^^^^^^^^^^^^^^^
Uses native Python f-strings. As described in
:ref:`generic_variable_templating`, an example usage would look be
configured as follows:
If passed the following *.sql* file:
.. code-block::
SELECT * FROM {tbl_name}
...and the following configuration in *.sqlfluff* in the same directory:
.. code-block:: cfg
[sqlfluff]
templater = python
[sqlfluff:templater:python:context]
tbl_name = my_table
...then before parsing, the sql will be transformed to:
.. code-block:: sql
SELECT * FROM my_table
Complex Python Variable Templating
""""""""""""""""""""""""""""""""""""
`Python string formatting`_ supports accessing object attributes
via dot notation (e.g. :code:`{foo.bar}`). However, since we cannot create Python
objects within configuration files, we need a workaround in order to provide
dummy values to render templates containing these values. The SQLFluff
python templater will interpret any variable containing a "." as a
dictionary lookup on the *magic* fixed context key :code:`sqlfluff`.
.. code-block::
-- this SQL
SELECT * FROM {foo.bar}
-- becomes this
SELECT * FROM {sqlfluff["foo.bar"]}
..which can be populated using the following configuration:
.. code-block:: cfg
[sqlfluff:templater:python:context]
sqlfluff = {"foo.bar": "abc"}
.. _`Python string formatting`: https://docs.python.org/3/library/string.html#format-string-syntax

View File

@@ -1,61 +0,0 @@
.. _developingpluginsref:
Developing Plugins
==================
*SQLFluff* is extensible through "plugins". We use the `pluggy library`_
to make linting Rules pluggable, which enable users to implement rules that
are just too "organization specific" to be shared, or too platform specific
to be included in the core library.
.. _`pluggy library`: https://pluggy.readthedocs.io/en/latest/
Creating a plugin
-----------------
We have an example plugin in
`sqlfluff/plugins/sqlfluff-plugin-example`_ which you can use as a template
for rules, or the `sqlfluff/plugins/sqlfluff-templater-dbt`_ which you can
use as a template for templater plugins.
Few things to note about plugins:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Currently, only Rules and Templaters can be added through plugins. Over time
we expect more elements of SQLFluff will be extensible with plugins. Each
plugin can implement multiple Rules or Templaters.
We recomment that the name of a plugin should start with *"sqlfluff-"* to be
clear on the purpose of your plugin.
A plugin may need to include a default configuration if its rules
are configurable: use plugin default configurations **only for that reason**!
We advise against overwriting core configurations by using a default
plugin configuration, as there is no mechanism in place to enforce precendence
between the core library configs and plugin configs,
and multiple plugins could clash.
A plugin Rule class name should have the structure:
"Rule_PluginName_L000". The 'L' can be any letter
and is meant to categorize rules; you could use the
letter 'S' to denote rules that enforce security checks
for example.
A plugin Rule code includes the PluginName,
so a rule "Rule_L000" in core will have code "L000",
while "Rule_PluginName_L000" will have code "PluginName_L000".
Codes are used to display errors, they are also used as configuration keys.
We make it easy for plugin developers to test their rules by
exposing a testing library in *sqlfluff.testing*.
.. _`sqlfluff/plugins/sqlfluff-plugin-example`: https://github.com/sqlfluff/sqlfluff/tree/main/plugins/sqlfluff-plugin-example
.. _`sqlfluff/plugins/sqlfluff-templater-dbt`: https://github.com/sqlfluff/sqlfluff/tree/main/plugins/sqlfluff-templater-dbt
Giving feedback
---------------
Would you like to have other parts of *SQLFluff* be "pluggable"?
Tell us about it in a `GitHub issue`_ 😄.
.. _`GitHub issue`: https://github.com/sqlfluff/sqlfluff/issues/new?assignees=&labels=enhancement&template=enhancement.md

View File

@@ -1,52 +0,0 @@
.. _developingrulesref:
Developing Rules
================
`Rules` in `SQLFluff` are implemented as `crawlers`. These are entities
which work their way through the parsed structure of a query to evaluate
a particular rule or set of rules. The intent is that the definition of
each specific rule should be really streamlined and only contain the logic
for the rule itself, with all the other mechanics abstracted away.
Base Rules
----------
`base_rules` Module
^^^^^^^^^^^^^^^^^^^
.. automodule:: sqlfluff.core.rules.base
:members:
Functional API
--------------
These newer modules provide a higher-level API for rules working with segments
and slices. Rules that need to navigate or search the parse tree may benefit
from using these. Eventually, the plan is for **all** rules to use these
modules. As of December 30, 2021, 17+ rules use these modules.
The modules listed below are submodules of `sqlfluff.core.rules.functional`.
`segments` Module
^^^^^^^^^^^^^^^^^
.. automodule:: sqlfluff.core.rules.functional.segments
:members:
`segment_predicates` Module
^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automodule:: sqlfluff.core.rules.functional.segment_predicates
:members:
`raw_file_slices` Module
^^^^^^^^^^^^^^^^^^^^^^^^
.. automodule:: sqlfluff.core.rules.functional.raw_file_slices
:members:
`raw_file_slice_predicates` Module
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. automodule:: sqlfluff.core.rules.functional.raw_file_slice_predicates
:members:

View File

@@ -1,174 +0,0 @@
.. _dialectref:
Dialects Reference
==================
SQLFluff is designed to be flexible in supporting a variety of dialects.
Not all potential dialects are supported so far, but several have been
implemented by the community. Below are a list of the currently available
dialects. Each inherits from another, up to the root `ansi` dialect.
For a canonical list of supported dialects, run the
:program:`sqlfluff dialects` command, which will output a list of the
current dialects available on your installation of SQLFluff.
.. note::
For technical users looking to add new dialects or add new features
to existing ones, the dependent nature of how dialects have been
implemented is to try and reduce the amount of repetition in how
different elements are defined. As an example, when we say that
the :ref:`redshift_dialect_ref` dialect *inherits* from the
:ref:`postgres_dialect_ref` dialect this is not because there
is an agreement between those projects which means that features
in one must end up in the other, but that the design of the
:ref:`redshift_dialect_ref` dialect was heavily *inspired* by the
postgres dialect and therefore when defining the dialect within
sqlfuff it makes sense to use :ref:`postgres_dialect_ref` as a
starting point rather than starting from scratch.
Consider when adding new features to a dialect:
- Should I be adding it just to this dialect, or adding it to
a *parent* dialect?
- If I'm creating a new dialect, which dialect would be best to
inherit from?
- Will the feature I'm adding break any *downstream* dependencies
within dialects which inherit from this one?
.. _ansi_dialect_ref:
ANSI
----
This is the base dialect which holds most of the definitions of common
SQL commands and structures. If the dialect which you're actually using
isn't specifically implemented by SQLFluff, using this dialect is a good
place to start.
This dialect doesn't intend to be brutal in adhering to (and only to) the
ANSI SQL spec *(mostly because ANSI charges for access to that spec)*. It aims
to be a representation of vanilla SQL before any other project adds their
spin to it, and so may contain a slightly wider set of functions than actually
available in true ANSI SQL.
.. _bigquery_dialect_ref:
BigQuery
--------
The dialect for `Google BigQuery`_.
.. _`Google BigQuery`: https://cloud.google.com/bigquery/
.. _exasol_dialect_ref:
Exasol
------
The dialect for `Exasol`_.
.. _`Exasol`: https://www.exasol.com/
.. _hive_dialect_ref:
Hive
----
The dialect for `Hive`_.
.. _`Hive`: https://hive.apache.org/
.. _mysql_dialect_ref:
MySQL
-----
The dialect for `MySQL`_.
.. _`MySQL`: https://www.mysql.com/
.. _oracle_dialect_ref:
Oracle
------
The dialect for `Oracle`_ SQL. Note: this does not include PL/SQL.
.. _`Oracle`: https://www.oracle.com/database/technologies/appdev/sql.html
.. _postgres_dialect_ref:
PostgreSQL
----------
This is based around the `PostgreSQL spec`_. Many other SQL instances are often
based on PostreSQL syntax. If you're running an unsupported dialect, then
this is often the dialect to use (until someone makes a specific dialect).
.. _`PostgreSQL spec`: https://www.postgresql.org/docs/9.6/reference.html
.. _redshift_dialect_ref:
Redshift
----------
The dialect for `Amazon Redshift`_.
.. _`Amazon Redshift`: https://aws.amazon.com/redshift/
.. _snowflake_dialect_ref:
Snowflake
---------
The dialect for `Snowflake`_, which has much of its syntax
inherited from :ref:`postgres_dialect_ref`.
.. _`Snowflake`: https://docs.snowflake.com/en/sql-reference.html
.. _spark3_dialect_ref:
Spark3
------
The dialect for `Spark3`_. It inherits from :ref:`ansi_dialect_ref` and
includes relevant syntax from :ref:`hive_dialect_ref` for commands that
permit Hive Format.
This implementation focuses on the `ANSI Compliant dialect`_ introduced in
Spark3, instead of being Hive Compliant. The introduction of ANSI Compliance
provides better data quality and easier migration from traditional DBMS.
Versions of Spark prior to 3.x will only support the Hive dialect.
.. _`Spark3`: https://spark.apache.org/docs/latest/sql-ref.html
.. _`Ansi Compliant dialect`: https://spark.apache.org/docs/latest/sql-ref-ansi-compliance.html
.. _sqlite_dialect_ref:
SQLite
------
The dialect for `SQLite`_.
.. _`SQLite`: https://www.sqlite.org/
.. _tsql_dialect_ref:
T-SQL
-----
The dialect for `T-SQL`_ (aka Transact-SQL).
.. _`T-SQL`: https://docs.microsoft.com/en-us/sql/t-sql/language-reference
.. _teradata_dialect_ref:
Teradata
--------
The dialect for `Teradata`_.
.. _`Teradata`: https://www.teradata.co.uk/

View File

@@ -43,7 +43,9 @@ If however, you do have python installed but not :code:`pip`, then
the best instructions for what to do next are `on the python website`_.
.. _`instructions for all platforms here`: https://wiki.python.org/moin/BeginnersGuide/Download
.. _`on the python website`: https://pip.pypa.io/en/stable/installing/
.. _`on the python website`: https://pip.pypa.io/en/stable/installation/
.. _installingsqlfluff:
Installing SQLFluff
-------------------
@@ -61,7 +63,7 @@ version number.
.. code-block:: text
$ sqlfluff version
0.3.1
3.2.5
Basic Usage
-----------
@@ -76,29 +78,40 @@ same folder that you're currently in with the following content:
SELECT a+b AS foo,
c AS bar from my_table
You can then run :code:`sqlfluff lint test.sql` to lint this file.
You can then run :code:`sqlfluff lint test.sql --dialect ansi` to lint this
file.
.. code-block:: text
$ sqlfluff lint test.sql
$ sqlfluff lint test.sql --dialect ansi
== [test.sql] FAIL
L: 1 | P: 1 | L036 | Select targets should be on a new line unless there is
L: 1 | P: 1 | LT09 | Select targets should be on a new line unless there is
| only one select target.
L: 1 | P: 8 | L034 | Use wildcards then simple select targets before
| calculations and aggregates.
L: 1 | P: 9 | L006 | Missing whitespace before +
L: 1 | P: 9 | L006 | Missing whitespace after +
L: 1 | P: 11 | L039 | Unnecessary whitespace found.
L: 2 | P: 1 | L003 | Indent expected and not found compared to line #1
L: 2 | P: 10 | L010 | Keywords must be consistently upper case.
L: 2 | P: 15 | L009 | Files must end with a single trailing newline.
| [layout.select_targets]
L: 1 | P: 1 | ST06 | Select wildcards then simple targets before calculations
| and aggregates. [structure.column_order]
L: 1 | P: 7 | LT02 | Expected line break and indent of 4 spaces before 'a'.
| [layout.indent]
L: 1 | P: 9 | LT01 | Expected single whitespace between naked identifier and
| binary operator '+'. [layout.spacing]
L: 1 | P: 10 | LT01 | Expected single whitespace between binary operator '+'
| and naked identifier. [layout.spacing]
L: 1 | P: 11 | LT01 | Expected only single space before 'AS' keyword. Found '
| '. [layout.spacing]
L: 2 | P: 1 | LT02 | Expected indent of 4 spaces.
| [layout.indent]
L: 2 | P: 9 | LT02 | Expected line break and no indent before 'from'.
| [layout.indent]
L: 2 | P: 10 | CP01 | Keywords must be consistently upper case.
| [capitalisation.keywords]
All Finished 📜 🎉!
You'll see that *SQLFluff* has failed the linting check for this file.
On each of the following lines you can see each of the problems it has
found, with some information about the location and what kind of
problem there is. One of the errors has been found on *line 1*, *position *
(as shown by :code:`L: 1 | P: 9`) and it's a problem with rule
*L006* (for a full list of rules, see :ref:`ruleref`). From this
*LT01* (for a full list of rules, see :ref:`ruleref`). From this
(and the following error) we can see that the problem is that there
is no space either side of the :code:`+` symbol in :code:`a+b`.
Head into the file, and correct this issue so that the file now
@@ -110,20 +123,27 @@ looks like this:
c AS bar from my_table
Rerun the same command as before, and you'll see that the original
error (violation of *L006*) no longer shows up.
error (violation of *LT01*) no longer shows up.
.. code-block:: text
$ sqlfluff lint test.sql
$ sqlfluff lint test.sql --dialect ansi
== [test.sql] FAIL
L: 1 | P: 1 | L036 | Select targets should be on a new line unless there is
L: 1 | P: 1 | LT09 | Select targets should be on a new line unless there is
| only one select target.
L: 1 | P: 8 | L034 | Use wildcards then simple select targets before
| calculations and aggregates.
L: 1 | P: 13 | L039 | Unnecessary whitespace found.
L: 2 | P: 1 | L003 | Indent expected and not found compared to line #1
L: 2 | P: 10 | L010 | Keywords must be consistently upper case.
L: 2 | P: 15 | L009 | Files must end with a single trailing newline.
| [layout.select_targets]
L: 1 | P: 1 | ST06 | Select wildcards then simple targets before calculations
| and aggregates. [structure.column_order]
L: 1 | P: 7 | LT02 | Expected line break and indent of 4 spaces before 'a'.
| [layout.indent]
L: 1 | P: 13 | LT01 | Expected only single space before 'AS' keyword. Found '
| '. [layout.spacing]
L: 2 | P: 1 | LT02 | Expected indent of 4 spaces.
| [layout.indent]
L: 2 | P: 9 | LT02 | Expected line break and no indent before 'from'.
| [layout.indent]
L: 2 | P: 10 | CP01 | Keywords must be consistently upper case.
| [capitalisation.keywords]
To fix the remaining issues, we're going to use one of the more
advanced features of *SQLFluff*, which is the *fix* command. This
@@ -133,18 +153,23 @@ and there may be some situations where a fix may not be able to be
applied because of the context of the query, but in many simple cases
it's a good place to start.
For now, we only want to fix the following rules: *L003*, *L009*, *L010*
For now, we only want to fix the following rules: *LT02*, *LT12*, *CP01*
.. code-block:: text
$ sqlfluff fix test.sql --rules L003,L009,L010
$ sqlfluff fix test.sql --rules LT02,LT12,CP01 --dialect ansi
==== finding violations ====
== [test.sql] FAIL
L: 2 | P: 1 | L003 | Indent expected and not found compared to line #1
L: 2 | P: 10 | L010 | Keywords must be consistently upper case.
L: 2 | P: 15 | L009 | Files must end with a single trailing newline.
L: 1 | P: 7 | LT02 | Expected line break and indent of 4 spaces before 'a'.
| [layout.indent]
L: 2 | P: 1 | LT02 | Expected indent of 4 spaces.
| [layout.indent]
L: 2 | P: 9 | LT02 | Expected line break and no indent before 'FROM'.
| [layout.indent]
L: 2 | P: 10 | CP01 | Keywords must be consistently upper case.
| [capitalisation.keywords]
==== fixing violations ====
3 fixable linting violations found
4 fixable linting violations found
Are you sure you wish to attempt to fix these? [Y/n]
...at this point you'll have to confirm that you want to make the
@@ -163,33 +188,32 @@ now different.
.. code-block:: sql
SELECT a + b AS foo,
c AS bar FROM my_table
SELECT
a + b AS foo,
c AS bar
FROM my_table
In particular:
* The second line has been indented to reflect being inside the
* The two columns have been indented to reflect being inside the
:code:`SELECT` statement.
* The :code:`FROM` keyword has been capitalised to match the
other keywords.
* A final newline character has been added at the end of the
file (which may not be obvious in the snippet above).
We could also fix *all* of the fixable errors by not
specifying :code:`--rules`.
.. code-block:: text
$ sqlfluff fix test.sql
$ sqlfluff fix test.sql --dialect ansi
==== finding violations ====
== [test.sql] FAIL
L: 1 | P: 1 | L036 | Select targets should be on a new line unless there is
| only one select target.
L: 1 | P: 8 | L034 | Use wildcards then simple select targets before
| calculations and aggregates.
L: 1 | P: 13 | L039 | Unnecessary whitespace found.
L: 1 | P: 1 | ST06 | Select wildcards then simple targets before calculations
| and aggregates. [structure.column_order]
L: 2 | P: 10 | LT01 | Expected only single space before 'AS' keyword. Found '
| '. [layout.spacing]
==== fixing violations ====
3 fixable linting violations found
2 fixable linting violations found
Are you sure you wish to attempt to fix these? [Y/n] ...
Attempting fixes...
Persisting Changes...
@@ -203,7 +227,8 @@ been updated again.
SELECT
c AS bar,
a + b AS foo FROM my_table
a + b AS foo
FROM my_table
The SQL statement is now well formatted according to all the
rules defined in SQLFluff.
@@ -229,17 +254,20 @@ put the following content:
.. code-block:: cfg
[sqlfluff:rules]
[sqlfluff]
dialect = ansi
[sqlfluff:indentation]
tab_space_size = 2
[sqlfluff:rules:L010]
[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = lower
Then rerun the same command as before.
.. code-block:: text
$ sqlfluff fix test.sql --rules L003,L009,L010,L034,L036,L039
$ sqlfluff fix test.sql --rules LT02,LT12,CP01,ST06,LT09,LT01
Then examine the file again, and you'll notice that the
file has been fixed accordingly.
@@ -247,10 +275,13 @@ file has been fixed accordingly.
.. code-block:: sql
select
c as bar,
a + b as foo from my_table
c as bar,
a + b as foo
from my_table
For a full list of configuration options check out :ref:`defaultconfig`.
Note that in our example here we've only set a few configuration values
and any other configuration settings remain as per the default config.
To see how these options apply to specific rules check out the
"Configuration" section within each rule's documentation in :ref:`ruleref`.
@@ -270,6 +301,8 @@ From here, there are several more things to explore.
* To find out more about which rules are available, see :ref:`ruleref`.
* To find out more about configuring *SQLFluff* and what other options
are available, see :ref:`config`.
* Once you're ready to start using *SQLFluff* on a project or with the
rest of your team, check out :ref:`production-use`.
One last thing to note is that *SQLFluff* is a relatively new project
and you may find bugs or strange things while using it. If you do find

View File

@@ -0,0 +1,131 @@
.. _architecture:
Architecture
------------
At a high level, the behaviour of SQLFluff is divided into a few key stages.
Whether calling `sqlfluff lint`, `sqlfluff fix` or `sqlfluff parse`, the
internal flow is largely the same.
.. _templater:
Stage 1, the templater
^^^^^^^^^^^^^^^^^^^^^^
This stage only applies to templated SQL. Vanilla SQL is sent straight to
stage 2, the lexer.
In order to lint templated SQL, SQLFluff must first convert the 'raw' or
pre-templated code into valid SQL, which can then be parsed. The templater
returns both the raw and post-templated SQL so that any rule violations which
occur in templated sections can be ignored and the rest mapped to their
original line location for user feedback.
.. _Jinja: https://jinja.palletsprojects.com/
.. _dbt: https://docs.getdbt.com/
.. _`Python format strings`: https://docs.python.org/3/library/string.html#format-string-syntax
*SQLFluff* supports multiple templating engines:
* Jinja_
* SQL placeholders (e.g. SQLAlchemy parameters)
* `Python format strings`_
* dbt_ (via plugin)
Under the hood dbt also uses Jinja, but in *SQLFluff* uses a separate
mechanism which interfaces directly with the dbt python package.
For more details on how to configure the templater see :ref:`templateconfig`.
Stage 2, the lexer
^^^^^^^^^^^^^^^^^^
The lexer takes SQL and separates it into segments of whitespace and
code. Where we can impart some high level meaning to segments, we
do, but the result of this operation is still a flat sequence of
typed segments (all subclasses of :code:`RawSegment`).
Stage 3, the parser
^^^^^^^^^^^^^^^^^^^
The parser is arguably the most complicated element of SQLFluff, and is
relied on by all the other elements of the tool to do most of the heavy
lifting.
#. The lexed segments are parsed using the specified dialect's grammars. In
SQLFluff, grammars describe the shape of SQL statements (or their
components). The parser attempts to apply each potential grammar to the
lexed segments until all the segments have been matched.
#. In SQLFluff, segments form a tree-like structure. The top-level segment is
a :code:`FileSegment`, which contains zero or more
:code:`StatementSegment`\ s, and so on. Before the segments have been parsed
and named according to their type, they are 'raw', meaning they have no
classification other than their literal value.
#. A segment's :code:`.match()` method uses the :code:`match_grammar`, on
which :code:`.match()` is called. SQLFluff parses in a single pass through
the file, so segments will recursively match the file based on their
respective grammars. In the example of a :code:`FileSegment`, it
first divides up the query into statements, and then the :code:`.match()`
method of those segments works out the structure within them.
* *Segments* must implement a :code:`match_grammar`. When :code:`.match()`
is called on a segment, this is the grammar which is used to decide
whether there is a match.
* *Grammars* combine *segments* or other *grammars* together in a
pre-defined way. For example the :code:`OneOf` grammar will match if any
one of its child elements match.
#. During the recursion, the parser eventually reaches segments which have
no children (raw segments containing a single token), and so the
recursion naturally finishes.
#. If no match is found for a segment, the contents will be wrapped in an
:code:`UnparsableSegment` which is picked up as a *parsing* error later.
This is usually facilitated by the :code:`ParseMode` on some grammars
which can be set to :code:`GREEDY`, allowing the grammar to capture
additional segments as unparsable. As an example, bracketed sections
are often configured to capture anything unexpected as unparsable rather
than simply failing to match if there is more than expected (which would
be the default, :code:`STRICT`, behaviour).
#. The result of the :code:`.match()` method is a :code:`MatchResult` which
contains the instructions on how to turn the flat sequence of raw segments
into a nested tree of segments. Calling :code:`.apply()` on this result
at the end of the matching process is what finally creates the nested
structure.
When working on the parser there are a couple of design principles
to keep in mind.
- Grammars are contained in *dialects*, the root dialect being
the *ansi* dialect. The ansi dialect is used to host logic common
to all dialects, and so does not necessarily adhere to the formal
ansi specification. Other SQL dialects inherit from the ansi dialect,
replacing or patching any segments they need to. One reason for the *Ref*
grammar is that it allows name resolution of grammar elements at runtime
and so a *patched* grammar with some elements overridden can still rely on
lower-level elements which haven't been redeclared within the dialect
- All grammars and segments attempt to match as much as they can and will
return partial matches where possible. It is up to the calling grammar
or segment to decide whether a partial or complete match is required
based on the context it is matching in.
Stage 4, the linter
^^^^^^^^^^^^^^^^^^^
Given the complete parse tree, rule classes check for linting errors by
traversing the tree, looking for segments and patterns of concern. If
the rule discovers a violation, it returns a
:py:class:`~sqlfluff.core.rules.base.LintResult` pointing to the segment
which caused the violation.
Some rules are able to *fix* the problems they find. If this is the case,
the rule will return a list of fixes, which describe changes to be made to
the tree. This can include edits, inserts, or deletions. Once the fixes
have been applied, the updated tree is written to the original file.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,121 @@
Documentation Contributions
===========================
Contributing to the docs is one of the easiest and most helpful ways
to help the project. Documentation changes require relatively little
specialist knowledge apart from being familiar with how to use SQLFluff
and the docs are read by a very wide range of people.
Documentation takes two forms:
1. Embedded documentation found in function and module `docstrings`_.
2. The free-standing documentation which you're reading now, and hosted
at `docs.sqlfluff.com`_ (built using `sphinx`_ and `ReadtheDocs`_).
The two are somewhat blurred by the use of `autodoc`_ (and some other custom
integrations), where documentation is generated directly off `docstrings`_
within the codebase, for example the :ref:`ruleref`, :ref:`cliref` and
:ref:`dialectref`. To understand more about how the custom integrations
we use to generate these docs, see the `generate-auto-docs.py`_ file.
.. _`docstrings`: https://en.wikipedia.org/wiki/Docstring
.. _`docs.sqlfluff.com`: https://docs.sqlfluff.com
.. _`autodoc`: https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html
.. _`generate-auto-docs.py`: https://github.com/sqlfluff/sqlfluff/blob/main/docs/generate-auto-docs.py
.. _`ReadtheDocs`: https://about.readthedocs.com/
Docstrings
----------
Embedded documentation of functions, classes and modules is most useful
for *developer-focussed* documentation as it's most accessible in the places
which those developers are working: *directly in the codebase*. We enforce
that docstrings are present and correctly formatted using the
`pydocstyle rules for ruff`_, which we have configured to enforce the
`google style of docstrings`_.
.. _`pydocstyle rules for ruff`: https://docs.astral.sh/ruff/rules/#pydocstyle-d
.. _`google style of docstrings`: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html
Sphinx Docs
-----------
The main documentation (which you're reading now), is build using `sphinx`_,
and written using `reStructuredText`_ (files ending with :code:`.rst`). The
`sphinx`_ project offers a `reStructuredText primer`_ for people who are new
to the syntax (and the SQLFluff project uses `doc8`_ in the CI process to try
and catch any issues early).
On top of those docs, there are a few areas worth highlighting for new (or
returning) users, which are either specific to the SQLFluff project, or not
particularly clear in the sphinx docs:
* `reStructuredText`_ is very similar to, but differs from (the somewhat more
well known) `Markdown`_ syntax. Importantly:
* :code:`*text with single asterisks*` renders as *italics*. Use
:code:`**double asterisks**` for **bold text**.
* :code:`code snippets` are created using the |codesnippet|
directive, rather than just lone backticks (|backquotes|) as found in
most `Markdown`_.
* To create links to other parts of the documentation (i.e.
`Cross-referencing`_), use either the :code:`:ref:` syntax.
* Docs for all the SQL dialects are auto generated with associated anchors
to use for referencing. For example to link to the
:ref:`postgres_dialect_ref` dialect docs, you can use the |postgresref|.
Replace the :code:`postgres` portion with the :code:`name` of the
dialect you want to link to.
* Docs for all the bundled rules and handled using a customer `sphinx`_
plugin, which means you can refer to them using their name or code:
|LT01ref| resolves to :sqlfluff:ref:`LT01` and |layoutspacingref|
resolves to :sqlfluff:ref:`layout.spacing`.
* Docs for any of the python classes and modules handled using `autodoc`_
can be referenced as per their docs, so the
:py:class:`sqlfluff.core.rules.base.BaseRule` class can be referenced
with |baseruleref|. You can also use the :code:`~` prefix (i.e.
|shortbaseruleref|) so that it just renders as
:py:class:`~sqlfluff.core.rules.base.BaseRule`. See the docs for
`Cross-referencing`_ for more details.
.. _`sphinx`: https://www.sphinx-doc.org/en/master/
.. _`reStructuredText`: https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html
.. _`reStructuredText primer`: https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html
.. _`doc8`: https://github.com/PyCQA/doc8
.. _`Markdown`: https://www.markdownguide.org/
.. _`Cross-referencing`: https://www.sphinx-doc.org/en/master/usage/referencing.html
.. _`autodoc`: https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html
.. |codesnippet| raw:: html
<code class="code docutils literal notranslate">:code:`...`</code>
.. |backquotes| raw:: html
<code class="code docutils literal notranslate">`...`</code>
.. |postgresref| raw:: html
<code class="code docutils literal notranslate">:ref:`postgres_dialect_ref`</code>
.. |LT01ref| raw:: html
<code class="code docutils literal notranslate">:sqlfluff:ref:`LT01`</code>
.. |layoutspacingref| raw:: html
<code class="code docutils literal notranslate">:sqlfluff:ref:`layout.spacing`</code>
.. |baseruleref| raw:: html
<code class="code docutils literal notranslate">:py:class:`sqlfluff.core.rules.base.BaseRule`</code>
.. |shortbaseruleref| raw:: html
<code class="code docutils literal notranslate">:py:class:`~sqlfluff.core.rules.base.BaseRule`</code>

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@@ -0,0 +1,96 @@
.. _developingpluginsref:
Developing Plugins
==================
*SQLFluff* is extensible through "plugins". We use the `pluggy library`_
to make linting Rules pluggable, which enable users to implement rules that
are just too "organization specific" to be shared, or too platform specific
to be included in the core library.
.. note::
We recommend that the module in a plugin which defines all
of the hook implementations (anything using the ``@hookimpl`` decorator)
must be able to fully import before any rule implementations are imported.
More specifically, SQLFluff must be able to both *import* **and**
*run* any implementations of ``get_configs_info()`` before any plugin
rules (i.e. any derivatives of :py:class:`~sqlfluff.core.rules.base.BaseRule`)
are *imported*. Because of this, we recommend that rules are defined in a
separate module to the root of the plugin and then only imported within
the ``get_rules()`` method.
Importing in the main body of the module was previously our recommendation
and so may be the case for versions of some plugins. If one of your plugins
does use imports in this way, a warning will be presented, recommending that
you update your plugin.
.. code-block:: python
:emphasize-lines: 7,8
# The root module will need to import `hookimpl`, but
# should not yet import the rule definitions for the plugin.
from sqlfluff.core.plugin import hookimpl
@hookimpl
def get_rules():
# Rules should be imported within the `get_rules` method instead
from my_plugin.rules import MyRule
return [MyRule]
.. _`pluggy library`: https://pluggy.readthedocs.io/en/latest/
Creating a plugin
-----------------
We have an example plugin in
`sqlfluff/plugins/sqlfluff-plugin-example`_ which you can use as a template
for rules, or the `sqlfluff/plugins/sqlfluff-templater-dbt`_ which you can
use as a template for templater plugins.
Few things to note about plugins:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Currently, only Rules and Templaters can be added through plugins. Over time
we expect more elements of SQLFluff will be extensible with plugins. Each
plugin can implement multiple Rules or Templaters.
We recommend that the name of a plugin should start with *"sqlfluff-"* to be
clear on the purpose of your plugin.
A plugin may need to include a default configuration if its rules
are configurable: use plugin default configurations **only for that reason**!
We advise against overwriting core configurations by using a default
plugin configuration, as there is no mechanism in place to enforce precedence
between the core library configs and plugin configs,
and multiple plugins could clash.
A plugin Rule class name should have the structure:
"Rule_PluginName_L000". The 'L' can be any letter
and is meant to categorize rules; you could use the
letter 'S' to denote rules that enforce security checks
for example.
An important thing to note when running custom implemented rules:
Run ``pip install -e .``, inside the plugin folder so custom rules in linting
are included.
A plugin Rule code includes the PluginName,
so a rule "Rule_L000" in core will have code "L000",
while "Rule_PluginName_L000" will have code "PluginName_L000".
Codes are used to display errors, they are also used as configuration keys.
We make it easy for plugin developers to test their rules by
exposing a testing library in *sqlfluff.utils.testing*.
.. _`sqlfluff/plugins/sqlfluff-plugin-example`: https://github.com/sqlfluff/sqlfluff/tree/main/plugins/sqlfluff-plugin-example
.. _`sqlfluff/plugins/sqlfluff-templater-dbt`: https://github.com/sqlfluff/sqlfluff/tree/main/plugins/sqlfluff-templater-dbt
Giving feedback
---------------
Would you like to have other parts of *SQLFluff* be "pluggable"?
Tell us about it in a `GitHub issue`_ 😄.
.. _`GitHub issue`: https://github.com/sqlfluff/sqlfluff/issues/new?assignees=&labels=enhancement&template=enhancement.md

View File

@@ -0,0 +1,99 @@
.. _developingrulesref:
Developing Rules
================
`Rules` in `SQLFluff` are implemented as classes inheriting from ``BaseRule``.
SQLFluff crawls through the parse tree of a SQL file, calling the rule's
``_eval()`` function for each segment in the tree. For many rules, this allows
the rule code to be really streamlined and only contain the logic for the rule
itself, with all the other mechanics abstracted away.
Running Tests
-------------
The majority of the test cases for most bundled rules are *"yaml test cases"*,
i.e. test cases defined in `yaml`_ files. You can find those `yaml fixtures on github`_.
While this provides a very simple way to *write* tests, it can be occasionally tedious
to *run* specific tests.
Within either a `tox` environment or `virtualenv` (as described in the `contributing.md`_
file), you can either run all of the rule yaml tests with:
.. code-block:: sh
pytest test/rules/yaml_test_cases_test.py -vv
...or to just run tests for a specific rule, there are two options for a syntax to select
only those tests:
.. code-block:: sh
pytest -vv test/rules/ -k RF01
The :code:`-k` option simply searches for the content of the argument being in the name
of the test, which will match any single or combo tests for that rule. By convention,
any test cases for a rule should include the code for that rule.
.. _`yaml`: https://yaml.org/
.. _`yaml fixtures on github`: https://github.com/sqlfluff/sqlfluff/tree/main/test/fixtures/rules/std_rule_cases
.. _`contributing.md`: https://github.com/sqlfluff/sqlfluff/blob/main/CONTRIBUTING.md
Traversal Options
-----------------
``recurse_into``
^^^^^^^^^^^^^^^^
Some rules are a poor fit for the simple traversal pattern described above.
Typical reasons include:
* The rule only looks at a small portion of the file (e.g. the beginning or
end).
* The rule needs to traverse the parse tree in a non-standard way.
These rules can override ``BaseRule``'s ``recurse_into`` field, setting it to
``False``. For these rules ``False``, ``_eval()`` is only called *once*, with
the root segment of the tree. This can be much more efficient, especially on
large files. For example, see rules ``LT13`` and ``LT12`` , which only look at
the beginning or end of the file, respectively.
``_works_on_unparsable``
^^^^^^^^^^^^^^^^^^^^^^^^
By default, `SQLFluff` calls ``_eval()`` for all segments, even "unparsable"
segments, i.e. segments that didn't match the parsing rules in the dialect.
This causes issues for some rules. If so, setting ``_works_on_unparsable``
to ``False`` tells SQLFluff not to call ``_eval()`` for unparsable segments and
their descendants.
Performance-related Options
---------------------------
These are other fields on ``BaseRule``. Rules can override them.
``needs_raw_stack``
^^^^^^^^^^^^^^^^^^^
``needs_raw_stack`` defaults to ``False``. Some rules use
``RuleContext.raw_stack`` property to access earlier segments in the traversal.
This can be useful, but it adds significant overhead to the linting process.
For this reason, it is disabled by default.
``lint_phase``
^^^^^^^^^^^^^^
There are two phases of rule running.
1. The ``main`` phase is appropriate for most rules. These rules are assumed to
interact and potentially cause a cascade of fixes requiring multiple passes.
These rules run the `runaway_limit` number of times (default 10).
2. The ``post`` phase is for post-processing rules, not expected to trigger
any downstream rules, e.g. capitalization fixes. They are run in a
post-processing loop at the end. This loop is identical to the ``main`` loop,
but is only run 2 times at the end (once to fix, and once again to confirm no
remaining issues).
The two phases add complexity, but they also improve performance by allowing
SQLFluff to run fewer rules during the ``main`` phase, which often runs several
times.
NOTE: ``post`` rules also run on the *first* pass of the ``main`` phase so that
any issues they find will be presented in the list of issues output by
``sqlfluff fix`` and ``sqlfluff lint``.

View File

@@ -0,0 +1,47 @@
.. _guides:
Guides & How-tos
================
This section is of short guides and articles is meant to be read alongside
the rest of the documentation which is more reference-oriented.
Setting up SQLFluff
-------------------
.. toctree::
:maxdepth: 1
setup/teamrollout
setup/developing_custom_rules
Troubleshooting SQLFluff
------------------------
.. toctree::
:maxdepth: 1
troubleshooting/how_to
.. _development:
Contributing to SQLFluff
------------------------
It is recommended that the following is read in conjunction with exploring
the codebase. `dialect_ansi.py`_ in particular is helpful to understand the
recursive structure of segments and grammars.
You may also need to reference the :ref:`internal_api_docs`.
.. _`dialect_ansi.py`: https://github.com/sqlfluff/sqlfluff/blob/main/src/sqlfluff/dialects/dialect_ansi.py
.. toctree::
:maxdepth: 1
contributing/architecture
contributing/git
contributing/dialect
contributing/rules
contributing/plugins
contributing/docs

View File

@@ -0,0 +1,134 @@
.. _developing_custom_rules:
Developing Custom Rules
=======================
It's quite common to have organisation-, or project-specific norms and
conventions you might want to enforce using SQLFluff. With a little bit
of python knowledge this is very achievable with SQLFluff, and there's
a plugin architecture to support that.
This guide should be read alongside the code for the
`SQLFluff example plugin`_ and the more technical documentation for
:ref:`developingpluginsref`.
What Plugin do I need?
----------------------
When thinking about developing a rule, the following thought process will
help you decide what to develop:
1. When do I want this rule to show a warning, when should it definitely
**not** show one? What information do I need when evaluating whether
a the rule has been followed or not? This information will tell you
about the two important *locations* in the parse tree which will become
important.
* The *trigger* location: i.e. when should the rule be *called* for
evaluation. e.g. :sqlfluff:ref:`CP01` triggers on keywords, because
it only needs the information about that keyword to run, but
:sqlfluff:ref:`LT08` triggers on ``WITH`` statements even though it's
only interested in specific pieces of whitespace, because it needs the
full context of the statement to evaluate. You may with to examine the
parse structure of some example queries you'd want to handle by using
``sqlfluff parse my_file.sql`` to identify the right segment. This is
then specified using the ``crawl_behaviour`` attribute on the rule.
* The *anchor* location: i.e. which position will show up in the CLI
readout back to the user. To continue the example of above, while
:sqlfluff:ref:`LT08` *triggers* on a ``WITH`` statement, it *anchors*
on a more specific segment just after where it expected whitespace.
It specifies this using the ``anchor`` argument to the
:py:class:`~sqlfluff.core.rules.base.LintResult` object.
2. How should the rule evaluate and should I implement an auto-fix? For
the simplest rules, it the logic to evaluate whether there's an issue
can be *very simple*. For example in the `SQLFluff example plugin`_,
we are just checking the name of an element isn't in a configured list.
Typically we recommend that for organisation-specific rules, **KEEP IT**
**SIMPLE**. Some of the rules bundled with SQLFluff contain a lot of
complexity for handling how to automatically fix lots of edge cases,
but for your organisation it's probably not worth the overhead unless
you're a **very big team** or **come across a huge amount of poorly**
**formatted SQL**.
* Consider the information not just to *trigger*, but also whether a
custom error message would be appropriate and how to get the information
to construct that too. The default error message will be the first
line of the rule docstring_. Custom messages can be configured by
setting the ``description`` argument of the
:py:class:`~sqlfluff.core.rules.base.LintResult` object.
* Do use the existing SQLFluff core rules as examples of what is possible
and how to achieve various things - but remember that many of them
implement a level of complexity and edge case handling which may not
be necessary for your organisation.
3. How am I going to roll out my rule to the team? Thinking through this
aspect of rule development is just as important as the technical aspect.
Spending a lot of time on rule development for it to be rejected by
the end users of it is both a waste of time and also counterproductive.
* Consider manually fixing any pre-existing issues in your project which
would trigger the rule before rollout.
* Seek consensus on how strictly the rule will be enforced and what the
step by step pathway is to strict enforcement.
* Consider *beta-testing* your new rule with a smaller group of users
who are more engaged with SQLFluff or code quality in general.
.. _docstring: https://en.wikipedia.org/wiki/Docstring
Plugin Discovery
----------------
One of most common questions asked with respect to custom plugins is
*discovery*, or *"how do I tell SQLFluff where my plugin is"*. SQLFluff
uses pluggy_ as it's plugin architecture (developed by the folks at pytest_).
Pluggy uses the python packaging metadata for plugin discovery. This means
that **your plugin must be installed as a python package for discovery**.
Specifically, it must define an `entry point`_ for SQLFluff.
When SQLFluff runs, it inspects installed python packages for this entry
point and then can run any which define one. For example you'll see in the
`SQLFluff example plugin`_ that the ``pyproject.toml`` file has the
following section:
.. code-block:: toml
[project.entry-points.sqlfluff]
# Change this name in your plugin, e.g. company name or plugin purpose.
sqlfluff_example = "sqlfluff_plugin_example"
You can find equivalent examples for ``setup.cfg`` and ``setup.py`` in the
python docs for `entry point`_. This information is registered
*on install* of your plugin, (i.e. when running `pip install`, or equivalent
if you're using a different package manager) so if you change it later, you
may need to re-install your plugin.
You can test whether your rule has been successfully discovered by running
``sqlfluff rules`` and reviewing whether your new rule has been included in
the readout.
.. note::
If you're struggling with rule discovery, **use the example plugin**.
It can be much easier to take a known working example and then modify
from there:
1. Copy the code from the `SQLFluff example plugin`_ into a local
folder.
2. Run `pip install -e /path/to/where/you/put/it`.
3. Run `sqlfluff rules`, to confirm that the example plugin is present
to demonstrate to yourself that discovery is functional.
4. Then edit the example plugin to do what you want now that discovery
isn't an issue. You may have to re-run `pip install ...` if you
change anything in the rule metadata (like the entry point, filenames
or plugin location).
.. _pluggy: https://pluggy.readthedocs.io/en/latest/
.. _pytest: https://docs.pytest.org/en/stable/
.. _`entry point`: https://setuptools.pypa.io/en/stable/userguide/entry_point.html
.. _`SQLFluff example plugin`: https://github.com/sqlfluff/sqlfluff/tree/main/plugins/sqlfluff-plugin-example

View File

@@ -3,12 +3,12 @@
Rolling out SQLFluff with a new team
====================================
Rolling out SQLFluff (like rolling out any other linter or style
guide) is not just about just the *technical* rollout, but also
how you introduce to the tool to the team and organisation around
Rolling out SQLFluff, like rolling out any other linter or style
guide, is not just about the *technical* rollout, but also
how you introduce the tool to the team and organisation around
you.
*The effect of SQLFluff should be to change your behaviours not*
*The effect of SQLFluff should be to change your behaviours, not*
*just your SQL*.
With that in mind, it's worth reminding ourselves what we're trying
@@ -25,7 +25,7 @@ might be:
found in open source projects is easy to read and *looks familiar*
then you're more likely to use it. This means more reusable code
across the industry.
#. **Productive discussions around style**. By defining your
#. **Productive discussions around style**. By defining your
organisation's style guide in code, it means you can version
control it, discuss changes and ultimately give a concrete output
to discussions over style.
@@ -37,7 +37,7 @@ Consider which of these success measures is most important and most
desirable for your team. *Write that down*.
The following steps are a guide, which you should adapt to your
organisation, and in particular it's level of data maturity.
organisation, and in particular its level of data maturity.
1. Assess the situation
-----------------------
@@ -48,12 +48,12 @@ This step is done by you, or a small group of people who *already*
* Run ``sqlfluff lint`` on your project with the stock configuration
to find out how things work *out of the box*.
* Set up your :ref:`config` so that things run and that you can get
a readout of of the errors which you would want the team to see and
a readout of the errors which you would want the team to see and
*not the ones you don't*. Great tools for this are to use
:ref:`sqlfluffignore`, ``--exclude-rules`` or ``--ignore`` in the
CLI (see :ref:`cliref`).
* Identify which areas of your project are the worst and which the
tidiest are. In particular, any areas which are particularly good
* Identify which areas of your project are the worst and which are the
tidiest. In particular, any areas which are particularly tidy
already will be particularly useful in the next phase.
2. Make a plan
@@ -67,24 +67,24 @@ There are three sensible rollout phases:
In each of these phases you have three levers to play with:
#. Areas of the project.
#. Areas of the project in which to apply rules.
#. Depth of rules enforced (this might also include whether
to ignore parsing errors or not too).
to ignore parsing errors or not).
#. Whether to just lint changes (:ref:`diff-quality`),
or whether to lint all the existing code as well.
or to lint all the existing code as well.
Work out a sensible roadmap of how hard you want to go in
each phase. Be clear who is responsible for changes at each
phase. An example plan might look like this:
#. **Pre CI/CD** we get the cleanest area of a project
to a stage that it fully passes the rules we eventually.
#. **Pre CI/CD** we get the tidiest area of a project
to a stage that it fully passes the rules we eventually want to enforce.
The core project team will do this. Liberal use of
``sqlfluff fix`` can be a lifesaver in this phase.
#. **Soft CI/CD** is applied to the whole project, team
members are encouraged to write tidy SQL, but not *required*.
members are encouraged to write tidy SQL, but not *required* to.
#. **Hard CI/CD** is applied to the tidy areas of the project
and to also to any changes to the whole project. Anyone
and also to any changes to the whole project. Anyone
making changes is *required* to write SQL which passes check.
#. **Hard CI/CD** is applied to the whole project on not just
changes, with only a few particularly problematic files
@@ -103,10 +103,10 @@ this an empowering experience that everyone can get involved with
rather than *another piece of admin they need to do*.
At this stage, you might also want to consider other tools in the
SQLFluff ecosystem such as the `SQLFluff pre-commit hook`_ and
the `SQLFluff VSCode plugin`_ or `SQLFluff online formatter`_.
SQLFluff ecosystem such as the :ref:`SQLFluff pre-commit hook
<using-pre-commit>` and the `SQLFluff VSCode plugin`_ or `SQLFluff
online formatter`_.
.. _`SQLFluff pre-commit hook`: https://github.com/sqlfluff/sqlfluff-github-actions
.. _`SQLFluff VSCode plugin`: https://github.com/sqlfluff/vscode-sqlfluff
.. _`SQLFluff online formatter`: https://online.sqlfluff.com/
@@ -122,8 +122,8 @@ norms and rituals around how you change the rules. In particular:
or whether some are creating unnecessary stress?
It's normal for your usage of tools like SQLFluff to change and
evolve over time, what's important is to know this in advance
and welcome it when it happens, and make sure you're always driving
evolve over time. It's important to expect this change in advance,
and welcome it when it happens. Always make sure you're driving
toward the success measures you decided up front, rather than
just resisting the change.

View File

@@ -0,0 +1,144 @@
How to Troubleshoot SQLFluff
============================
It can at times be tricky to troubleshoot SQLFluff as it exists within
an ecosystem of other tools, and can be deployed in wide range of ways.
This step by step guide can help you narrow down what's likely going wrong
and point you toward the swiftest resolution.
1. Common Errors
----------------
There are a few error messages you may get which have relatively
straightforward resolution paths.
Parsing Errors
^^^^^^^^^^^^^^
SQLFluff needs to be able to parse your SQL to understand it's structure.
That means if it fails to parse the SQL it will give you an error message.
The intent is that if SQLFluff cannot parse the SQL, then it should mean
the SQL is also invalid and help you understand where and why.
For example, this is a simple query which is not valid SQL:
.. code-block:: sql
select 1 2 3
from my_table
When running ``sqlfluff lint`` or ``sqlfluff parse`` we get the following
error message::
==== parsing violations ====
L: 1 | P: 10 | PRS | Line 1, Position 10: Found unparsable section: '2 3'
Furthermore if we look at the full parsing output we can see an unparsable
section in the parse tree:
.. code-block::
:emphasize-lines: 12,13,14,15
[L: 1, P: 1] |file:
[L: 1, P: 1] | statement:
[L: 1, P: 1] | select_statement:
[L: 1, P: 1] | select_clause:
[L: 1, P: 1] | keyword: 'select'
[L: 1, P: 7] | [META] indent:
[L: 1, P: 7] | whitespace: ' '
[L: 1, P: 8] | select_clause_element:
[L: 1, P: 8] | numeric_literal: '1'
[L: 1, P: 9] | [META] dedent:
[L: 1, P: 9] | whitespace: ' '
[L: 1, P: 10] | unparsable: !! Expected: 'Nothing here.'
[L: 1, P: 10] | numeric_literal: '2'
[L: 1, P: 11] | whitespace: ' '
[L: 1, P: 12] | numeric_literal: '3'
[L: 1, P: 13] | newline: '\n'
[L: 2, P: 1] | from_clause:
[L: 2, P: 1] | keyword: 'from'
[L: 2, P: 5] | whitespace: ' '
[L: 2, P: 6] | from_expression:
[L: 2, P: 6] | [META] indent:
[L: 2, P: 6] | from_expression_element:
[L: 2, P: 6] | table_expression:
[L: 2, P: 6] | table_reference:
[L: 2, P: 6] | naked_identifier: 'my_table'
[L: 2, P: 14] | [META] dedent:
[L: 2, P: 14] | newline: '\n'
[L: 3, P: 1] | [META] end_of_file:
SQLFluff maintains it's own version of each SQL dialect, and this may not be
exhaustive for some of the dialects which are newer to SQLFluff or which are
in very active development themselves. This means in some scenarios you may
find a query which runs fine in your environment, but cannot be parsed by
SQLFluff. This is not a *"bug"* per-se, but is an indicator of a gap in the
SQLFluff dialect.
Many of the issues raised on GitHub relate to parsing errors like this, but
it's also a great way to support the project if you feel able to contribute
a dialect improvement yourself. We have a short guide on
:ref:`contributing_dialect_changes` to walk you through the process. In the
short term you can also ignore specific files from your overall project so
that this specific file doesn't become a blocker for the rest.
See :ref:`ignoreconfig`.
Configuration Issues
^^^^^^^^^^^^^^^^^^^^
If you're getting ether unexpected behaviour with your config, or errors
because config values haven't been set correctly, it's often due to config
file discovery (i.e. whether SQLFluff can find your config file, and what
order it's combining config files).
For a more general guide to this topic see :ref:`setting_config`.
To help troubleshoot issues, if you run ``sqlfluff`` with a more verbose
logging setting (e.g. ``sqlfluff lint /my/model.sql -v``, or ``-vv``, or
``-vvvvvv``) you'll get a readout of the root config that SQLFluff is using.
This can help debug which values are being used.
2. Isolating SQLFluff
---------------------
If you're still getting strange errors, then the next most useful thing you
can do, both to help narrow down the cause, but also to assist with fixing
a bug if you have found one, is to isolate SQLFluff from any other tools
you're using in parallel:
1. If you're using SQLFluff with the :ref:`dbt_templater`, then try and
recreate the error with the :ref:`jinja_templater` to remove the influence
of ``dbt`` and any database connection related issues.
2. If you're getting an error in a remote CI suite (for example on GitHub
actions, or a server like Jenkins), try and recreate the issue locally
on your machine using the same tools.
3. If you're :ref:`using-pre-commit`, :ref:`diff-quality` or the
`VSCode extension`_ try to recreate the issue by running the SQLFluff
:ref:`cliref` directly. Often this can make debugging significantly
easier because some of these tools hide some of the error messages
which SQLFluff gives the user to help debugging errors.
.. _`VSCode extension`: https://github.com/sqlfluff/vscode-sqlfluff
3. Minimise the Query
---------------------
Often SQL scripts can get very long, and if you're getting an error on a very
long script, then it can be extremely difficult to work out what the issue is.
To assist with this we recommend iteratively cutting down the file (or
alternatively, iteratively building a file back up) until you have the smallest
file which still exhibits the issue. Often after this step, the issue can
become obvious.
1. If your file has multiple statements in it (i.e. statements separated
by ``;``), then remove ones until SQLFluff no longer shows the issue. When
you get to that point, add the offending one back in and remove all the
others.
2. Simplify individual statements. For example in a ``SELECT`` statement, if
you suspect the issue is coming from a particular column, then remove the
others, or remove CTEs, until you've got the simplest query which still
shows the issue.

View File

@@ -1,240 +0,0 @@
.. _indentref:
Let's talk about indentation
============================
If there is one part of building a linter that is going to be controversial
it's going to be **indentation** (closely followed by **cApiTaLiSaTiOn** 😁).
*SQLFluff* aims to be *opinionated* here, but also *configurable* (see
:ref:`indentconfig`). The tool will have a default viewpoint and will aim
to have views on all of the important aspects of SQL layout, but if you
(or your organisation) don't like those views then we aim to allow enough
configuration that you can lint in line with your views, and still use
*SQLFluff*. For more information on how to configure rules to your own
viewpoint see :ref:`config`.
So, without further ado, here are the principles we think apply to indentation:
1. **For Keywords within a statement, the first root keyword of each line should be
aligned.** For :code:`SELECT` statements, this means that :code:`SELECT`,
:code:`FROM`, :code:`WHERE`, :code:`GROUP`, :code:`ORDER`, :code:`HAVING`
and :code:`LIMIT`, should all have the same indent. Occasionally, it's
actually more legible to have one-line or more compressed statements,
and so additionally, if two (or more) of these keywords are on *the same*
line, then the second (and any further) keywords won't raise a violation,
provided that the *first* was correctly aligned.
* This same logic applies to keywords within subsections, but the
likelihood of them being on the same line to start is higher. one
example of where this might occur regularly is within aggregate
functions.
.. code-block:: sql
SELECT
col_a,
col_b,
COUNT(*) as num,
SUM(num) OVER (
PARTITION BY col_a
ORDER BY col_b
) as an_aggregate_function
FROM tbl_a
GROUP BY 1, 2
Note that :code:`PARTITION` and :code:`ORDER` are both aligned on
the same line. This also follows the rules around brackets described
below.
2. **Line Length**. Long lines are hard to read and many SQL guidelines
include a line length restriction. This is (of course) configurable, but
the default is 80 characters (in line with the `dbt Labs SQL style guide`_.)
3. **Bracket behaviour**. For brackets there are three accepted ways:
a. *Inline brackets*. Bracket expressions that start and end on the same line are
fine (providing we don't fall foul of the line length rules above).
.. code-block:: sql
SELECT GREATEST(1, 6) AS col1 FROM my_table
b. *Brackets with immediate linebreak*. If brackets are followed by an immediate
line break (or at least with no other non-code elements after them on that
line), then the following line should be indented +1 relative to the
indent of the previous line. All elements of the bracketed block should
be at this level of indent or deeper. The *closing* bracket of this block
should have the same indent as the first element of the line containing
the opening bracket.
.. code-block:: sql
SELECT GREATEST(
1, 3, 7,
6, 8, 9
) AS col1
FROM my_table
c. *Brackets with delayed linebreak*. If brackets are followed by content,
and then a linebreak *before* the closing bracket, then we assume a
*hanging* indent, where the following items of content should have the
same indent as the first item of content. In this case, the *closing*
bracket should come after the final element *on the same line*.
.. code-block:: sql
SELECT GREATEST(1, 6, 8,
6, 7) AS col1
FROM my_table
4. **Comments** are dealt with differently, depending on whether they're
*block* comments (:code:`/* like this */`), which might optionally
include newlines, or *inline* comments (:code:`-- like this`) which
are necessarily only on one line.
a. *Block comments* cannot share a line with any code elements (so
in effect they must start on their own new line), they cannot be
followed by any code elements on the same line (and so in effect
must be followed by a newline, if we are to avoid trailing
whitespace). None of the lines within the block comment may have
an indent less than the first line of the block comment (although
additional indentation within a comment is allowed), and that first
line should be aligned with the first code element *following*
the block comment.
.. code-block:: sql
SELECT
/* This is a block comment starting on a new line
which contains a newline (continuing with at least
the same indent.
- potentially containing greater indents
- having no other code following it in the same line
- and aligned with the line of code following it */
this_column as what_we_align_the_column_to
FROM my_table
b. *Inline comments* can be on the same line as other code, but are
subject to the same line-length restrictions. If they don't fit
on the same line (or if it just looks nicer) they can also be
the only element on a line. In this latter case they should be
aligned with the first code element *following* the comment.
.. code-block:: sql
SELECT
-- This is fine
this_column as what_we_align_to,
another_column as something_short, -- Is ok
case
-- This is aligned correctly with below
when indented then take_care
else try_harder
end as the_general_guidance
-- Even here we align with the line below
FROM my_table
.. note::
When fixing issues with comment indentation, SQLFluff
will attempt to keep comments in their original position
but if line length concerns make this difficult, it will
either abort the fix, or move *same line* comments up and
*before* the line they are currently on. This is in line
with the assumption that comments on their own line refer
to the elements of code which they come *before*, not *after*.
.. _indentconfig:
Configuring Indentation
^^^^^^^^^^^^^^^^^^^^^^^
How indentation is linted is controlled in the rules, but what indentation
is expected to be present is controlled by the parser, and therefore
configured separately. One of the key areas for this is the indentation
of the :code:`JOIN` expression.
Semantically, a :code:`JOIN` expression is part of the :code:`FROM` expression
and therefore would be expected to be indented. However according to many
of the most common SQL style guides (including the `dbt Labs SQL style guide`_
and the `Mozilla SQL style guide`_) the :code:`JOIN` keyword is expected to at
the same indent as the :code:`FROM` keyword. By default, *SQLFluff* sides with
the current consensus, which is to *not* indent the :code:`JOIN` keyword,
however this is one element which is configurable.
By setting values in the :code:`sqlfluff:indentation` section of your config
file you can control how this is parsed, for example you may work with an
indentation similar to that of `Baron Schwartz`_.
By setting your config file to:
.. code-block:: cfg
[sqlfluff:indentation]
indented_joins = True
Then the expected indentation will be:
.. code-block:: sql
SELECT
a, b, c
FROM my_table
JOIN another_table
USING(a)
However if no value for :code:`indented_joins` is set, or if it is set to
:code:`False` then then following indentation will be expected:
.. code-block:: sql
SELECT
a, b, c
FROM my_table
JOIN another_table
USING(a)
There is a similar :code:`indented_using_on` config (defaulted to :code:`True`)
which can be set to :code:`False` to prevent the :code:`using` clause from
being indented, in which case above SQL would become:
.. code-block:: sql
SELECT
a, b, c
FROM my_table
JOIN another_table
USING(a)
There is also a similar :code:`indented_ctes` config (defaulted to
:code:`False`) which can be set to :code:`True` to enforce CTEs to be
indented within the :code:`WITH` clause:
.. code-block:: sql
WITH
some_cte AS (
SELECT 1 FROM table1
),
some_other_cte AS (
SELECT 1 FROM table1
)
SELECT 1 FROM some_cte
Note that using :code:`indented_ctes` may clash with `Rule L018`_ (`"WITH
clause closing bracket should be aligned with WITH keyword."``), so if using
this option you will likely want to disable that rule.
By default, *SQLFluff* aims to follow the indentation most common approach
to indentation. However, if you have other versions of indentation which are
supported by published style guides, then please submit an issue on GitHub
to have that variation supported by *SQLFluff*.
.. _`dbt Labs SQL style guide`: https://github.com/dbt-labs/corp/blob/master/dbt_style_guide.md
.. _`Mozilla SQL style guide`: https://docs.telemetry.mozilla.org/concepts/sql_style.html#joins
.. _`Baron Schwartz`: https://www.xaprb.com/blog/2006/04/26/sql-coding-standards/
.. _`Rule L018`: ./rules.html#sqlfluff.core.rules.Rule_L018

View File

@@ -6,36 +6,20 @@ you're working with? Fluff is an extensible and modular linter designed
to help you write good SQL and catch errors and bad SQL before it hits
your database.
.. note::
**SQLFluff** is still in an open Beta phase - expect potentially
non-backward compatible api changes to happen with releases
(particularly when major or minor version numbers increase).
Notable changes:
* **0.1.x** involved a major re-write of the parser, completely changing
the behaviour of the tool with respect to complex parsing.
* **0.2.x** added templating support and a big restructure of rules
and changed how users might interact with SQLFluff on templated code.
* **0.3.x** drops support for python 2.7 and 3.4, and also reworks the
handling of indentation linting in a potentially not backward
compatible way.
* **0.4.x** dropped python 3.5, added the dbt templater, source mapping and
also introduced the python API
* **0.5.x** introduced some breaking changes to the API.
* **0.6.x** introduced parallel processing, which necessitated a big re-write
of several innards
* **0.7.x** extracted the dbt templater to a separate plugin and removed the
``exasol_fs`` dialect (now merged in with the main ``exasol``)
* **0.8.x** an improvement to the performance of the parser, a rebuild of the
Jinja Templater, and a progress bar for the CLI
* **0.9.x** refinement of the Simple API, dbt 1.0.0 compatibility,
and the official SQLFluff Docker image.
* **0.10.x** removed support for older dbt versions < 0.20 and stopped ``fix``
attempting to fix unparsable SQL.
Notable releases:
* **1.0.x**: First *stable* release, no major changes to take advantage of a
point of relative stability.
* **2.0.x**: Recode of rules, whitespace fixing consolidation,
:code:`sqlfluff format` and removal of support for dbt versions pre `1.1`.
Note, that this release brings with it some breaking changes to rule coding
and configuration, see :ref:`upgrading_2_0`.
* **3.0.x**: :code:`sqlfluff fix` now defaults to *not* asking for confirmation
and the `--force` option was removed. Richer information returned by the
:code:`sqlfluff lint` command (although in a different structure to previous
versions). See :ref:`upgrading_3_0`.
For more detail on other releases, see our :ref:`releasenotes`.
Want to see where and how people are using SQLFluff in their projects?
Head over to :ref:`inthewildref` for inspiration.
@@ -51,11 +35,23 @@ have python or pip already installed see :ref:`gettingstartedref`.
$ pip install sqlfluff
$ echo " SELECT a + b FROM tbl; " > test.sql
$ sqlfluff lint test.sql
$ sqlfluff lint test.sql --dialect ansi
== [test.sql] FAIL
L: 1 | P: 1 | L003 | Single indentation uses a number of spaces not a multiple of 4
L: 1 | P: 14 | L006 | Operators should be surrounded by a single space unless at the start/end of a line
L: 1 | P: 27 | L001 | Unnecessary trailing whitespace
L: 1 | P: 1 | LT01 | Expected only single space before 'SELECT' keyword.
| Found ' '. [layout.spacing]
L: 1 | P: 1 | LT02 | First line should not be indented.
| [layout.indent]
L: 1 | P: 1 | LT13 | Files must not begin with newlines or whitespace.
| [layout.start_of_file]
L: 1 | P: 11 | LT01 | Expected only single space before binary operator '+'.
| Found ' '. [layout.spacing]
L: 1 | P: 14 | LT01 | Expected only single space before naked identifier.
| Found ' '. [layout.spacing]
L: 1 | P: 27 | LT01 | Unnecessary trailing whitespace at end of file.
| [layout.spacing]
L: 1 | P: 27 | LT12 | Files must end with a single trailing newline.
| [layout.end_of_file]
All Finished 📜 🎉!
Contents
^^^^^^^^
@@ -65,19 +61,11 @@ Contents
:caption: Documentation for SQLFluff:
gettingstarted
realworld
vision
teamrollout
indentation
rules
dialects
production
configuration
architecture
cli
api
developingrules
developingplugins
why_sqlfluff
guides/index
configuration/index
production/index
reference/index
inthewild
jointhecommunity

View File

@@ -45,7 +45,7 @@ Just add a section below by raising a PR on GitHub by
to this project. In particular our annual `Web Almanac <https://almanac.httparchive.org>`_
attracts hundreds of volunteers to help analyse our BigQuery dataset and
being able automatically lint Pull Requests through GitHub Actions is a
fantastic way to help us maintain our growing repositary of
fantastic way to help us maintain our growing repository of
`over a thousand queries <https://github.com/HTTPArchive/almanac.httparchive.org/tree/main/sql>`_.
- `Brooklyn Data Co <https://www.brooklyndata.co>`_ has a `dbt_artifacts <https://github.com/brooklyn-data/dbt_artifacts>`_
dbt package from which runs SQLFluff in CI to lint pull requests
@@ -54,3 +54,26 @@ Just add a section below by raising a PR on GitHub by
contributed by Greg Clunies, with annotations on pull requests to make it
easy for contributors to see where their SQL has failed any rules. See an
`example pull request with SQLFluff annotations <https://github.com/brooklyn-data/dbt_artifacts/pull/74/files>`_.
- `Markerr <https://www.markerr.com>`_ has tightly integrated SQLFluff into our
CI/CD process for data model changes and process improvements. Since adopting
SQLFluff across the organization, the clarity of our SQL code has risen
dramatically, freeing up review time to focus on deeper data and
process-specific questions.
- `Symend <https://www.symend.com>`_ has a microservices platform supporting
our SaaS product. We use SQLFLuff in the CI/CD process of several of our
data-oriented microservices. Among other things, it validates our database
migration scripts, deployed using
`schemachange <https://github.com/Snowflake-Labs/schemachange>`_ and we have
near-term plans to implement it for our `dbt`_ projects.
- At `CarePay <https://www.carepay.com>`_ we use SQLFLuff to lint and fix all
our dbt models as well as several other SQL heavy projects. Locally we use
SQLFluff with pre-commit and have also integrated it into our CI/CD
pipelines.
- Core Analytics Team from `Typeform <https://www.typeform.com/>`_ and
`videoask <https://www.videoask.com/>`_ uses SQLFluff in the production
`dbt <http://www.getdbt.com/>`_ project for building our datawarehouse
layer for both products:
- We use it locally in our day to day work, helping us to write cleaner code.
- We added SQLFluff to our CI processes, so during a PR we can check that any
new or modified sql file has a consistent and easy-to-read format.

View File

@@ -1,12 +1,12 @@
.. _jointhecommunity:
.. _sqlfluff_slack:
SQLFluff Slack
====================
==============
We have a fast-growing `community on Slack <https://join.slack.com/t/sqlfluff/shared_invite/zt-o1f4x0e8-pZzarAIlQmKj_6ZwD16w0g>`_, come and join us!
We have a fast-growing `community on Slack <https://join.slack.com/t/sqlfluff/shared_invite/zt-2qtu36kdt-OS4iONPbQ3aCz2DIbYJdWg>`_, come and join us!
SQLFluff on Twitter
====================
Follow us On Twitter `@SQLFluff <https://twitter.com/SQLFluff>`_ for annoncements and other related posts.
Follow us On Twitter `@SQLFluff <https://twitter.com/SQLFluff>`_ for announcements and other related posts.

View File

@@ -1,173 +0,0 @@
Production Usage
================
SQLFluff is designed to be used both as a utility for developers but also to
be part of `CI/CD`_ pipelines.
Using SQLFluff on a whole sql codebase
--------------------------------------
The `exit code`_ provided by SQLFluff when run as a command line utility is
designed to assist usefulness in deployment pipelines. If no violations
are found then the `exit code`_ will be 0. If violations are found then
a non-zero code will be returned which can be interrogated to find out
more.
- At the moment all error states related to linting return *65*.
- An error as a result of a SQLFluff internal error will return *1*.
.. _`CI/CD`: https://en.wikipedia.org/wiki/Continuous_integration
.. _`exit code`: https://shapeshed.com/unix-exit-codes/
.. _diff-quality:
Using SQLFluff on changes using `diff-quality`
----------------------------------------------
For projects with large amounts of (potentially imperfect) SQL code, the full
SQLFluff output could be very large, which can be distracting -- perhaps the CI
build for a one-line SQL change shouldn't encourage the developer to fix lots
of unrelated quality issues.
To support this use case, SQLFluff integrates with a quality checking tool
called `diff-quality`. By running SQLFluff using `diff-quality` (rather than
running it directly), you can limit the the output to the new or modified SQL
in the branch (aka pull request or PR) containing the proposed changes.
Currently, ``diff-quality`` requires that you are using ``git`` for version
control.
NOTE: Installing SQLFluff automatically installs the `diff_cover` package that
provides the `diff-quality` tool.
Adding `diff-quality` to your builds
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
In your CI build script:
1. Set the current working directory to the ``git`` repository containing the
SQL code to be checked.
2. Run `diff-quality`, specifying SQLFluff as the underlying tool:
.. code-block:: text
$ diff-quality --violations sqlfluff
The output will look something like:
.. code-block:: text
-------------
Diff Quality
Quality Report: sqlfluff
Diff: origin/master...HEAD, staged and unstaged changes
-------------
sql/audience_size_queries/constraints/_postcondition_check_gdpr_compliance.sql (0.0%):
sql/audience_size_queries/constraints/_postcondition_check_gdpr_compliance.sql:5: Unquoted Identifiers must be consistently upper case.
-------------
Total: 1 line
Violations: 1 line
% Quality: 0%
-------------
These messages are basically the same as those provided directly by SQLFluff,
although the format is a little different. Note that `diff-quality` only lists
the line _numbers_, not the character position. If you need the character
position, you will need to run SQLFluff directly.
For more information on `diff-quality`, see the
`documentation <https://diff-cover.readthedocs.io/en/latest/>`_. It covers topics
such as:
* Generating HTML reports
* Controlling which branch to compare against (i.e. to determine new/changed
lines). The default is `origin/master`.
* Configuring `diff-quality` to return an error code if the quality is too low
* Troubleshooting
Using `pre-commit`_
^^^^^^^^^^^^^^^^^^^
`pre-commit`_ is a framework to manage git "hooks"
triggered right before a commit is made.
A `git hook`_ is a git feature to "fire off custom scripts"
when specific actions occur.
Using `pre-commit`_ with SQLFluff is a good way
to provide automated linting to SQL developers.
With `pre-commit`_, you also get the benefit of
only linting/fixing the files that changed.
SQLFluff comes with two `pre-commit`_ hooks:
* sqlfluff-lint: returns linting errors.
* sqlfluff-fix: attempts to fix rule violations.
.. warning::
For safety reasons, ``sqlfluff-fix`` by default will not make any fixes in
files that had templating or parse errors, even if those errors were ignored
using ``noqa`` or `--ignore``.
Although it is not advised, you *can* tell SQLFluff to try and fix
these files by overriding the ``fix_even_unparsable`` setting
in ``.sqlfluff`` config file or using the ``sqlfluff fix --FIX-EVEN-UNPARSABLE``
command line option.
*Overriding this behavior may break your SQL. If you use this override,
always be sure to review any fixes applied to files with templating or parse
errors to verify they are okay.*
You should create a file named `.pre-commit-config.yaml`
at the root of your git project, which should look
like this:
.. code-block:: yaml
repos:
- repo: https://github.com/sqlfluff/sqlfluff
rev: |release|
hooks:
- id: sqlfluff-lint
# For dbt projects, this installs the dbt "extras".
# You will need to select the relevant dbt adapter for your dialect
# (https://docs.getdbt.com/docs/available-adapters):
# additional_dependencies: ['<dbt-adapter>', 'sqlfluff-templater-dbt']
- id: sqlfluff-fix
# Arbitrary arguments to show an example
# args: [--rules, "L003,L014"]
# additional_dependencies: ['<dbt-adapter>', 'sqlfluff-templater-dbt']
When trying to use the `dbt templater`_, uncomment the
``additional_dependencies`` to install the extras.
This is equivalent to running ``pip install <dbt-adapter> sqlfluff-templater-dbt``.
You can specify the verion of ``dbt-adapter`` used in `pre-commit`_,
for example:
.. code-block:: yaml
additional_dependencies : ['dbt-bigquery==1.0.0', 'sqlfluff-templater-dbt']
See the list of available `dbt-adapters`_.
Note that you can pass the same arguments available
through the CLI using ``args:``.
Using `GitHub Actions`_ to Annotate PRs
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
When `sqlfluff lint` is run with the `--format github-annotation` option, it
produces output compatible with this `action <https://github.com/yuzutech/annotations-action>`_.
You can use this to annotate the SQL in `GitHub pull requests`.
For more information and examples on using SQLFluff in GitHub Actions, see the
`sqlfluff-github-actions repository <https://github.com/sqlfluff/sqlfluff-github-actions>`_.
.. _`pre-commit`: https://pre-commit.com/
.. _`git hook`: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
.. _`dbt templater`: `dbt-project-configuration`
.. _`GitHub Actions`: https://github.com/features/actions
.. _`GitHub pull requests`: https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests
.. _`dbt-adapters`: https://docs.getdbt.com/docs/available-adapters

View File

@@ -0,0 +1,25 @@
Using SQLFluff directly as a CLI application
--------------------------------------------
The :ref:`SQLFluff CLI application <cliref>` is a python application which
means if depends on your host python environment
(see :ref:`installingsqlfluff`).
The `exit code`_ provided by SQLFluff when run as a command line utility is
designed to assist usefulness in deployment pipelines. If no violations
are found then the `exit code`_ will be 0. If violations are found then
a non-zero code will be returned which can be interrogated to find out
more.
- An error code of ``0`` means *operation success*, *no issues found*.
- An error code of ``1`` means *operation success*, *issues found*. For
example this might mean that a linting issue was found, or that one file
could not be parsed.
- An error code of ``2`` means an error occurred and the operation could
not be completed. For example a configuration issue or an internal error
within SQLFluff.
For details of what commands and options are available in the CLI see the
:ref:`cliref`.
.. _`exit code`: https://shapeshed.com/unix-exit-codes/

View File

@@ -0,0 +1,98 @@
.. _diff-quality:
Using SQLFluff on changes using ``diff-quality``
================================================
For projects with large amounts of (potentially imperfect) SQL code, the full
SQLFluff output could be very large, which can be distracting -- perhaps the CI
build for a one-line SQL change shouldn't encourage the developer to fix lots
of unrelated quality issues.
To support this use case, SQLFluff integrates with a quality checking tool
called ``diff-quality``. By running SQLFluff using ``diff-quality`` (rather
than running it directly), you can limit the the output to the new or modified
SQL in the branch (aka pull request or PR) containing the proposed changes.
Currently, ``diff-quality`` requires that you are using ``git`` for version
control.
NOTE: Installing SQLFluff automatically installs the ``diff_cover`` package
that provides the ``diff-quality`` tool.
Adding ``diff-quality`` to your builds
--------------------------------------
In your CI build script:
1. Set the current working directory to the ``git`` repository containing the
SQL code to be checked.
2. Run ``diff-quality``, specifying SQLFluff as the underlying tool:
.. code-block:: text
$ diff-quality --violations sqlfluff
The output will look something like:
.. code-block:: text
-------------
Diff Quality
Quality Report: sqlfluff
Diff: origin/master...HEAD, staged and unstaged changes
-------------
sql/audience_size_queries/constraints/_postcondition_check_gdpr_compliance.sql (0.0%):
sql/audience_size_queries/constraints/_postcondition_check_gdpr_compliance.sql:5: Unquoted Identifiers must be consistently upper case.
-------------
Total: 1 line
Violations: 1 line
% Quality: 0%
-------------
These messages are basically the same as those provided directly by SQLFluff,
although the format is a little different. Note that ``diff-quality`` only lists
the line _numbers_, not the character position. If you need the character
position, you will need to run SQLFluff directly.
.. note::
When using ``diff-quality`` with ``.sqlfluff`` :ref:`config-files`, and
especially together with the :ref:`dbt_templater`, it can be really easy
to run into issues with file discovery. There are a few steps you can
take to make it much less likely that this will happen:
1. ``diff-quality`` needs to be run from the root of your ``git``
repository (so that it can find the ``git`` metadata).
2. SQLFluff works best if the bulk of the configuration is done from a
single ``.sqlfluff`` file, which should be in the root of your
``git`` repository.
3. If using :ref:`dbt_templater`, then either place your ``dbt_project.yml``
file in the same root folder, or if you put it in a subfolder, then
only invoke ``diff-quality`` and ``sqlfluff`` from the root and define
the subfolder that the ``dbt`` project lives in using the ``.sqlfluff``
config file.
By aligning the paths of all three, you should be able to achieve a
robust setup. If each is rooted in different paths if can be very
difficult to achieve the same result, and the resulting behaviour
can be difficult to debug.
To debug any issues relating to this setup, we recommend occasionally
running ``sqlfluff`` directly using the main cli (i.e. calling
:code:`sqlfluff lint my/project/path`) and check whether that route
gives you the results you expect. ``diff-quality`` should behave as
though it's calling the SQLFluff CLI *from the same path that you*
*invoke* ``diff-quality``.
For more information on ``diff-quality`` and the ``diff_cover`` package, see the
`documentation <https://github.com/Bachmann1234/diff_cover>`_ on their github
repository. It covers topics such as:
* Generating HTML reports
* Controlling which branch to compare against (i.e. to determine new/changed
lines). The default is ``origin/main``.
* Configuring ``diff-quality`` to return an error code if the quality is
too low.
* Troubleshooting

View File

@@ -0,0 +1,30 @@
Using `GitHub Actions`_ to Annotate PRs
=======================================
There are two way to utilize SQLFluff to annotate Github PRs.
1. When :code:`sqlfluff lint` is run with the :code:`--format github-annotation-native`
option, it produces output formatted as `Github workflow commands`_ which
are converted into pull request annotations by Github.
2. When :code:`sqlfluff lint` is run with the :code:`--format github-annotation`
option, it produces output compatible with this `action from yuzutech`_.
Which uses Github API to annotate the SQL in `GitHub pull requests`.
.. warning::
At present (December 2023), limitations put in place by Github mean that only the
first 10 annotations will be displayed if the first option (using
:code:`github-annotation-native`) is used. This is a not something that SQLFluff
can control itself and so we currently recommend using the the second option
above and the `action from yuzutech`_.
There is an `open feature request <https://github.com/orgs/community/discussions/68471>`_
for GitHub Actions which you can track to follow this issue.
For more information and examples on using SQLFluff in GitHub Actions, see the
`sqlfluff-github-actions repository <https://github.com/sqlfluff/sqlfluff-github-actions>`_.
.. _`GitHub Actions`: https://github.com/features/actions
.. _`GitHub pull requests`: https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests
.. _`Github workflow commands`: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-notice-message
.. _`action from yuzutech`: https://github.com/yuzutech/annotations-action

View File

@@ -0,0 +1,18 @@
.. _production-use:
Production Usage & Security
===========================
SQLFluff is designed to be used both as a utility for developers but also to
be part of `CI/CD`_ pipelines.
.. _`CI/CD`: https://en.wikipedia.org/wiki/Continuous_integration
.. toctree::
:maxdepth: 2
security
cli_use
diff_quality
pre_commit
github_actions

View File

@@ -0,0 +1,99 @@
.. _using-pre-commit:
Using :code:`pre-commit`
========================
`pre-commit`_ is a framework to manage git "hooks"
triggered right before a commit is made.
A `git hook`_ is a git feature to "fire off custom scripts"
when specific actions occur.
Using `pre-commit`_ with SQLFluff is a good way
to provide automated linting to SQL developers.
With `pre-commit`_, you also get the benefit of
only linting/fixing the files that changed.
SQLFluff comes with two `pre-commit`_ hooks:
* ``sqlfluff-lint``: returns linting errors.
* ``sqlfluff-fix``: attempts to fix rule violations.
.. warning::
For safety reasons, ``sqlfluff-fix`` by default will not make any fixes in
files that had templating or parse errors, even if those errors were ignored
using ``noqa`` or `--ignore``.
Although it is not advised, you *can* tell SQLFluff to try and fix
these files by overriding the ``fix_even_unparsable`` setting
in ``.sqlfluff`` config file or using the ``sqlfluff fix --FIX-EVEN-UNPARSABLE``
command line option.
*Overriding this behavior may break your SQL. If you use this override,
always be sure to review any fixes applied to files with templating or parse
errors to verify they are okay.*
You should create a file named ``.pre-commit-config.yaml``
at the root of your git project, which should look
like this:
.. code-block:: yaml
repos:
- repo: https://github.com/sqlfluff/sqlfluff
rev: |release|
hooks:
- id: sqlfluff-lint
# For dbt projects, this installs the dbt "extras".
# You will need to select the relevant dbt adapter for your dialect
# (https://docs.getdbt.com/docs/available-adapters):
# additional_dependencies: ['<dbt-adapter>', 'sqlfluff-templater-dbt']
- id: sqlfluff-fix
# Arbitrary arguments to show an example
# args: [--rules, "LT02,CP02"]
# additional_dependencies: ['<dbt-adapter>', 'sqlfluff-templater-dbt']
When trying to use the `dbt templater`_, uncomment the
``additional_dependencies`` to install the extras.
This is equivalent to running ``pip install <dbt-adapter> sqlfluff-templater-dbt``.
You can specify the version of ``dbt-adapter`` used in `pre-commit`_,
for example:
.. code-block:: yaml
additional_dependencies : ['dbt-bigquery==1.0.0', 'sqlfluff-templater-dbt']
See the list of available `dbt-adapters`_.
Note that you can pass the same arguments available
through the CLI using ``args:``.
.. _`pre-commit`: https://pre-commit.com/
.. _`git hook`: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
.. _`dbt templater`: `dbt-project-configuration`
.. _`dbt-adapters`: https://docs.getdbt.com/docs/available-adapters
Ignoring files while using :code:`pre-commit`
---------------------------------------------
Under the hood, `pre-commit`_ works by passing specific files to *SQLFluff*.
For example, if the only two files that are modified in your commit are
:code:`file_a.sql` and :code:`file_b.sql`, then the command which is called
in the background is :code:`sqlfluff lint file_a.sql file_b.sql`. While this
is efficient, it does produce some unwanted noise when also
using :ref:`sqlfluffignore`. This is because *SQLFluff* is designed to allow
users to override an *ignore* configuration by passing the name of the file
directly. This makes a lot of sense in a CLI context, but less so in the context
of being invoked by `pre-commit`_.
To avoid noisy logs when using both `pre-commit`_ and :ref:`sqlfluffignore`,
we recommend also setting the :code:`exclude` argument in your
:code:`.pre-commit-config.yaml` file (either the `top level config`_ or the
`hook specific config`_). This will prevent files matching the given pattern
being passed to *SQLFluff* and so silence any warnings about the
:ref:`sqlfluffignore` being overridden.
.. _`top level config`: https://pre-commit.com/#top_level-exclude
.. _`hook specific config`: https://pre-commit.com/#config-exclude

View File

@@ -0,0 +1,56 @@
.. _security:
Security Considerations
=======================
A full list of `Security Advisories is available on GitHub <https://github.com/sqlfluff/sqlfluff/security/advisories>`_.
Given the context of how SQLFluff is designed to be used, there are three
different tiers of access which users may have access to manipulate how the
tool functions in a secure environment.
#. *Users may have edit access to the SQL code which is being linted*. While
SQLFluff does not execute the SQL itself, in the process of the
:ref:`templating step <templater>` (in particular via jinja or dbt),
certain macros may have the ability to execute arbitrary SQL code (e.g.
the `dbt run_query macro`_). For the Jinja templater, SQLFluff uses the
`Jinja2 SandboxedEnvironment`_ to limit the execution on unsafe code. When
looking to further secure this situation, see below for ways to limit the
ability of users to import other libraries.
#. *Users may have edit access to the SQLFluff :ref:`config-files`*. In some
(perhaps, many) environments, the users who can edit SQL files may also
be able to access and edit the :ref:`config-files`. It's important to note
that because of :ref:`in_file_config`, that users who can edit SQL files
which are designed to be linted, will also have access to the vast majority
of any configuration options available in :ref:`config-files`. This means
that there is minimal additional protection from restricting access to
:ref:`config-files` for users who already have access to edit the linting
target files (as described above).
#. *Users may have access to change how SQLFluff is invoked*. SQLFluff can
be invoked either as a command line too or via the python API. Typically
the method is fixed for a given application. When thinking about how to
restrict the ability of users to call insecure code, SQLFluff aims to
provide options at the point of invocation. In particular, as described
above, the primary risk vector for SQLFluff is the macro environment
as described in :ref:`templateconfig`. To restrict users being able to
bring arbitrary python methods into sqlfluff via the ``library_path``
configuration value (see :ref:`jinja_library_templating`), we recommend
that for secure environments you override this config value either by
providing an ``override`` option to the :class:`FluffConfig` object if
using the Python API or via the ``--library-path`` CLI option:
To disable this option entirely via the CLI:
.. code-block:: bash
$ sqlfluff lint my_path --library-path none
To disable this option entirely via the python API:
.. literalinclude:: ../../../examples/04_config_overrides.py
:language: python
.. _`Jinja2 SandboxedEnvironment`: https://jinja.palletsprojects.com/en/3.0.x/sandbox/#jinja2.sandbox.SandboxedEnvironment
.. _`dbt run_query macro`: https://docs.getdbt.com/reference/dbt-jinja-functions/run_query

View File

@@ -1,101 +0,0 @@
.. _realworldref:
SQL in the Wild
===============
SQL has been around for a long time, as a language for communicating
with databases, like a communication protocol. More recently with the
rise of *data* as a business function, or a domain in its own right
SQL has also become an invaluable tool for defining the *structure* of
data and analysis - not just as a one off but as a form of
`infrastructure as code`_.
As *analytics* transitions from a profession of people doing one-offs,
and moves to building stable and reusable pieces of analytics, more and
more principles from software engineering are moving in the analytics
space. One of the best articulations of this is written in the
`viewpoint section of the docs for the open-source tool dbt`_. Two of
the principles mentioned in that article are `quality assurance`_ and
`modularity`_.
Quality assurance
-----------------
The primary aim of `SQLFluff` as a project is in service of that first
aim of `quality assurance`_. With larger and larger teams maintaining
large bodies of SQL code, it becomes more and more important that the
code is not just *valid* but also easily *comprehensible* by other users
of the same codebase. One way to ensure readability is to enforce a
`consistent style`_, and the tools used to do this are called `linters`_.
Some famous `linters`_ which are well known in the software community are
`flake8`_ and `jslint`_ (the former is used to lint the `SQLFluff` project
itself).
**SQLFluff** aims to fill this space for SQL.
Modularity
----------
SQL itself doesn't lend itself well to `modularity`_, so to introduce
some flexibility and reusability it is often `templated`_. Typically
this is done in the wild in one of the following ways:
1. Using the limited inbuilt templating abilities of a programming
language directly. For example in python this would be using the
`format string syntax`_:
.. code-block:: python
"SELECT {foo} FROM {tbl}".format(foo="bar", tbl="mytable")
Which would evaluate to:
.. code-block:: sql
SELECT bar FROM mytable
2. Using a dedicated templating library such as `jinja2`_. This allows
a lot more flexibility and more powerful expressions and macros. See
the :ref:`templateconfig` section for more detail on how this works.
- Often there are tools like `dbt`_ or `apache airflow`_ which allow
`templated`_ sql to be used directly, and they will implement a
library like `jinja2`_ under the hood themselves.
All of these templating tools are great for `modularity`_ but they also
mean that the SQL files themselves are no longer valid SQL code, because
they now contain these configured *placeholder* values, intended to
improve modularity.
SQLFluff supports both of the templating methods outlined above,
as well as `dbt`_ projects, to allow you to still lint these
"dynamic" SQL files as part of your CI/CD pipeline (which is great 🙌),
rather than waiting until you're in production (which is bad 🤦,
and maybe too late).
During the CI/CD pipeline (or any time that we need to handle `templated`_
code), SQLFluff needs additional info in order to interpret your templates
as valid SQL code. You do so by providing dummy parameters in SQLFluff
configuration files. When substituted into the template, these values should
evaluate to valid SQL (so SQLFluff can check its style, formatting, and
correctness), but the values don't need to match actual values used in
production. This means that you can use *much simpler* dummy values than
what you would really use. The recommendation is to use *the simplest*
possible dummy value that still allows your code to evaluate to valid SQL
so that the configuration values can be a streamlined as possible.
.. _`infrastructure as code`: https://en.wikipedia.org/wiki/Infrastructure_as_code
.. _`viewpoint section of the docs for the open-source tool dbt`: https://docs.getdbt.com/docs/viewpoint
.. _`quality assurance`: https://docs.getdbt.com/docs/viewpoint#section-quality-assurance
.. _`modularity`: https://docs.getdbt.com/docs/viewpoint#section-modularity
.. _`consistent style`: https://www.smashingmagazine.com/2012/10/why-coding-style-matters/
.. _`linters`: https://en.wikipedia.org/wiki/Lint_(software)
.. _`flake8`: http://flake8.pycqa.org/
.. _`jslint`: https://www.jslint.com/
.. _`templated`: https://en.wikipedia.org/wiki/Template_processor
.. _`format string syntax`: https://docs.python.org/3/library/string.html#formatstrings
.. _`jinja2`: https://jinja.palletsprojects.com/
.. _`apache airflow`: https://airflow.apache.org
.. _`dbt`: https://getdbt.com

View File

@@ -0,0 +1,65 @@
.. _apiref:
Python API
==========
SQLFluff exposes a public api for other python applications to use.
A basic example of this usage is given here, with the documentation
for each of the methods below.
.. literalinclude:: ../../../examples/01_basic_api_usage.py
:language: python
Simple API commands
-------------------
.. automodule:: sqlfluff
:members: lint, fix, parse
Advanced API usage
------------------
The simple API presents only a fraction of the functionality present
within the core SQLFluff library. For more advanced use cases, users
can import the :code:`Linter()` and :code:`FluffConfig()` classes from
:code:`sqlfluff.core`. As of version 0.4.0 this is considered as
*experimental only* as the internals may change without warning in any
future release. If you come to rely on the internals of SQLFluff, please
post an issue on GitHub to share what you're up to. This will help shape
a more reliable, tidy and well documented public API for use.
Configuring SQLFluff
~~~~~~~~~~~~~~~~~~~~
You can use :code:`FluffConfig()` class to configure SQLFluff behaviour.
.. literalinclude:: ../../../examples/04_config_overrides.py
:language: python
Instances of :code:`FluffConfig()` can be created manually, or parsed.
.. literalinclude:: ../../../examples/05_simple_api_config.py
:language: python
Supported dialects and rules are available through :code:`list_dialects()`
and :code:`list_rules()`.
.. literalinclude:: ../../../examples/03_getting_rules_and_dialects.py
:language: python
Advanced API reference
~~~~~~~~~~~~~~~~~~~~~~
.. automodule:: sqlfluff.core
:members: Linter, Lexer, Parser

View File

@@ -0,0 +1,48 @@
.. _dialectref:
Dialects Reference
==================
SQLFluff is designed to be flexible in supporting a variety of dialects.
Not all potential dialects are supported so far, but several have been
implemented by the community. Below are a list of the currently available
dialects. Each inherits from another, up to the root `ansi` dialect.
For a canonical list of supported dialects, run the
:program:`sqlfluff dialects` command, which will output a list of the
current dialects available on your installation of SQLFluff.
.. note::
For technical users looking to add new dialects or add new features
to existing ones, the dependent nature of how dialects have been
implemented is to try and reduce the amount of repetition in how
different elements are defined. As an example, when we say that
the :ref:`redshift_dialect_ref` dialect *inherits* from the
:ref:`postgres_dialect_ref` dialect this is not because there
is an agreement between those projects which means that features
in one must end up in the other, but that the design of the
:ref:`redshift_dialect_ref` dialect was heavily *inspired* by the
postgres dialect and therefore when defining the dialect within
sqlfuff it makes sense to use :ref:`postgres_dialect_ref` as a
starting point rather than starting from scratch.
Consider when adding new features to a dialect:
- Should I be adding it just to this dialect, or adding it to
a *parent* dialect?
- If I'm creating a new dialect, which dialect would be best to
inherit from?
- Will the feature I'm adding break any *downstream* dependencies
within dialects which inherit from this one?
.. We define a shortcut to render double backticks here, which can
then be referenced by individual dialects when they want to say
how backtick quotes behave in that dialect. They would otherwise
be interpreted as markup and so not shown as back quotes.
.. |back_quotes| raw:: html
<code class="code docutils literal notranslate">``</code>
.. include:: ../_partials/dialect_summaries.rst

View File

@@ -0,0 +1,14 @@
.. _reference:
Reference
=========
.. toctree::
:maxdepth: 2
dialects
rules
cli
api
internals/index
releasenotes

Some files were not shown because too many files have changed in this diff Show More