sqlccc 1.2.0__tar.gz → 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlccc
3
- Version: 1.2.0
3
+ Version: 1.3.0
4
4
  Summary: A cyclomatic complexity calculator for SQL
5
5
  Author-email: Søren Brønsted <soren@bronsted.dk>
6
6
  License-Expression: Apache-2.0
@@ -152,16 +152,20 @@ The complexity starts at 1 and each of the following adds to it:
152
152
 
153
153
  | Construct | Adds |
154
154
  |--------------------------------------------------------------------------------------------------|----------------------------|
155
- | `WHERE` | 1 per clause |
155
+ | `WHERE`, `HAVING`, `QUALIFY` | 1 per clause |
156
156
  | `AND`, `OR` | 1 each |
157
- | `IN`, `BETWEEN`, `LIKE`, `ILIKE` | 1 each |
157
+ | `IN`, `BETWEEN`, `LIKE`, `ILIKE`, `SIMILAR TO`, `ANY`, `ALL` | 1 each |
158
158
  | `GROUP BY` | 1 |
159
159
  | `WHEN` branch of a `CASE`, and `IF`, `IFF` (the `CASE` itself adds nothing) | 1 per branch or call |
160
160
  | `COALESCE`, `NVL`, `IFNULL`, `NULLIF`, `NVL2`, `DECODE`, `GREATEST`, `LEAST`, `EXISTS` | 1 per call |
161
- | `TRY_CAST`, `SAFE_CAST` | 1 per call |
162
- | `REGEXP_LIKE`, `RLIKE`, `CONTAINS`, `STARTSWITH`, `ENDSWITH`, `ARRAY_CONTAINS`, `COUNT_IF` | 1 per call |
161
+ | `LAG`, `LEAD` | 1 per call |
162
+ | `TRY_CAST`, `SAFE_CAST`, `SAFE_DIVIDE`, `TRY_TO_NUMBER`, `TRY_CONVERT` and other `TRY_`/`SAFE_` | 1 per call |
163
+ | `REGEXP_LIKE`, `RLIKE`, `CONTAINS`, `STARTSWITH`, `ENDSWITH`, `ARRAY_CONTAINS`, `ARRAYS_OVERLAP` | 1 per call |
164
+ | `COUNT_IF` | 1 per call |
163
165
  | `JOIN` of any kind, including a comma join | 1 per join |
164
166
  | `UNION`, `INTERSECT`, `EXCEPT` | 1 per operator |
167
+ | `WITH RECURSIVE`, `CONNECT BY` | 1 each |
168
+ | `WHEN` of a `MERGE` or multi table `INSERT`, `ON CONFLICT`, `ON DUPLICATE KEY` | 1 each |
165
169
 
166
170
  Everything is counted anywhere in the SQL, including subqueries and CTEs. A construct is only counted once.
167
171
 
@@ -172,15 +176,30 @@ adds 1 for the join and 1 for the `AND`.
172
176
  **A function counts when it branches**, which means that the path through the SQL depends on the data, and a test is
173
177
  needed for each path. `COALESCE` has a path for a NULL and one for a value. `CAST`, `LOWER`, `TRIM`, `CONCAT` and
174
178
  `SUBSTRING` do the same whatever the data is, and so they add nothing. Neither do the aggregates (`COUNT`, `SUM`,
175
- `MAX`, ...) and the window functions, as they change the grain and do not branch, and `GROUP BY` counts on its own.
176
- `TRY_CAST` counts, because a value which can not be converted gives NULL, which is a path of its own. A function
177
- which sqlglot does not know adds nothing either, as nothing can be said about it.
178
-
179
- `HAVING` adds nothing itself. Its expression can have any length, so it is counted by what it contains, like `AND`
180
- and `BETWEEN`. That is also why `HAVING COUNT(*) BETWEEN 1 AND 3` and `HAVING COUNT(*) >= 1 AND COUNT(*) <= 3` get the
181
- same complexity.
182
-
183
- Not counted (yet): comparisons, subqueries, CTEs, window functions in themselves and `QUALIFY`.
179
+ `MAX`, ...), as they change the grain and do not branch, and `GROUP BY` counts on its own.
180
+ `TRY_CAST` counts, because a value which can not be converted gives NULL, which is a path of its own. So do the other
181
+ functions which give NULL instead of an error, like `TRY_TO_NUMBER`, `TRY_CONVERT`, `TRY_PARSE_JSON` and `SAFE_DIVIDE`,
182
+ also when sqlglot does not know them but their name starts with `TRY_` or `SAFE_`. Any other function which sqlglot does
183
+ not know adds nothing, as nothing can be said about it.
184
+
185
+ **A clause which filters rows counts**, and `WHERE`, `HAVING` and `QUALIFY` do. The expression of the filter can have
186
+ any length, so it is also counted by what it contains, like `AND` and `BETWEEN`. That is why
187
+ `HAVING COUNT(*) BETWEEN 1 AND 3` and `HAVING COUNT(*) >= 1 AND COUNT(*) <= 3` get the same complexity.
188
+
189
+ **A window function does not filter and does not branch**, except `LAG` and `LEAD`: the first or last row of a
190
+ partition has no neighbour, which gives NULL or the default, so they count 1 per call. `ROW_NUMBER`, `RANK`, `SUM() OVER`
191
+ and the like add nothing, and a filter on them is counted by the filter. `QUALIFY ROW_NUMBER() OVER (...) = 1` and
192
+ `SELECT ... FROM (SELECT ROW_NUMBER() OVER (...) AS rn ...) WHERE rn = 1` therefore get the same complexity.
193
+
194
+ **A loop counts**: a recursive CTE (`WITH RECURSIVE`) and `CONNECT BY` repeat until nothing is left, and count 1 each, in
195
+ addition to the `UNION` and the `WHERE` they have.
196
+
197
+ **A statement which branches counts**: each `WHEN` of a `MERGE` (`MATCHED`, `NOT MATCHED`) and of a multi table
198
+ `INSERT ALL WHEN` counts 1, but the `ELSE` of the `INSERT` does not, like the `ELSE` of a `CASE`. `ON CONFLICT` and
199
+ `ON DUPLICATE KEY` count 1. The `IN` of a `PIVOT` lists the columns and is not a predicate, so it does not count, and
200
+ `LIKE ANY (...)` counts as the `LIKE` and not as an `ANY` too.
201
+
202
+ Not counted (yet): comparisons, also `IS NULL` and `IS DISTINCT FROM`, subqueries and CTEs.
184
203
  The weights are defined in `WEIGHTS` in `sqlcc.py`. `COALESCE` counts 1 however many arguments it has.
185
204
 
186
205
  Which functions sqlglot knows depends on its version, and an unknown function adds nothing. For example, `IFF` in the
@@ -136,16 +136,20 @@ The complexity starts at 1 and each of the following adds to it:
136
136
 
137
137
  | Construct | Adds |
138
138
  |--------------------------------------------------------------------------------------------------|----------------------------|
139
- | `WHERE` | 1 per clause |
139
+ | `WHERE`, `HAVING`, `QUALIFY` | 1 per clause |
140
140
  | `AND`, `OR` | 1 each |
141
- | `IN`, `BETWEEN`, `LIKE`, `ILIKE` | 1 each |
141
+ | `IN`, `BETWEEN`, `LIKE`, `ILIKE`, `SIMILAR TO`, `ANY`, `ALL` | 1 each |
142
142
  | `GROUP BY` | 1 |
143
143
  | `WHEN` branch of a `CASE`, and `IF`, `IFF` (the `CASE` itself adds nothing) | 1 per branch or call |
144
144
  | `COALESCE`, `NVL`, `IFNULL`, `NULLIF`, `NVL2`, `DECODE`, `GREATEST`, `LEAST`, `EXISTS` | 1 per call |
145
- | `TRY_CAST`, `SAFE_CAST` | 1 per call |
146
- | `REGEXP_LIKE`, `RLIKE`, `CONTAINS`, `STARTSWITH`, `ENDSWITH`, `ARRAY_CONTAINS`, `COUNT_IF` | 1 per call |
145
+ | `LAG`, `LEAD` | 1 per call |
146
+ | `TRY_CAST`, `SAFE_CAST`, `SAFE_DIVIDE`, `TRY_TO_NUMBER`, `TRY_CONVERT` and other `TRY_`/`SAFE_` | 1 per call |
147
+ | `REGEXP_LIKE`, `RLIKE`, `CONTAINS`, `STARTSWITH`, `ENDSWITH`, `ARRAY_CONTAINS`, `ARRAYS_OVERLAP` | 1 per call |
148
+ | `COUNT_IF` | 1 per call |
147
149
  | `JOIN` of any kind, including a comma join | 1 per join |
148
150
  | `UNION`, `INTERSECT`, `EXCEPT` | 1 per operator |
151
+ | `WITH RECURSIVE`, `CONNECT BY` | 1 each |
152
+ | `WHEN` of a `MERGE` or multi table `INSERT`, `ON CONFLICT`, `ON DUPLICATE KEY` | 1 each |
149
153
 
150
154
  Everything is counted anywhere in the SQL, including subqueries and CTEs. A construct is only counted once.
151
155
 
@@ -156,15 +160,30 @@ adds 1 for the join and 1 for the `AND`.
156
160
  **A function counts when it branches**, which means that the path through the SQL depends on the data, and a test is
157
161
  needed for each path. `COALESCE` has a path for a NULL and one for a value. `CAST`, `LOWER`, `TRIM`, `CONCAT` and
158
162
  `SUBSTRING` do the same whatever the data is, and so they add nothing. Neither do the aggregates (`COUNT`, `SUM`,
159
- `MAX`, ...) and the window functions, as they change the grain and do not branch, and `GROUP BY` counts on its own.
160
- `TRY_CAST` counts, because a value which can not be converted gives NULL, which is a path of its own. A function
161
- which sqlglot does not know adds nothing either, as nothing can be said about it.
162
-
163
- `HAVING` adds nothing itself. Its expression can have any length, so it is counted by what it contains, like `AND`
164
- and `BETWEEN`. That is also why `HAVING COUNT(*) BETWEEN 1 AND 3` and `HAVING COUNT(*) >= 1 AND COUNT(*) <= 3` get the
165
- same complexity.
166
-
167
- Not counted (yet): comparisons, subqueries, CTEs, window functions in themselves and `QUALIFY`.
163
+ `MAX`, ...), as they change the grain and do not branch, and `GROUP BY` counts on its own.
164
+ `TRY_CAST` counts, because a value which can not be converted gives NULL, which is a path of its own. So do the other
165
+ functions which give NULL instead of an error, like `TRY_TO_NUMBER`, `TRY_CONVERT`, `TRY_PARSE_JSON` and `SAFE_DIVIDE`,
166
+ also when sqlglot does not know them but their name starts with `TRY_` or `SAFE_`. Any other function which sqlglot does
167
+ not know adds nothing, as nothing can be said about it.
168
+
169
+ **A clause which filters rows counts**, and `WHERE`, `HAVING` and `QUALIFY` do. The expression of the filter can have
170
+ any length, so it is also counted by what it contains, like `AND` and `BETWEEN`. That is why
171
+ `HAVING COUNT(*) BETWEEN 1 AND 3` and `HAVING COUNT(*) >= 1 AND COUNT(*) <= 3` get the same complexity.
172
+
173
+ **A window function does not filter and does not branch**, except `LAG` and `LEAD`: the first or last row of a
174
+ partition has no neighbour, which gives NULL or the default, so they count 1 per call. `ROW_NUMBER`, `RANK`, `SUM() OVER`
175
+ and the like add nothing, and a filter on them is counted by the filter. `QUALIFY ROW_NUMBER() OVER (...) = 1` and
176
+ `SELECT ... FROM (SELECT ROW_NUMBER() OVER (...) AS rn ...) WHERE rn = 1` therefore get the same complexity.
177
+
178
+ **A loop counts**: a recursive CTE (`WITH RECURSIVE`) and `CONNECT BY` repeat until nothing is left, and count 1 each, in
179
+ addition to the `UNION` and the `WHERE` they have.
180
+
181
+ **A statement which branches counts**: each `WHEN` of a `MERGE` (`MATCHED`, `NOT MATCHED`) and of a multi table
182
+ `INSERT ALL WHEN` counts 1, but the `ELSE` of the `INSERT` does not, like the `ELSE` of a `CASE`. `ON CONFLICT` and
183
+ `ON DUPLICATE KEY` count 1. The `IN` of a `PIVOT` lists the columns and is not a predicate, so it does not count, and
184
+ `LIKE ANY (...)` counts as the `LIKE` and not as an `ANY` too.
185
+
186
+ Not counted (yet): comparisons, also `IS NULL` and `IS DISTINCT FROM`, subqueries and CTEs.
168
187
  The weights are defined in `WEIGHTS` in `sqlcc.py`. `COALESCE` counts 1 however many arguments it has.
169
188
 
170
189
  Which functions sqlglot knows depends on its version, and an unknown function adds nothing. For example, `IFF` in the
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sqlccc"
3
- version = "1.2.0"
3
+ version = "1.3.0"
4
4
  authors = [
5
5
  { name="Søren Brønsted", email="soren@bronsted.dk" },
6
6
  ]
@@ -3,6 +3,7 @@ import json
3
3
  import os
4
4
  import sys
5
5
  from collections import Counter
6
+ from collections.abc import Callable
6
7
  from dataclasses import dataclass
7
8
  from pathlib import Path
8
9
 
@@ -15,32 +16,64 @@ MAX_SKIPPED_LISTED = 5
15
16
  # dbt adapter types that are named differently from the sqlglot dialect
16
17
  ADAPTER_DIALECTS = {'sqlserver': 'tsql'}
17
18
 
19
+
20
+ def _if_arg(name: str) -> Callable[[sg.exp.Expression], int]:
21
+ return lambda node: 1 if node.args.get(name) else 0
22
+
23
+
24
+ def _unless_parent(*classes: type) -> Callable[[sg.exp.Expression], int]:
25
+ return lambda node: 0 if isinstance(node.parent, classes) else 1
26
+
27
+
28
+ def _named(*prefixes: str) -> Callable[[sg.exp.Expression], int]:
29
+ return lambda node: 1 if node.name.upper().startswith(prefixes) else 0
30
+
31
+
18
32
  # The weight each construct adds to the complexity. A node gets the weight of the most specific class
19
33
  # in its inheritance chain, so a Union counts as the SetOperation it is, and a node which has no class
20
- # in WEIGHTS adds nothing.
34
+ # in WEIGHTS adds nothing. The weight is a number, or a function of the node when it depends on more
35
+ # than the class.
21
36
  WEIGHTS = {
22
- # Logic: HAVING is not weighted, its expression varies in length and is counted by what it contains
23
- sg.exp.Where: 1, sg.exp.And: 1, sg.exp.Or: 1, sg.exp.In: 1, sg.exp.Between: 1,
24
- sg.exp.Like: 1, sg.exp.ILike: 1, sg.exp.Group: 1,
37
+ # Logic: a filter (WHERE, HAVING, QUALIFY) counts 1, and its expression is counted by what it contains.
38
+ # The IN of a PIVOT lists the columns, and LIKE ANY counts as the LIKE
39
+ sg.exp.Where: 1, sg.exp.Having: 1, sg.exp.Qualify: 1, sg.exp.And: 1, sg.exp.Or: 1,
40
+ sg.exp.In: _unless_parent(sg.exp.Pivot), sg.exp.Between: 1, sg.exp.Like: 1, sg.exp.ILike: 1,
41
+ sg.exp.SimilarTo: 1, sg.exp.Group: 1,
42
+ sg.exp.Any: _unless_parent(sg.exp.Like, sg.exp.ILike, sg.exp.SimilarTo),
43
+ sg.exp.All: _unless_parent(sg.exp.Like, sg.exp.ILike, sg.exp.SimilarTo),
25
44
  # Functions: only the ones which branch count, and a CASE through its WHEN branches (sg.exp.If). The others,
26
45
  # like CAST and LOWER, take the same path whatever the data is. So do the ones sqlglot does not know
27
- # (sg.exp.Anonymous), as nothing can be said about them.
46
+ # (sg.exp.Anonymous), as nothing can be said about them, except the ones which are named TRY_ or SAFE_
28
47
  sg.exp.If: 1, sg.exp.Coalesce: 1, sg.exp.Nullif: 1, sg.exp.Nvl2: 1, sg.exp.DecodeCase: 1,
29
48
  sg.exp.Greatest: 1, sg.exp.Least: 1, sg.exp.Exists: 1,
30
- # A conversion which fails gives NULL, and that is a path of its own
31
- sg.exp.TryCast: 1,
49
+ # The first or last row of a partition has no neighbour, which gives NULL or the default. The other window
50
+ # functions, like ROW_NUMBER, do not branch, and a filter on them is counted by the filter
51
+ sg.exp.Lag: 1, sg.exp.Lead: 1,
52
+ # A conversion which fails gives NULL, and that is a path of its own. sqlglot sets safe on the ones which do,
53
+ # like TRY_TO_NUMBER, TRY_CONVERT and TRY_PARSE_JSON, but also on CONCAT, which is only about NULL arguments
54
+ sg.exp.TryCast: 1, sg.exp.SafeDivide: 1, sg.exp.Func: _if_arg('safe'), sg.exp.Concat: 0,
55
+ sg.exp.Anonymous: _named('TRY_', 'SAFE_'),
32
56
  # Functions which are predicates, like LIKE and IN
33
57
  sg.exp.RegexpLike: 1, sg.exp.RegexpILike: 1, sg.exp.Contains: 1, sg.exp.StartsWith: 1,
34
- sg.exp.EndsWith: 1, sg.exp.ArrayContains: 1, sg.exp.CountIf: 1,
58
+ sg.exp.EndsWith: 1, sg.exp.ArrayContains: 1, sg.exp.ArrayOverlaps: 1, sg.exp.CountIf: 1,
35
59
  # Sets: SetOperation is UNION, INTERSECT and EXCEPT
36
60
  sg.exp.Join: 1, sg.exp.SetOperation: 1,
61
+ # Loops: a recursive CTE, and CONNECT BY
62
+ sg.exp.With: _if_arg('recursive'), sg.exp.Connect: 1,
63
+ # Branches of a statement: WHEN of MERGE, WHEN of a multi table INSERT (not its ELSE), and ON CONFLICT
64
+ # or ON DUPLICATE KEY
65
+ sg.exp.When: 1, sg.exp.ConditionalInsert: _if_arg('expression'), sg.exp.OnConflict: 1,
37
66
  }
67
+ # SAFE.f() of BigQuery returns NULL for an error. It is only known to sqlglot from a later version
68
+ if hasattr(sg.exp, 'SafeFunc'):
69
+ WEIGHTS[sg.exp.SafeFunc] = 1
38
70
 
39
71
 
40
72
  def _weight(node: sg.exp.Expression) -> int:
41
73
  for cls in type(node).__mro__:
42
74
  if cls in WEIGHTS:
43
- return WEIGHTS[cls]
75
+ weight = WEIGHTS[cls]
76
+ return weight(node) if callable(weight) else weight
44
77
  return 0
45
78
 
46
79
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlccc
3
- Version: 1.2.0
3
+ Version: 1.3.0
4
4
  Summary: A cyclomatic complexity calculator for SQL
5
5
  Author-email: Søren Brønsted <soren@bronsted.dk>
6
6
  License-Expression: Apache-2.0
@@ -152,16 +152,20 @@ The complexity starts at 1 and each of the following adds to it:
152
152
 
153
153
  | Construct | Adds |
154
154
  |--------------------------------------------------------------------------------------------------|----------------------------|
155
- | `WHERE` | 1 per clause |
155
+ | `WHERE`, `HAVING`, `QUALIFY` | 1 per clause |
156
156
  | `AND`, `OR` | 1 each |
157
- | `IN`, `BETWEEN`, `LIKE`, `ILIKE` | 1 each |
157
+ | `IN`, `BETWEEN`, `LIKE`, `ILIKE`, `SIMILAR TO`, `ANY`, `ALL` | 1 each |
158
158
  | `GROUP BY` | 1 |
159
159
  | `WHEN` branch of a `CASE`, and `IF`, `IFF` (the `CASE` itself adds nothing) | 1 per branch or call |
160
160
  | `COALESCE`, `NVL`, `IFNULL`, `NULLIF`, `NVL2`, `DECODE`, `GREATEST`, `LEAST`, `EXISTS` | 1 per call |
161
- | `TRY_CAST`, `SAFE_CAST` | 1 per call |
162
- | `REGEXP_LIKE`, `RLIKE`, `CONTAINS`, `STARTSWITH`, `ENDSWITH`, `ARRAY_CONTAINS`, `COUNT_IF` | 1 per call |
161
+ | `LAG`, `LEAD` | 1 per call |
162
+ | `TRY_CAST`, `SAFE_CAST`, `SAFE_DIVIDE`, `TRY_TO_NUMBER`, `TRY_CONVERT` and other `TRY_`/`SAFE_` | 1 per call |
163
+ | `REGEXP_LIKE`, `RLIKE`, `CONTAINS`, `STARTSWITH`, `ENDSWITH`, `ARRAY_CONTAINS`, `ARRAYS_OVERLAP` | 1 per call |
164
+ | `COUNT_IF` | 1 per call |
163
165
  | `JOIN` of any kind, including a comma join | 1 per join |
164
166
  | `UNION`, `INTERSECT`, `EXCEPT` | 1 per operator |
167
+ | `WITH RECURSIVE`, `CONNECT BY` | 1 each |
168
+ | `WHEN` of a `MERGE` or multi table `INSERT`, `ON CONFLICT`, `ON DUPLICATE KEY` | 1 each |
165
169
 
166
170
  Everything is counted anywhere in the SQL, including subqueries and CTEs. A construct is only counted once.
167
171
 
@@ -172,15 +176,30 @@ adds 1 for the join and 1 for the `AND`.
172
176
  **A function counts when it branches**, which means that the path through the SQL depends on the data, and a test is
173
177
  needed for each path. `COALESCE` has a path for a NULL and one for a value. `CAST`, `LOWER`, `TRIM`, `CONCAT` and
174
178
  `SUBSTRING` do the same whatever the data is, and so they add nothing. Neither do the aggregates (`COUNT`, `SUM`,
175
- `MAX`, ...) and the window functions, as they change the grain and do not branch, and `GROUP BY` counts on its own.
176
- `TRY_CAST` counts, because a value which can not be converted gives NULL, which is a path of its own. A function
177
- which sqlglot does not know adds nothing either, as nothing can be said about it.
178
-
179
- `HAVING` adds nothing itself. Its expression can have any length, so it is counted by what it contains, like `AND`
180
- and `BETWEEN`. That is also why `HAVING COUNT(*) BETWEEN 1 AND 3` and `HAVING COUNT(*) >= 1 AND COUNT(*) <= 3` get the
181
- same complexity.
182
-
183
- Not counted (yet): comparisons, subqueries, CTEs, window functions in themselves and `QUALIFY`.
179
+ `MAX`, ...), as they change the grain and do not branch, and `GROUP BY` counts on its own.
180
+ `TRY_CAST` counts, because a value which can not be converted gives NULL, which is a path of its own. So do the other
181
+ functions which give NULL instead of an error, like `TRY_TO_NUMBER`, `TRY_CONVERT`, `TRY_PARSE_JSON` and `SAFE_DIVIDE`,
182
+ also when sqlglot does not know them but their name starts with `TRY_` or `SAFE_`. Any other function which sqlglot does
183
+ not know adds nothing, as nothing can be said about it.
184
+
185
+ **A clause which filters rows counts**, and `WHERE`, `HAVING` and `QUALIFY` do. The expression of the filter can have
186
+ any length, so it is also counted by what it contains, like `AND` and `BETWEEN`. That is why
187
+ `HAVING COUNT(*) BETWEEN 1 AND 3` and `HAVING COUNT(*) >= 1 AND COUNT(*) <= 3` get the same complexity.
188
+
189
+ **A window function does not filter and does not branch**, except `LAG` and `LEAD`: the first or last row of a
190
+ partition has no neighbour, which gives NULL or the default, so they count 1 per call. `ROW_NUMBER`, `RANK`, `SUM() OVER`
191
+ and the like add nothing, and a filter on them is counted by the filter. `QUALIFY ROW_NUMBER() OVER (...) = 1` and
192
+ `SELECT ... FROM (SELECT ROW_NUMBER() OVER (...) AS rn ...) WHERE rn = 1` therefore get the same complexity.
193
+
194
+ **A loop counts**: a recursive CTE (`WITH RECURSIVE`) and `CONNECT BY` repeat until nothing is left, and count 1 each, in
195
+ addition to the `UNION` and the `WHERE` they have.
196
+
197
+ **A statement which branches counts**: each `WHEN` of a `MERGE` (`MATCHED`, `NOT MATCHED`) and of a multi table
198
+ `INSERT ALL WHEN` counts 1, but the `ELSE` of the `INSERT` does not, like the `ELSE` of a `CASE`. `ON CONFLICT` and
199
+ `ON DUPLICATE KEY` count 1. The `IN` of a `PIVOT` lists the columns and is not a predicate, so it does not count, and
200
+ `LIKE ANY (...)` counts as the `LIKE` and not as an `ANY` too.
201
+
202
+ Not counted (yet): comparisons, also `IS NULL` and `IS DISTINCT FROM`, subqueries and CTEs.
184
203
  The weights are defined in `WEIGHTS` in `sqlcc.py`. `COALESCE` counts 1 however many arguments it has.
185
204
 
186
205
  Which functions sqlglot knows depends on its version, and an unknown function adds nothing. For example, `IFF` in the
File without changes
File without changes