Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions coverage/translation/form-links.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ forms = ["sf.query.from"]
constructs = ["clause:with"]
forms = ["sf.query.with.select"]

[[link]]
constructs = ["clause:with_recursive"]
forms = ["sf.query.with.select.syntax"]

[[link]]
constructs = ["clause:where"]
forms = ["sf.query.where"]
Expand All @@ -85,6 +89,10 @@ forms = ["sf.query.where"]
constructs = ["clause:group_by"]
forms = ["sf.query.group-by.groupitem"]

[[link]]
constructs = ["clause:group_by_all"]
forms = ["sf.query.group-by.all"]

[[link]]
constructs = ["clause:having"]
forms = ["sf.query.having"]
Expand All @@ -93,10 +101,18 @@ forms = ["sf.query.having"]
constructs = ["clause:order_by"]
forms = ["sf.query.order-by.orderitem"]

[[link]]
constructs = ["clause:order_by_all"]
forms = ["sf.query.order-by.all"]

[[link]]
constructs = ["clause:qualify"]
forms = ["sf.query.qualify.qualify", "sf.query.qualify.select-from-qualify"]

[[link]]
constructs = ["clause:sample"]
forms = ["sf.query.sample"]

[[link]]
constructs = ["clause:limit"]
forms = ["sf.query.limit.limit"]
Expand Down
2 changes: 1 addition & 1 deletion coverage/translation/results-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -11098,7 +11098,7 @@
"sf.query.group-by-cube": "unmeasured",
"sf.query.group-by-grouping-sets": "unmeasured",
"sf.query.group-by-rollup": "unmeasured",
"sf.query.group-by.all": "unmeasured",
"sf.query.group-by.all": "matching",
"sf.query.group-by.groupitem": "refused",
"sf.query.having": "refused",
"sf.query.into": "not_translatable",
Expand Down
27 changes: 27 additions & 0 deletions crates/sqlquack-core/src/classification/_helpers/clauses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) fn clause_constructs(node: &Expression) -> Vec<Construct> {
Expression::Union(union) => union_clauses(union),
Expression::Intersect(intersect) => intersect_clauses(intersect),
Expression::Except(except) => except_clauses(except),
Expression::Table(table) => present(&[(table.table_sample.is_some(), "sample")]),
_ => Vec::new(),
};
let mut constructs: Vec<Construct> = names
Expand Down Expand Up @@ -87,18 +88,34 @@ fn select_clauses(select: &Select) -> Vec<String> {
} = select;
present(&[
(with.is_some(), "with"),
(
with.as_ref().is_some_and(|with| with.recursive),
"with_recursive",
),
(*distinct, "distinct"),
(distinct_on.is_some(), "distinct_on"),
(top.is_some(), "top"),
(!lateral_views.is_empty(), "lateral_view"),
(prewhere.is_some(), "prewhere"),
(where_clause.is_some(), "where"),
(group_by.is_some(), "group_by"),
(
group_by
.as_ref()
.is_some_and(|group_by| group_by.all == Some(true)),
"group_by_all",
),
(having.is_some(), "having"),
(windows.is_some(), "window"),
(qualify.is_some(), "qualify"),
(connect.is_some(), "connect_by"),
(order_by.is_some(), "order_by"),
(
order_by
.as_ref()
.is_some_and(|order_by| order_by.all.is_some()),
"order_by_all",
),
(distribute_by.is_some(), "distribute_by"),
(cluster_by.is_some(), "cluster_by"),
(sort_by.is_some(), "sort_by"),
Expand Down Expand Up @@ -159,7 +176,17 @@ macro_rules! set_operation_clauses {
(*strict, concat!($prefix, "_strict")),
(!on_columns.is_empty(), concat!($prefix, "_on_columns")),
(with.is_some(), "with"),
(
with.as_ref().is_some_and(|with| with.recursive),
"with_recursive",
),
(order_by.is_some(), "order_by"),
(
order_by
.as_ref()
.is_some_and(|order_by| order_by.all.is_some()),
"order_by_all",
),
(limit.is_some(), "limit"),
(offset.is_some(), "offset"),
(distribute_by.is_some(), "distribute_by"),
Expand Down
20 changes: 20 additions & 0 deletions crates/sqlquack-core/src/classification/tests/test_classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ fn given_snowflake_query_when_classifying_then_reports_each_construct_family() {
sql: "SELECT product_id FROM products UNION ALL SELECT product_id FROM inventory",
expected_keys: &["node:union", "clause:union_all"],
},
ConstructTestCase {
description: "GROUP BY ALL and ORDER BY ALL have keys of their own beside the clause",
sql: "SELECT region, COUNT(*) FROM orders GROUP BY ALL ORDER BY ALL",
expected_keys: &[
"clause:group_by",
"clause:group_by_all",
"clause:order_by",
"clause:order_by_all",
],
},
ConstructTestCase {
description: "WITH RECURSIVE has a key of its own beside the clause",
sql: "WITH RECURSIVE r AS (SELECT 1 AS n) SELECT n FROM r",
expected_keys: &["clause:with", "clause:with_recursive"],
},
ConstructTestCase {
description: "a SAMPLE on a table reference is a sample clause",
sql: "SELECT order_id FROM orders SAMPLE (10)",
expected_keys: &["clause:sample"],
},
ConstructTestCase {
description: "project functions collapse into one construct",
sql: "SELECT __sqlquack_udf(o.status) FROM orders o",
Expand Down
Loading