izveigor commented on code in PR #6384:
URL: https://github.com/apache/arrow-datafusion/pull/6384#discussion_r1209545448
##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -115,3 +149,1560 @@ pub fn array(values: &[ColumnarValue]) ->
Result<ColumnarValue> {
.collect();
Ok(ColumnarValue::Array(array_array(arrays.as_slice())?))
}
+
+macro_rules! downcast_arg {
+ ($ARG:expr, $ARRAY_TYPE:ident) => {{
+ $ARG.as_any().downcast_ref::<$ARRAY_TYPE>().ok_or_else(|| {
+ DataFusionError::Internal(format!(
+ "could not cast to {}",
+ type_name::<$ARRAY_TYPE>()
+ ))
+ })?
+ }};
+}
+
+macro_rules! append {
+ ($ARRAY:expr, $ELEMENT:expr, $ARRAY_TYPE:ident) => {{
+ let child_array =
+ downcast_arg!(downcast_arg!($ARRAY, ListArray).values(),
$ARRAY_TYPE);
+ let element = downcast_arg!($ELEMENT, $ARRAY_TYPE);
+ let concat = compute::concat(&[child_array, element])?;
+ let mut scalars = vec![];
+ for i in 0..concat.len() {
+ scalars.push(ColumnarValue::Scalar(ScalarValue::try_from_array(
+ &concat, i,
+ )?));
+ }
+ scalars
+ }};
+}
+
+/// Array_append SQL function
+pub fn array_append(args: &[ColumnarValue]) -> Result<ColumnarValue> {
+ if args.len() != 2 {
+ return Err(DataFusionError::Internal(format!(
+ "Array_append function requires two arguments, got {}",
+ args.len()
+ )));
+ }
+
+ let arr = match &args[0] {
+ ColumnarValue::Scalar(scalar) => scalar.to_array().clone(),
+ ColumnarValue::Array(arr) => arr.clone(),
+ };
+
+ let element = match &args[1] {
+ ColumnarValue::Scalar(scalar) => scalar.to_array().clone(),
Review Comment:
`ColumnarValue::Array` also makes sense in this situation?
--
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]