Skip to content

Commit 22c11ae

Browse files
committed
Merge remote-tracking branch 'github/fix/clause-keys' into land/b-107-108
2 parents 8e8b436 + b96845f commit 22c11ae

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

‎coverage/translation/form-links.toml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ forms = ["sf.query.from"]
7777
constructs = ["clause:with"]
7878
forms = ["sf.query.with.select"]
7979

80+
[[link]]
81+
constructs = ["clause:with_recursive"]
82+
forms = ["sf.query.with.select.syntax"]
83+
8084
[[link]]
8185
constructs = ["clause:where"]
8286
forms = ["sf.query.where"]
@@ -85,6 +89,10 @@ forms = ["sf.query.where"]
8589
constructs = ["clause:group_by"]
8690
forms = ["sf.query.group-by.groupitem"]
8791

92+
[[link]]
93+
constructs = ["clause:group_by_all"]
94+
forms = ["sf.query.group-by.all"]
95+
8896
[[link]]
8997
constructs = ["clause:having"]
9098
forms = ["sf.query.having"]
@@ -93,10 +101,18 @@ forms = ["sf.query.having"]
93101
constructs = ["clause:order_by"]
94102
forms = ["sf.query.order-by.orderitem"]
95103

104+
[[link]]
105+
constructs = ["clause:order_by_all"]
106+
forms = ["sf.query.order-by.all"]
107+
96108
[[link]]
97109
constructs = ["clause:qualify"]
98110
forms = ["sf.query.qualify.qualify", "sf.query.qualify.select-from-qualify"]
99111

112+
[[link]]
113+
constructs = ["clause:sample"]
114+
forms = ["sf.query.sample"]
115+
100116
[[link]]
101117
constructs = ["clause:limit"]
102118
forms = ["sf.query.limit.limit"]

‎coverage/translation/results-baseline.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11098,7 +11098,7 @@
1109811098
"sf.query.group-by-cube": "unmeasured",
1109911099
"sf.query.group-by-grouping-sets": "unmeasured",
1110011100
"sf.query.group-by-rollup": "unmeasured",
11101-
"sf.query.group-by.all": "unmeasured",
11101+
"sf.query.group-by.all": "matching",
1110211102
"sf.query.group-by.groupitem": "refused",
1110311103
"sf.query.having": "refused",
1110411104
"sf.query.into": "not_translatable",

‎crates/sqlquack-core/src/classification/_helpers/clauses.rs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub(crate) fn clause_constructs(node: &Expression) -> Vec<Construct> {
1616
Expression::Union(union) => union_clauses(union),
1717
Expression::Intersect(intersect) => intersect_clauses(intersect),
1818
Expression::Except(except) => except_clauses(except),
19+
Expression::Table(table) => present(&[(table.table_sample.is_some(), "sample")]),
1920
_ => Vec::new(),
2021
};
2122
let mut constructs: Vec<Construct> = names
@@ -87,18 +88,34 @@ fn select_clauses(select: &Select) -> Vec<String> {
8788
} = select;
8889
present(&[
8990
(with.is_some(), "with"),
91+
(
92+
with.as_ref().is_some_and(|with| with.recursive),
93+
"with_recursive",
94+
),
9095
(*distinct, "distinct"),
9196
(distinct_on.is_some(), "distinct_on"),
9297
(top.is_some(), "top"),
9398
(!lateral_views.is_empty(), "lateral_view"),
9499
(prewhere.is_some(), "prewhere"),
95100
(where_clause.is_some(), "where"),
96101
(group_by.is_some(), "group_by"),
102+
(
103+
group_by
104+
.as_ref()
105+
.is_some_and(|group_by| group_by.all == Some(true)),
106+
"group_by_all",
107+
),
97108
(having.is_some(), "having"),
98109
(windows.is_some(), "window"),
99110
(qualify.is_some(), "qualify"),
100111
(connect.is_some(), "connect_by"),
101112
(order_by.is_some(), "order_by"),
113+
(
114+
order_by
115+
.as_ref()
116+
.is_some_and(|order_by| order_by.all.is_some()),
117+
"order_by_all",
118+
),
102119
(distribute_by.is_some(), "distribute_by"),
103120
(cluster_by.is_some(), "cluster_by"),
104121
(sort_by.is_some(), "sort_by"),
@@ -159,7 +176,17 @@ macro_rules! set_operation_clauses {
159176
(*strict, concat!($prefix, "_strict")),
160177
(!on_columns.is_empty(), concat!($prefix, "_on_columns")),
161178
(with.is_some(), "with"),
179+
(
180+
with.as_ref().is_some_and(|with| with.recursive),
181+
"with_recursive",
182+
),
162183
(order_by.is_some(), "order_by"),
184+
(
185+
order_by
186+
.as_ref()
187+
.is_some_and(|order_by| order_by.all.is_some()),
188+
"order_by_all",
189+
),
163190
(limit.is_some(), "limit"),
164191
(offset.is_some(), "offset"),
165192
(distribute_by.is_some(), "distribute_by"),

‎crates/sqlquack-core/src/classification/tests/test_classify.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ fn given_snowflake_query_when_classifying_then_reports_each_construct_family() {
4343
sql: "SELECT product_id FROM products UNION ALL SELECT product_id FROM inventory",
4444
expected_keys: &["node:union", "clause:union_all"],
4545
},
46+
ConstructTestCase {
47+
description: "GROUP BY ALL and ORDER BY ALL have keys of their own beside the clause",
48+
sql: "SELECT region, COUNT(*) FROM orders GROUP BY ALL ORDER BY ALL",
49+
expected_keys: &[
50+
"clause:group_by",
51+
"clause:group_by_all",
52+
"clause:order_by",
53+
"clause:order_by_all",
54+
],
55+
},
56+
ConstructTestCase {
57+
description: "WITH RECURSIVE has a key of its own beside the clause",
58+
sql: "WITH RECURSIVE r AS (SELECT 1 AS n) SELECT n FROM r",
59+
expected_keys: &["clause:with", "clause:with_recursive"],
60+
},
61+
ConstructTestCase {
62+
description: "a SAMPLE on a table reference is a sample clause",
63+
sql: "SELECT order_id FROM orders SAMPLE (10)",
64+
expected_keys: &["clause:sample"],
65+
},
4666
ConstructTestCase {
4767
description: "project functions collapse into one construct",
4868
sql: "SELECT __sqlquack_udf(o.status) FROM orders o",

0 commit comments

Comments
 (0)