@@ -70,44 +70,36 @@ impl AggregateColumn {
7070 & self . function
7171 }
7272
73- pub fn aggregate_expr ( & self , schema : & ArrowSchema ) -> Result < AggregateFunctionExpr , CubeError > {
73+ pub fn aggregate_expr (
74+ & self ,
75+ schema : & Arc < ArrowSchema > ,
76+ ) -> Result < AggregateFunctionExpr , CubeError > {
7477 let col = Arc :: new ( FusionColumn :: new_with_schema (
7578 self . column . get_name ( ) . as_str ( ) ,
76- & schema,
79+ schema,
7780 ) ?) ;
78- let res: AggregateFunctionExpr = match self . function {
79- AggregateFunction :: SUM => AggregateExprBuilder :: new (
80- Arc :: new ( AggregateUDF :: new_from_impl ( Sum :: new ( ) ) ) ,
81- vec ! [ col] ,
82- )
83- . build ( ) ?,
84- AggregateFunction :: MAX => AggregateExprBuilder :: new (
85- Arc :: new ( AggregateUDF :: new_from_impl ( Max :: new ( ) ) ) ,
86- vec ! [ col] ,
87- )
88- . build ( ) ?,
89- AggregateFunction :: MIN => AggregateExprBuilder :: new (
90- Arc :: new ( AggregateUDF :: new_from_impl ( Min :: new ( ) ) ) ,
91- vec ! [ col] ,
92- )
93- . build ( ) ?,
94- AggregateFunction :: MERGE => {
95- let fun = aggregate_udf_by_kind ( CubeAggregateUDFKind :: MergeHll ) ;
96-
97- // TODO upgrade DF: Understand what effect the choice of alias value has.
98- // TODO upgrade DF: We probably want .schema and .alias on other cases.
99- // TODO upgrade DF: schema.clone() is wasteful; pass an &Arc<ArrowSchema> to this function.
100- // TODO upgrade DF: Do we want more than .alias and .schema? It seems some stuff is mandatory, in general
101-
102- // A comment in DF downstream name() fn suggests 'Human readable name such as
103- // `"MIN(c2)"`.' It is mandatory that a .alias be supplied.
104- let alias = format ! ( "MERGE({})" , col. name( ) ) ;
105- AggregateExprBuilder :: new ( Arc :: new ( fun) , vec ! [ col] )
106- . schema ( Arc :: new ( schema. clone ( ) ) )
107- . alias ( alias)
108- . build ( ) ?
109- }
81+ let ( name, udaf) : ( & str , AggregateUDF ) = match self . function {
82+ AggregateFunction :: SUM => ( "SUM" , AggregateUDF :: new_from_impl ( Sum :: new ( ) ) ) ,
83+ AggregateFunction :: MAX => ( "MAX" , AggregateUDF :: new_from_impl ( Max :: new ( ) ) ) ,
84+ AggregateFunction :: MIN => ( "MIN" , AggregateUDF :: new_from_impl ( Min :: new ( ) ) ) ,
85+ AggregateFunction :: MERGE => (
86+ "MERGE" ,
87+ aggregate_udf_by_kind ( CubeAggregateUDFKind :: MergeHll ) ,
88+ ) ,
11089 } ;
90+
91+ // TODO upgrade DF: Understand what effect the choice of alias value has.
92+ // TODO upgrade DF: schema.clone() is wasteful; pass an &Arc<ArrowSchema> to this function.
93+ // TODO upgrade DF: Do we want more than .alias and .schema? It seems some stuff is mandatory, in general
94+
95+ // A comment in DF downstream name() fn suggests 'Human readable name such as
96+ // `"MIN(c2)"`.' It is mandatory that a .alias be supplied.
97+ let alias = format ! ( "{}({})" , name, col. name( ) ) ;
98+ let res: AggregateFunctionExpr = AggregateExprBuilder :: new ( Arc :: new ( udaf) , vec ! [ col] )
99+ . schema ( schema. clone ( ) )
100+ . alias ( alias)
101+ . build ( ) ?;
102+
111103 Ok ( res)
112104 }
113105}
0 commit comments