diff --git a/crates/dax/src/binder.rs b/crates/dax/src/binder.rs index 78591224d..787736804 100644 --- a/crates/dax/src/binder.rs +++ b/crates/dax/src/binder.rs @@ -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 diff --git a/crates/dax/tests/binder.rs b/crates/dax/tests/binder.rs index f8491beef..b6908447d 100644 --- a/crates/dax/tests/binder.rs +++ b/crates/dax/tests/binder.rs @@ -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()); +}