jayzhan211 commented on code in PR #6796:
URL: https://github.com/apache/arrow-datafusion/pull/6796#discussion_r1346614106
##########
datafusion/expr/src/expr.rs:
##########
@@ -970,6 +987,43 @@ impl Expr {
pub fn contains_outer(&self) -> bool {
!find_out_reference_exprs(self).is_empty()
}
+
+ /// Flatten the nested array expressions until the base array is reached.
+ /// For example:
+ /// unnest([[1, 2, 3], [4, 5, 6]]) => unnest([1, 2, 3, 4, 5, 6])
+ pub fn flatten(&self) -> Self {
+ self.try_flatten().unwrap_or_else(|_| self.clone())
+ }
+
+ pub fn try_flatten(&self) -> Result<Self> {
+ match self {
+ Self::ScalarFunction(ScalarFunction {
+ fun: built_in_function::BuiltinScalarFunction::MakeArray,
+ args,
+ }) => {
+ let flatten_args: Vec<Expr> =
+ args.iter().flat_map(Self::flatten_internal).collect();
+ Ok(Self::ScalarFunction(ScalarFunction {
+ fun: built_in_function::BuiltinScalarFunction::MakeArray,
+ args: flatten_args,
+ }))
+ }
+ _ => Err(DataFusionError::Internal(format!(
Review Comment:
The updated version is in
https://github.com/apache/arrow-datafusion/pull/7461/files
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]