You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/25 09:16:09 UTC

[GitHub] [arrow-datafusion] Ted-Jiang opened a new pull request, #2332: Support scalar values for func Array

Ted-Jiang opened a new pull request, #2332:
URL: https://github.com/apache/arrow-datafusion/pull/2332

   # Which issue does this PR close?
    
   Closes #2331.
   
   Now 
   ```
   DataFusion CLI v7.0.0
   ❯
   SELECT array(1, 2, 3);
   +-----------------------------------+
   | array(Int64(1),Int64(2),Int64(3)) |
   +-----------------------------------+
   | [1, 2, 3]                         |
   +-----------------------------------+
   1 row in set. Query took 0.005 seconds.
   ❯
   ```
   
    # Rationale for this change
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on pull request #2332: Support scalar values for func Array

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2332:
URL: https://github.com/apache/arrow-datafusion/pull/2332#issuecomment-1108552454

   ❤️ 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2332: Support scalar values for func Array

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2332:
URL: https://github.com/apache/arrow-datafusion/pull/2332#discussion_r857517340


##########
datafusion/common/src/scalar.rs:
##########
@@ -1391,6 +1391,29 @@ impl ScalarValue {
                 }
                 Self::Struct(Some(Box::new(field_values)), Box::new(fields.clone()))
             }
+            DataType::FixedSizeList(nested_type, _len) => {
+                let list_array = array
+                    .as_any()
+                    .downcast_ref::<FixedSizeListArray>()
+                    .ok_or_else(|| {
+                        DataFusionError::Internal(
+                            "Failed to downcast FixedSizeListArray".to_string(),
+                        )
+                    })?;

Review Comment:
   This is fine -- I also think it is fine to panic in this case where the data type didn't match the array type as this is not an error condition DataFusion is expected to handle in the normal case:
   
   ```suggestion
                       .unwrap();
   ```
   



##########
datafusion/physical-expr/src/array_expressions.rs:
##########
@@ -90,18 +90,12 @@ fn array_array(args: &[&dyn Array]) -> Result<ArrayRef> {
 
 /// put values in an array.
 pub fn array(values: &[ColumnarValue]) -> Result<ColumnarValue> {
-    let arrays: Vec<&dyn Array> = values
-        .iter()
-        .map(|value| {
-            if let ColumnarValue::Array(value) = value {
-                Ok(value.as_ref())
-            } else {
-                Err(DataFusionError::NotImplemented(
-                    "Array is not implemented for scalar values.".to_string(),
-                ))
-            }
-        })
-        .collect::<Result<_>>()?;
-
-    Ok(ColumnarValue::Array(array_array(&arrays)?))
+    let mut arrays: Vec<ArrayRef> = vec![];
+    for x in values {
+        match x {
+            ColumnarValue::Array(array) => arrays.push(array.clone()),
+            ColumnarValue::Scalar(scalar) => arrays.push(scalar.to_array().clone()),
+        }
+    }

Review Comment:
   If you wanted to write this slightly more idomatically it could be
   
   ```suggestion
       let arrays: Vec<ArrayRef> = values.iter().map(|x| {
           match x {
               ColumnarValue::Array(array) => array.clone(),
               ColumnarValue::Scalar(scalar) => scalar.to_array().clone(),
           })
           .collect()
       }
   ```
   
   However, I don't think it makes any practical difference



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on pull request #2332: Support scalar values for func Array

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #2332:
URL: https://github.com/apache/arrow-datafusion/pull/2332#issuecomment-1108552635

   Thanks again @Ted-Jiang 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb merged pull request #2332: Support scalar values for func Array

Posted by GitBox <gi...@apache.org>.
alamb merged PR #2332:
URL: https://github.com/apache/arrow-datafusion/pull/2332


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org