Skip to content

Commit

Permalink
auto type inference for array_agg
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <[email protected]>
  • Loading branch information
wangrunji0408 committed Sep 19, 2023
1 parent 343cb14 commit e95e7bd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/expr/macro/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ impl FunctionAttr {
// infer as the type of "anyarray" argument
return Ok(quote! { |args| Ok(args[#i].clone()) });
}
if let Some(i) = self.args.iter().position(|t| t == "any") {
// infer as the array type of "any" argument
return Ok(quote! { |args| Ok(DataType::List(Box::new(args[#i].clone()))) });
}
} else if self.ret == "struct" {
if let Some(i) = self.args.iter().position(|t| t == "struct") {
// infer as the type of "struct" argument
Expand Down
5 changes: 1 addition & 4 deletions src/expr/src/agg/array_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ use risingwave_common::array::ListValue;
use risingwave_common::types::{Datum, ScalarRefImpl, ToOwnedDatum};
use risingwave_expr_macro::aggregate;

#[aggregate(
"array_agg(any) -> anyarray",
type_infer = "|args| Ok(DataType::List(Box::new(args[0].clone())))"
)]
#[aggregate("array_agg(any) -> anyarray")]
fn array_agg(state: Option<ListValue>, value: Option<ScalarRefImpl<'_>>) -> ListValue {
let mut state: Vec<Datum> = state.unwrap_or_default().into();
state.push(value.to_owned_datum());
Expand Down

0 comments on commit e95e7bd

Please sign in to comment.