mirror of
https://github.com/storytold/gridcraft.git
synced 2026-12-01 18:26:05 -06:00
dax: bind every repeated order pair of SAMPLE and TOPNSKIP (#2228)
This commit is contained in:
@@ -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"]),
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user