You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "yyy1000 (via GitHub)" <gi...@apache.org> on 2024/03/11 23:46:04 UTC

[PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

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

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #9532 .
   
   ## 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 these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## 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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522299523


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -137,6 +136,19 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
         }) = expr
         {
             match field {
+                GetFieldAccess::NamedStructField { name, .. } => {
+                    let expr = *expr.clone();
+                    let name = name.clone();
+                    let args = vec![expr, Expr::Literal(name)];
+                    return Ok(Transformed::yes(Expr::ScalarFunction(
+                        ScalarFunction::new_udf(
+                            Arc::new(ScalarUDF::new_from_impl(
+                                datafusion_functions::core::getfield::GetFieldFunc::new(),
+                            )),
+                            args,
+                        ),
+                    )));
+                }

Review Comment:
   I think we could implement this rewrite more easily using the API proposed in https://github.com/apache/arrow-datafusion/pull/9583 (so you could use datafusion_functions directly)



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522276234


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -137,6 +136,19 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
         }) = expr
         {
             match field {
+                GetFieldAccess::NamedStructField { name, .. } => {
+                    let expr = *expr.clone();
+                    let name = name.clone();
+                    let args = vec![expr, Expr::Literal(name)];
+                    return Ok(Transformed::yes(Expr::ScalarFunction(
+                        ScalarFunction::new_udf(
+                            Arc::new(ScalarUDF::new_from_impl(
+                                datafusion_functions::core::getfield::GetFieldFunc::new(),
+                            )),
+                            args,
+                        ),
+                    )));
+                }

Review Comment:
   only *sql crate* can get it directly, or any other crate that has `context`



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


Re: [PR] Remove physical expr of NamedStructField, convert to get_field function [arrow-datafusion]

Posted by "yyy1000 (via GitHub)" <gi...@apache.org>.
yyy1000 commented on PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#issuecomment-1994941409

   Hi @alamb 
   I applied the feature and it looks good.
   Could you review it again when you are available?


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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522288522


##########
datafusion/functions/src/core/getfield.rs:
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow::datatypes::DataType;
+use arrow_array::{Scalar, StringArray};
+use datafusion_common::cast::{as_map_array, as_struct_array};
+use datafusion_common::{exec_err, ExprSchema, Result, ScalarValue};
+use datafusion_expr::field_util::GetFieldAccessSchema;
+use datafusion_expr::{ColumnarValue, Expr, ExprSchemable};
+use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
+use std::any::Any;
+
+#[derive(Debug)]
+pub struct GetFieldFunc {
+    signature: Signature,
+}
+
+impl GetFieldFunc {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::any(2, Volatility::Immutable),

Review Comment:
   > it seems the signature should be `array` and `utf8`
   
   I think we can have `Any` and `utf8` for now. We don't have signature for struct, `array` is not for struct too



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "yyy1000 (via GitHub)" <gi...@apache.org>.
yyy1000 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522324581


##########
datafusion/optimizer/Cargo.toml:
##########
@@ -45,6 +45,7 @@ async-trait = { workspace = true }
 chrono = { workspace = true }
 datafusion-common = { workspace = true, default-features = true }
 datafusion-expr = { workspace = true }
+datafusion-functions = { workspace = true }

Review Comment:
   Cool, I can wait on it and use that function.



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522276234


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -137,6 +136,19 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
         }) = expr
         {
             match field {
+                GetFieldAccess::NamedStructField { name, .. } => {
+                    let expr = *expr.clone();
+                    let name = name.clone();
+                    let args = vec![expr, Expr::Literal(name)];
+                    return Ok(Transformed::yes(Expr::ScalarFunction(
+                        ScalarFunction::new_udf(
+                            Arc::new(ScalarUDF::new_from_impl(
+                                datafusion_functions::core::getfield::GetFieldFunc::new(),
+                            )),
+                            args,
+                        ),
+                    )));
+                }

Review Comment:
   only sql crate can get it directly, or any other crate that has context



##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -137,6 +136,19 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
         }) = expr
         {
             match field {
+                GetFieldAccess::NamedStructField { name, .. } => {
+                    let expr = *expr.clone();
+                    let name = name.clone();
+                    let args = vec![expr, Expr::Literal(name)];
+                    return Ok(Transformed::yes(Expr::ScalarFunction(
+                        ScalarFunction::new_udf(
+                            Arc::new(ScalarUDF::new_from_impl(
+                                datafusion_functions::core::getfield::GetFieldFunc::new(),
+                            )),
+                            args,
+                        ),
+                    )));
+                }

Review Comment:
   only sql crate can get it directly, or any other crate that has `context`



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522336881


##########
datafusion/functions/src/core/getfield.rs:
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow::datatypes::DataType;
+use arrow_array::{Scalar, StringArray};
+use datafusion_common::cast::{as_map_array, as_struct_array};
+use datafusion_common::{exec_err, ExprSchema, Result, ScalarValue};
+use datafusion_expr::field_util::GetFieldAccessSchema;
+use datafusion_expr::{ColumnarValue, Expr, ExprSchemable};
+use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
+use std::any::Any;
+
+#[derive(Debug)]
+pub struct GetFieldFunc {
+    signature: Signature,
+}
+
+impl GetFieldFunc {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::any(2, Volatility::Immutable),

Review Comment:
   I think we should keep it as any(2) for now. I forgot that it is better to introduce signature only if we need type coercion.



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


Re: [PR] Remove physical expr of NamedStructField, convert to get_field function [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#issuecomment-1994649122

   Hi @yyy1000  -- I have merged https://github.com/apache/arrow-datafusion/pull/9583 -- is there any chance you can rebase this PR and try to use that feature here?


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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522280620


##########
datafusion/functions/src/core/getfield.rs:
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow::datatypes::DataType;
+use arrow_array::{Scalar, StringArray};
+use datafusion_common::cast::{as_map_array, as_struct_array};
+use datafusion_common::{exec_err, ExprSchema, Result, ScalarValue};
+use datafusion_expr::field_util::GetFieldAccessSchema;
+use datafusion_expr::{ColumnarValue, Expr, ExprSchemable};
+use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
+use std::any::Any;
+
+#[derive(Debug)]
+pub struct GetFieldFunc {
+    signature: Signature,
+}
+
+impl GetFieldFunc {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::any(2, Volatility::Immutable),
+        }
+    }
+}
+impl Default for GetFieldFunc {
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
+// get_field(struct_array, field_name)
+impl ScalarUDFImpl for GetFieldFunc {
+    fn as_any(&self) -> &dyn Any {
+        self
+    }
+    fn name(&self) -> &str {
+        "get_field"
+    }
+
+    fn signature(&self) -> &Signature {
+        &self.signature
+    }
+
+    fn return_type(&self, _: &[DataType]) -> Result<DataType> {
+        todo!()
+    }
+
+    fn return_type_from_exprs(
+        &self,
+        args: &[Expr],
+        schema: &dyn ExprSchema,
+        _arg_types: &[DataType],
+    ) -> Result<DataType> {
+        if args.len() != 2 {
+            return exec_err!(
+                "get_field function requires 2 arguments, got {}",
+                args.len()
+            );
+        }
+
+        let name = match &args[1] {
+            Expr::Literal(name) => name,
+            _ => {
+                return exec_err!(
+                    "get_field function requires the argument field_name to be a string"
+                );
+            }
+        };
+        let access_schema = GetFieldAccessSchema::NamedStructField { name: name.clone() };
+        let arg_dt = args[0].get_type(schema)?;
+        access_schema
+            .get_accessed_field(&arg_dt)
+            .map(|f| f.data_type().clone())
+    }
+
+    fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
+        if args.len() != 2 {
+            return exec_err!(
+                "get_field function requires 2 arguments, got {}",
+                args.len()
+            );
+        }
+
+        let arr;
+        let array = match &args[0] {

Review Comment:
   maybe try `values_to_arrays`?



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522288522


##########
datafusion/functions/src/core/getfield.rs:
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow::datatypes::DataType;
+use arrow_array::{Scalar, StringArray};
+use datafusion_common::cast::{as_map_array, as_struct_array};
+use datafusion_common::{exec_err, ExprSchema, Result, ScalarValue};
+use datafusion_expr::field_util::GetFieldAccessSchema;
+use datafusion_expr::{ColumnarValue, Expr, ExprSchemable};
+use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
+use std::any::Any;
+
+#[derive(Debug)]
+pub struct GetFieldFunc {
+    signature: Signature,
+}
+
+impl GetFieldFunc {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::any(2, Volatility::Immutable),

Review Comment:
   > it seems the signature should be `array` and `utf8`
   
   I think we can have `Any` and `utf8` for now. We don't have signature for struct, `array` is not for struct too



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522284957


##########
datafusion/functions/src/core/getfield.rs:
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow::datatypes::DataType;
+use arrow_array::{Scalar, StringArray};
+use datafusion_common::cast::{as_map_array, as_struct_array};
+use datafusion_common::{exec_err, ExprSchema, Result, ScalarValue};
+use datafusion_expr::field_util::GetFieldAccessSchema;
+use datafusion_expr::{ColumnarValue, Expr, ExprSchemable};
+use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
+use std::any::Any;
+
+#[derive(Debug)]
+pub struct GetFieldFunc {
+    signature: Signature,
+}
+
+impl GetFieldFunc {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::any(2, Volatility::Immutable),

Review Comment:
   it seems the signature should be `struct` and `utf8`. But, we can set it to `Any` and `utf8` for now.



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "yyy1000 (via GitHub)" <gi...@apache.org>.
yyy1000 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1521752381


##########
datafusion/functions/src/core/struct.rs:
##########
@@ -73,12 +73,6 @@ impl StructFunc {
     }
 }
 
-impl Default for StructFunc {
-    fn default() -> Self {
-        Self::new()
-    }
-}
-
 impl ScalarUDFImpl for StructFunc {

Review Comment:
   Last PR I make StructFunc pub so I add the Default trait, but since https://github.com/apache/arrow-datafusion/pull/9546#discussion_r1519548725 it will not be needed.



##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -137,6 +136,19 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
         }) = expr
         {
             match field {
+                GetFieldAccess::NamedStructField { name, .. } => {
+                    let expr = *expr.clone();
+                    let name = name.clone();
+                    let args = vec![expr, Expr::Literal(name)];
+                    return Ok(Transformed::yes(Expr::ScalarFunction(
+                        ScalarFunction::new_udf(
+                            Arc::new(ScalarUDF::new_from_impl(
+                                datafusion_functions::core::getfield::GetFieldFunc::new(),
+                            )),
+                            args,
+                        ),
+                    )));
+                }

Review Comment:
   I know the method from https://github.com/apache/arrow-datafusion/pull/9546#discussion_r1519548725, but it seems that here it can't get the `context_provider`?



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522276234


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -137,6 +136,19 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
         }) = expr
         {
             match field {
+                GetFieldAccess::NamedStructField { name, .. } => {
+                    let expr = *expr.clone();
+                    let name = name.clone();
+                    let args = vec![expr, Expr::Literal(name)];
+                    return Ok(Transformed::yes(Expr::ScalarFunction(
+                        ScalarFunction::new_udf(
+                            Arc::new(ScalarUDF::new_from_impl(
+                                datafusion_functions::core::getfield::GetFieldFunc::new(),
+                            )),
+                            args,
+                        ),
+                    )));
+                }

Review Comment:
   only sql crate can get it directly



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


Re: [PR] Remove physical expr of NamedStructField, convert to get_field function [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1523680099


##########
datafusion/core/src/physical_planner.rs:
##########
@@ -222,12 +225,10 @@ fn create_physical_name(e: &Expr, is_first_expr: bool) -> Result<String> {
                     stride: _,
                 } => {
                     unreachable!(
-                        "ListIndex should have been rewritten in OperatorToFunction"
+                        "ListRange should have been rewritten in OperatorToFunction"

Review Comment:
   👍 



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "yyy1000 (via GitHub)" <gi...@apache.org>.
yyy1000 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522323705


##########
datafusion/functions/src/core/getfield.rs:
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow::datatypes::DataType;
+use arrow_array::{Scalar, StringArray};
+use datafusion_common::cast::{as_map_array, as_struct_array};
+use datafusion_common::{exec_err, ExprSchema, Result, ScalarValue};
+use datafusion_expr::field_util::GetFieldAccessSchema;
+use datafusion_expr::{ColumnarValue, Expr, ExprSchemable};
+use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
+use std::any::Any;
+
+#[derive(Debug)]
+pub struct GetFieldFunc {
+    signature: Signature,
+}
+
+impl GetFieldFunc {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::any(2, Volatility::Immutable),

Review Comment:
   I think it can also be `map` and `utf8`.
   A question for me is how to specify the Any as the param in Signature? 
   I tried `Signature::exact(vec![Any, DataType::Utf8], Volatility::Immutable)` but it said 
   
   > expected value, found trait `Any` not a value



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522301014


##########
datafusion/optimizer/Cargo.toml:
##########
@@ -45,6 +45,7 @@ async-trait = { workspace = true }
 chrono = { workspace = true }
 datafusion-common = { workspace = true, default-features = true }
 datafusion-expr = { workspace = true }
+datafusion-functions = { workspace = true }

Review Comment:
   I think it is very important to not add this dependency -- we are triyng to make the core not know about the functions
   
   I think https://github.com/apache/arrow-datafusion/pull/9583 will let us avoid it



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "yyy1000 (via GitHub)" <gi...@apache.org>.
yyy1000 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522323705


##########
datafusion/functions/src/core/getfield.rs:
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow::datatypes::DataType;
+use arrow_array::{Scalar, StringArray};
+use datafusion_common::cast::{as_map_array, as_struct_array};
+use datafusion_common::{exec_err, ExprSchema, Result, ScalarValue};
+use datafusion_expr::field_util::GetFieldAccessSchema;
+use datafusion_expr::{ColumnarValue, Expr, ExprSchemable};
+use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
+use std::any::Any;
+
+#[derive(Debug)]
+pub struct GetFieldFunc {
+    signature: Signature,
+}
+
+impl GetFieldFunc {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::any(2, Volatility::Immutable),

Review Comment:
   I think it can also be `Map` and `utf8`.
   A question for me is how to specify the Any as the param in Signature? 
   I tried `Signature::exact(vec![Any, DataType::Utf8], Volatility::Immutable)` but it said 
   
   > expected value, found trait `Any` not a value



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


Re: [PR] Remove physical expr of NamedStructField, convert to `get_field` function call [arrow-datafusion]

Posted by "yyy1000 (via GitHub)" <gi...@apache.org>.
yyy1000 commented on PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#issuecomment-1995254576

   Thank you @alamb @jayzhan211 for your reviews and guidance! 


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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522288522


##########
datafusion/functions/src/core/getfield.rs:
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow::datatypes::DataType;
+use arrow_array::{Scalar, StringArray};
+use datafusion_common::cast::{as_map_array, as_struct_array};
+use datafusion_common::{exec_err, ExprSchema, Result, ScalarValue};
+use datafusion_expr::field_util::GetFieldAccessSchema;
+use datafusion_expr::{ColumnarValue, Expr, ExprSchemable};
+use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
+use std::any::Any;
+
+#[derive(Debug)]
+pub struct GetFieldFunc {
+    signature: Signature,
+}
+
+impl GetFieldFunc {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::any(2, Volatility::Immutable),

Review Comment:
   > it seems the signature should be `array` and `utf8`
   
   I think we can have `Any` and `utf8` for now. We don't have signature for struct



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522284957


##########
datafusion/functions/src/core/getfield.rs:
##########
@@ -0,0 +1,139 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow::datatypes::DataType;
+use arrow_array::{Scalar, StringArray};
+use datafusion_common::cast::{as_map_array, as_struct_array};
+use datafusion_common::{exec_err, ExprSchema, Result, ScalarValue};
+use datafusion_expr::field_util::GetFieldAccessSchema;
+use datafusion_expr::{ColumnarValue, Expr, ExprSchemable};
+use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};
+use std::any::Any;
+
+#[derive(Debug)]
+pub struct GetFieldFunc {
+    signature: Signature,
+}
+
+impl GetFieldFunc {
+    pub fn new() -> Self {
+        Self {
+            signature: Signature::any(2, Volatility::Immutable),

Review Comment:
   it seems the signature should be `array` and `utf8`



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


Re: [PR] Remove physical expr of NamedStructField, convert to struct function [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#discussion_r1522301014


##########
datafusion/optimizer/Cargo.toml:
##########
@@ -45,6 +45,7 @@ async-trait = { workspace = true }
 chrono = { workspace = true }
 datafusion-common = { workspace = true, default-features = true }
 datafusion-expr = { workspace = true }
+datafusion-functions = { workspace = true }

Review Comment:
   I think it is very important to not add this dependency -- we are triyng to make the core not know about the functions



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


Re: [PR] Remove physical expr of NamedStructField, convert to get_field function [arrow-datafusion]

Posted by "yyy1000 (via GitHub)" <gi...@apache.org>.
yyy1000 commented on PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563#issuecomment-1994670610

   > Hi @yyy1000 -- I have merged #9583 -- is there any chance you can rebase this PR and try to use that feature here?
   
   Yeah, I will try to use this feature now. 


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


Re: [PR] Remove physical expr of NamedStructField, convert to `get_field` function call [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #9563:
URL: https://github.com/apache/arrow-datafusion/pull/9563


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