dax: bind the documented ASC/DESC slots of RANK.EQ, TOPNSKIP, SAMPLE and CONCATENATEX (#2228)

This commit is contained in:
alosslessdev
2026-11-05 03:47:57 -05:00
parent 21212be16a
commit d1cc151fc7
2 changed files with 31 additions and 0 deletions
+6
View File
@@ -278,6 +278,12 @@ impl<'a> Binder<'a> {
// RANK/ROWNUMBER's Reset argument is `NONE`, `LOWESTPARENT` or `HIGHESTPARENT`,
// catalogued as `Any` so that a relation expression still binds there.
"RANK" if index == 6 => clause_keyword(arg, &["NONE", "LOWESTPARENT", "HIGHESTPARENT"]),
// The documented bare ASC/DESC slots: RANKX and RANK.EQ take Order at index 3/2,
// TOPNSKIP/CONCATENATEX at index 4 and SAMPLE at index 3.
"RANK.EQ" if index == 2 => clause_keyword(arg, &["ASC", "DESC"]),
"TOPNSKIP" if index == 4 => clause_keyword(arg, &["ASC", "DESC"]),
"SAMPLE" if index == 3 => clause_keyword(arg, &["ASC", "DESC"]),
"CONCATENATEX" if index == 4 => clause_keyword(arg, &["ASC", "DESC"]),
"ROWNUMBER" if index == 5 => clause_keyword(arg, &["NONE", "LOWESTPARENT", "HIGHESTPARENT"]),
// Window/relation clauses take bare enum words: `ORDERBY(x, DESC)`,
// `WINDOW(1, ABS, 1, ABS, ...)`, `INDEX(..., KEEP, PARTITIONBY(...))`, and the
+25
View File
@@ -246,3 +246,28 @@ fn an_interval_keyword_is_not_shadowed_by_a_variable() {
let bound = bind(&model, "VAR DENSE = 1 RETURN RANKX ( Sales, Sales[Amount], 42, DENSE )");
assert!(format!("{bound:?}").contains("Variable"), "{bound:?}");
}
#[test]
fn documented_order_keywords_bind_at_their_argument_positions() {
let model = sample_model();
// Each documented bare `ASC`/`DESC` slot binds as a keyword instead of failing as an unknown
// name, and an undocumented word there is still a name (and therefore an unknown one).
let calls = [
("RANKX ( Sales, Sales[Amount], 42, DESC )", 3),
("RANK.EQ ( 42, Sales[Amount], DESC )", 2),
("TOPNSKIP ( 10, 20, Sales, Sales[Amount], DESC )", 4),
("CONCATENATEX ( Sales, Sales[Amount], \", \", Sales[Amount], DESC )", 4),
("SAMPLE ( 10, Sales, Sales[Amount], DESC )", 3),
];
for (src, position) in calls {
match bind(&model, src) {
BoundExpr::Call { args, .. } => {
assert!(matches!(&args[position], BoundExpr::Keyword(word) if word == "DESC"), "{src}: {:?}", args[position]);
}
other => panic!("{src}: expected a call, got {other:?}"),
}
}
// An unknown word in a keyword slot is still unknown.
let expr = parse_expression("SAMPLE ( 10, Sales, Sales[Amount], SIDEWAYS )").expect("parse");
assert!(Binder::new(&model).bind_expression(&expr).is_err());
}