You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e30bb65
Browse filesBrowse the repository at this point in the historyBrowse files
fix(optimizer): preserve alias qualifier in coalesce_first_last
A qualified alias on a coalesced peer lost its qualifier and tripped the
optimizer's schema-invariant check. Also normalizes null treatment in the
bucket key, notes in the docs that ties may resolve differently with the
rule on vs off, and adds result-level slt coverage for NULL order keys,
explicit null placement, multi-key ORDER BY, struct payloads, and tied keys.
// Regression: the qualifier must survive the rewrite or the schema
598
+
// invariant check rejects the plan (the alias prints bare either way).
599
+
let plan = LogicalPlanBuilder::from(scan()?)
600
+
.aggregate(
601
+
vec![col("p")],
602
+
vec![
603
+
first_value(col("a"), order_by_o(),false)
604
+
.alias_qualified(Some("t"),"fa"),
605
+
first_value(col("b"), order_by_o(),false)
606
+
.alias_qualified(Some("t"),"fb"),
607
+
],
608
+
)?
609
+
.build()?;
610
+
assert_coalesced!(TestConfig::new(), plan, @ r#"
611
+
Projection: t.p, get_field(__coalesce_first_last_1, Utf8("c0")) AS fa, get_field(__coalesce_first_last_1, Utf8("c1")) AS fb
612
+
Aggregate: groupBy=[[t.p]], aggr=[[first_value(named_struct(Utf8("c0"), t.a, Utf8("c1"), t.b)) ORDER BY [t.o DESC NULLS LAST] AS __coalesce_first_last_1]]
613
+
TableScan: t
614
+
"#)
615
+
}
616
+
617
+
#[test]
618
+
fncoalesces_global_aggregate() -> Result<()>{
619
+
// No GROUP BY, so the group/aggregate split of the output columns is at 0.
620
+
let plan = LogicalPlanBuilder::from(scan()?)
621
+
.aggregate(
622
+
Vec::<Expr>::new(),
623
+
vec![
624
+
first_value(col("a"), order_by_o(),false),
625
+
first_value(col("b"), order_by_o(),false),
626
+
],
627
+
)?
628
+
.build()?;
629
+
assert_coalesced!(TestConfig::new(), plan, @ r#"
630
+
Projection: get_field(__coalesce_first_last_1, Utf8("c0")) AS first_value(t.a) ORDER BY [t.o DESC NULLS LAST], get_field(__coalesce_first_last_1, Utf8("c1")) AS first_value(t.b) ORDER BY [t.o DESC NULLS LAST]
631
+
Aggregate: groupBy=[[]], aggr=[[first_value(named_struct(Utf8("c0"), t.a, Utf8("c1"), t.b)) ORDER BY [t.o DESC NULLS LAST] AS __coalesce_first_last_1]]
632
+
TableScan: t
633
+
"#)
634
+
}
635
+
636
+
#[test]
637
+
fncoalesces_two_buckets() -> Result<()>{
638
+
// Two ORDER BY keys => two buckets => one coalesced aggregate each.
639
+
let by_b = vec![Sort::new(col("b"),true,true)];
640
+
let plan = LogicalPlanBuilder::from(scan()?)
641
+
.aggregate(
642
+
vec![col("p")],
643
+
vec![
644
+
first_value(col("a"), order_by_o(),false),
645
+
first_value(col("b"), order_by_o(),false),
646
+
first_value(col("a"), by_b.clone(),false),
647
+
first_value(col("o"), by_b,false),
648
+
],
649
+
)?
650
+
.build()?;
651
+
assert_coalesced!(TestConfig::new(), plan, @ r#"
652
+
Projection: t.p, get_field(__coalesce_first_last_1, Utf8("c0")) AS first_value(t.a) ORDER BY [t.o DESC NULLS LAST], get_field(__coalesce_first_last_1, Utf8("c1")) AS first_value(t.b) ORDER BY [t.o DESC NULLS LAST], get_field(__coalesce_first_last_2, Utf8("c0")) AS first_value(t.a) ORDER BY [t.b ASC NULLS FIRST], get_field(__coalesce_first_last_2, Utf8("c1")) AS first_value(t.o) ORDER BY [t.b ASC NULLS FIRST]
653
+
Aggregate: groupBy=[[t.p]], aggr=[[first_value(named_struct(Utf8("c0"), t.a, Utf8("c1"), t.b)) ORDER BY [t.o DESC NULLS LAST] AS __coalesce_first_last_1, first_value(named_struct(Utf8("c0"), t.a, Utf8("c1"), t.o)) ORDER BY [t.b ASC NULLS FIRST] AS __coalesce_first_last_2]]
Projection: t.p, get_field(__coalesce_first_last_1, Utf8("c0")) AS first_value(t.a) ORDER BY [t.o DESC NULLS LAST], get_field(__coalesce_first_last_1, Utf8("c1")) AS first_value(t.b) RESPECT NULLS ORDER BY [t.o DESC NULLS LAST]
677
+
Aggregate: groupBy=[[t.p]], aggr=[[first_value(named_struct(Utf8("c0"), t.a, Utf8("c1"), t.b)) ORDER BY [t.o DESC NULLS LAST] AS __coalesce_first_last_1]]
678
+
TableScan: t
679
+
"#)
680
+
}
681
+
573
682
#[test]
574
683
fncoalesces_three_peers() -> Result<()>{
575
684
// A bucket with three members packs into c0 / c1 / c2.
0 commit comments