From 292f0a3447c355fd445affd278826c2cd2a9cc4b Mon Sep 17 00:00:00 2001 From: alosslessdev Date: Thu, 5 Nov 2026 06:36:15 -0500 Subject: [PATCH] dax: bind every repeated order pair of SAMPLE and TOPNSKIP (#2228) --- crates/dax/src/binder.rs | 7 +++++-- crates/dax/tests/binder.rs | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/dax/src/binder.rs b/crates/dax/src/binder.rs index 846420f4b..9e475178f 100644 --- a/crates/dax/src/binder.rs +++ b/crates/dax/src/binder.rs @@ -281,8 +281,11 @@ impl<'a> Binder<'a> { // 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"]), + // SAMPLE and TOPNSKIP repeat `(orderBy, Order)` pairs, so every order word sits at + // an even offset from the first one: 3, 5, 7, ... for SAMPLE and 4, 6, 8, ... for + // TOPNSKIP. + "TOPNSKIP" if index >= 4 && (index - 4) % 2 == 0 => clause_keyword(arg, &["ASC", "DESC"]), + "SAMPLE" if index >= 3 && (index - 3) % 2 == 0 => clause_keyword(arg, &["ASC", "DESC"]), // CONCATENATEX takes `(orderBy, Order)` pairs from index 4 on, so every even // offset from 4 is an order word. "CONCATENATEX" if index >= 4 && (index - 4) % 2 == 0 => clause_keyword(arg, &["ASC", "DESC"]), diff --git a/crates/dax/tests/binder.rs b/crates/dax/tests/binder.rs index a90f878bf..9421556fe 100644 --- a/crates/dax/tests/binder.rs +++ b/crates/dax/tests/binder.rs @@ -267,6 +267,19 @@ fn documented_order_keywords_bind_at_their_argument_positions() { other => panic!("{src}: expected a call, got {other:?}"), } } + // Every repeated `(orderBy, Order)` pair binds, not just the first one. + for (src, positions) in [ + ("SAMPLE ( 10, Sales, Sales[Amount], DESC, Sales[Amount], ASC )", [3usize, 5usize]), + ("TOPNSKIP ( 10, 20, Sales, Sales[Amount], DESC, Sales[Amount], ASC )", [4usize, 6usize]), + ] { + match bind(&model, src) { + BoundExpr::Call { args, .. } => { + assert!(matches!(&args[positions[0]], BoundExpr::Keyword(word) if word == "DESC"), "{src}: {:?}", args[positions[0]]); + assert!(matches!(&args[positions[1]], BoundExpr::Keyword(word) if word == "ASC"), "{src}: {:?}", args[positions[1]]); + } + 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());