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/12 12:49:38 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2196: feat: Support ArrayIndex for ScalarValue(List)

alamb commented on code in PR #2196:
URL: https://github.com/apache/arrow-datafusion/pull/2196#discussion_r848396271


##########
datafusion/physical-expr/src/expressions/get_indexed_field.rs:
##########
@@ -105,9 +105,51 @@ impl PhysicalExpr for GetIndexedFieldExpr {
                 }
                 (dt, key) => Err(DataFusionError::NotImplemented(format!("get indexed field is only possible on lists with int64 indexes. Tried {} with {} index", dt, key))),
             },
-            ColumnarValue::Scalar(_) => Err(DataFusionError::NotImplemented(
-                "field access is not yet implemented for scalar values".to_string(),
-            )),
+            ColumnarValue::Scalar(scalar) => match (scalar.get_datatype(), &self.key) {
+                (DataType::List(v), ScalarValue::Int64(Some(i))) => {
+                    let wrapper = scalar.to_array();

Review Comment:
   I wonder if initially you might be able to use `ScalarValue::to_array_of_size` to convert the scalar argument into an `ArrayRef` and then use the same code as above:
   
   Another alternative might be to use the take kernel with something like
   
   Untested:
   
   ```rust
   ColumnarValue::Scalar(scalar) =>  {
     let indicies = self.key.to_array_of_size(array.len());
     let indicies = arrow::compute::cast(&indicies, DataType::Int32);
     let values = arrow::compute::take(indices, array)
   }
   ```
   
   Though I see the code above to handle non scalars is a bit more involved so perhaps `take` doesn't work -- though there is code for lists here: https://github.com/apache/arrow-rs/blob/master/arrow/src/compute/kernels/take.rs#L222-L228
   



-- 
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