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/10 20:28:53 UTC

[GitHub] [arrow-datafusion] ovr opened a new pull request, #2196: feat: Support ArrayIndex for ScalarValue(List)

ovr opened a new pull request, #2196:
URL: https://github.com/apache/arrow-datafusion/pull/2196

   Hello!
   
   I've opened a PR as a Draft to indicate that I am working on the task of supporting the array index operator in DF. 
   This PR depends on:
   
   - https://github.com/apache/arrow-datafusion/pull/2194
   - https://github.com/apache/arrow-datafusion/pull/2195
   
   Thanks


-- 
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 #2196: feat: Support ArrayIndex for ScalarValue(List)

Posted by GitBox <gi...@apache.org>.
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


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

Posted by GitBox <gi...@apache.org>.
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~
   



-- 
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] ovr commented on pull request #2196: feat: Support GetIndexedFieldExpr for ScalarValue

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

   Rebased ✅ Changed to simplify/reuse logic across Scalar/ArrayRef. cC @alamb 


-- 
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] ovr commented on a diff in pull request #2196: feat: Support GetIndexedFieldExpr for ScalarValue

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


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -491,6 +491,16 @@ async fn test_crypto_expressions() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn test_array_index() -> Result<()> {
+    test_expression!("([5,4,3,2,1])[1]", "5");
+    test_expression!("([5,4,3,2,1])[5]", "1");
+    test_expression!("([5,4,3,2,1])[100]", "NULL");
+    test_expression!("([5,4,3,2,1])[-1]", "NULL");

Review Comment:
   Right now, it's not possible to define multi-dimension arrays via SQL.



-- 
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] ovr commented on a diff in pull request #2196: feat: Support GetIndexedFieldExpr for ScalarValue

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


##########
datafusion/physical-expr/src/expressions/get_indexed_field.rs:
##########
@@ -107,9 +136,69 @@ 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) {

Review Comment:
   Thanks, Done.



-- 
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 #2196: Support GetIndexedFieldExpr for ScalarValue

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


-- 
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] ovr commented on a diff in pull request #2196: feat: Support GetIndexedFieldExpr for ScalarValue

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


##########
datafusion/expr/src/field_util.rs:
##########
@@ -28,14 +28,7 @@ use datafusion_common::{DataFusionError, Result, ScalarValue};
 pub fn get_indexed_field(data_type: &DataType, key: &ScalarValue) -> Result<Field> {
     match (data_type, key) {
         (DataType::List(lt), ScalarValue::Int64(Some(i))) => {
-            if *i < 0 {
-                Err(DataFusionError::Plan(format!(
-                    "List based indexed access requires a positive int, was {0}",
-                    i
-                )))
-            } else {
-                Ok(Field::new(&i.to_string(), lt.data_type().clone(), false))
-            }
+            Ok(Field::new(&i.to_string(), lt.data_type().clone(), true))

Review Comment:
   I've removed the check for negative integers to be compatible with PostgreSQL.
   <img width="822" alt="image" src="https://user-images.githubusercontent.com/572096/171677500-8eaa9933-9b2b-48e4-b0c9-17a6f21e29e0.png">



##########
datafusion/expr/src/field_util.rs:
##########
@@ -28,14 +28,7 @@ use datafusion_common::{DataFusionError, Result, ScalarValue};
 pub fn get_indexed_field(data_type: &DataType, key: &ScalarValue) -> Result<Field> {
     match (data_type, key) {
         (DataType::List(lt), ScalarValue::Int64(Some(i))) => {
-            if *i < 0 {
-                Err(DataFusionError::Plan(format!(
-                    "List based indexed access requires a positive int, was {0}",
-                    i
-                )))
-            } else {
-                Ok(Field::new(&i.to_string(), lt.data_type().clone(), false))
-            }
+            Ok(Field::new(&i.to_string(), lt.data_type().clone(), true))

Review Comment:
   I've removed the check for negative integers to be compatible with PostgreSQL.
   
   <img width="822" alt="image" src="https://user-images.githubusercontent.com/572096/171677500-8eaa9933-9b2b-48e4-b0c9-17a6f21e29e0.png">



-- 
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] ovr commented on a diff in pull request #2196: feat: Support GetIndexedFieldExpr for ScalarValue

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


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -491,6 +491,16 @@ async fn test_crypto_expressions() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn test_array_index() -> Result<()> {
+    test_expression!("([5,4,3,2,1])[1]", "5");
+    test_expression!("([5,4,3,2,1])[5]", "1");
+    test_expression!("([5,4,3,2,1])[100]", "NULL");
+    test_expression!("([5,4,3,2,1])[-1]", "NULL");

Review Comment:
   Oh, Nope, I was wrong.



-- 
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] ovr commented on a diff in pull request #2196: feat: Support GetIndexedFieldExpr for ScalarValue

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


##########
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:
   @alamb Sorry for the ping, just a reminder that I am still waiting for advice on how to solve it. Thank you!



-- 
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] ovr commented on a diff in pull request #2196: feat: Support GetIndexedFieldExpr for ScalarValue

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


##########
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:
   @alamb Sorry for the ping, just a friendly reminder that I am still waiting for advice on how to solve it. Thank you!



-- 
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] ovr commented on a diff in pull request #2196: feat: Support ArrayIndex for ScalarValue(List)

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


##########
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:
   Should I implement a new method that will convert Vec<SQLExpr> (which ScalarValue holds) for List instead of using the current API and temporarily ArrayRef? For example: `as_array_list()`?
   
   Thanks
   
   cC @alamb 



-- 
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] ovr commented on a diff in pull request #2196: feat: Support GetIndexedFieldExpr for ScalarValue

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


##########
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:
   `to_array` uses `to_array_of_size` under the hood, but I cannot reuse the code above, because it returns an `ColumnarValue::Array`, but in the case with `ColumnarValue::Scalar` we need to return `ColumnarValue::Scalar`.
   
   I did another draft in https://github.com/apache/arrow-datafusion/pull/2196/commits/af8c77fcb947137a3d173ead288a2d7067c1be7d WDYT?
   
   Thanks



-- 
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] ovr commented on a diff in pull request #2196: feat: Support GetIndexedFieldExpr for ScalarValue

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


##########
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:
   `to_array` uses `to_array_of_size` under the hood, but I cannot use the code above, because it returns an `ColumnarValue::Array`, but in the case with `ColumnarValue::Scalar` we need to return `ColumnarValue::Scalar`.
   
   I did another draft in https://github.com/apache/arrow-datafusion/pull/2196/commits/af8c77fcb947137a3d173ead288a2d7067c1be7d WDYT?
   
   Thanks



-- 
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 #2196: feat: Support GetIndexedFieldExpr for ScalarValue

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


##########
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:
   sorry @ovr  -- taking a look



-- 
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 #2196: feat: Support GetIndexedFieldExpr for ScalarValue

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


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -491,6 +491,16 @@ async fn test_crypto_expressions() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn test_array_index() -> Result<()> {
+    test_expression!("([5,4,3,2,1])[1]", "5");

Review Comment:
   https://www.postgresql.org/docs/current/arrays.html
   
   I verified that the subscripts are 1 based 👍 
   
   > The array subscript numbers are written within square brackets. By default PostgreSQL uses a one-based numbering convention for arrays, that is, an array of n elements starts with array[1] and ends with array[n].
   
   
   
   
   



##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -491,6 +491,16 @@ async fn test_crypto_expressions() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn test_array_index() -> Result<()> {
+    test_expression!("([5,4,3,2,1])[1]", "5");
+    test_expression!("([5,4,3,2,1])[5]", "1");
+    test_expression!("([5,4,3,2,1])[100]", "NULL");
+    test_expression!("([5,4,3,2,1])[-1]", "NULL");

Review Comment:
   I wonder if you want to potentially try nested lists. Something like
   
   ```suggestion
       test_expression!("([5,4,3,2,1])[-1]", "NULL");
       test_expression!("([[123],[4,5,6]])[2]", "[4,5,6]");
   ```



##########
datafusion/physical-expr/src/expressions/get_indexed_field.rs:
##########
@@ -107,9 +136,69 @@ 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) {

Review Comment:
   I am not sure I fully follow this code -- Since it is creating a `ArrayRef` from the `ColumnarValue::Scalar`, I wonder why it can't use the same code as the `ColumnarValue::Array` case and call `to_arrow()`?
   
   https://github.com/cube-js/arrow-datafusion/blob/scalar-array-index/ballista/rust/client/src/columnar_batch.rs#L150
   
   So for example, rather than 
   
   ```rust
       fn evaluate(&self, batch: &RecordBatch) -> Result<ColumnarValue> {
           let arg = self.arg.evaluate(batch)?;
           match arg {
               ColumnarValue::Array(array) => match (array.data_type(), &self.key) {
   ...
   ```
   
   It could look like:
   ```rust
       fn evaluate(&self, batch: &RecordBatch) -> Result<ColumnarValue> {
           let array = self.arg.evaluate(batch)?
             // convert to Arrayref
             .to_arrow();
   
           match (array.data_type(), &self.key) {
   ...
   ```
   
   That way the same code would be used for the array and scalar cases of `ColumnarValue`



-- 
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] ovr commented on a diff in pull request #2196: feat: Support GetIndexedFieldExpr for ScalarValue

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


##########
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:
   `to_array` uses `to_array_of_size` under the hood, but I cannot use the code above, because it returns an `ColumnarValue::Array`, but in the case with `ColumnarValue::Scalar` we need to return `ColumnarValue::Scalar`.
   
   I did another draft in https://github.com/apache/arrow-datafusion/pull/2196/commits/af8c77fcb947137a3d173ead288a2d7067c1be7d WDT?
   
   Thanks



-- 
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] andygrove commented on pull request #2196: Support GetIndexedFieldExpr for ScalarValue

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

   I'll go ahead and merge this later today unless @alamb has any additional feedback


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