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

[PR] Port ArrayHas family to `functions-array` [arrow-datafusion]

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

   ## 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.
   -->
   
   Part of #9285 
   
   ## 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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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

   Contains #9477 


-- 
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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   I filed https://github.com/apache/arrow-datafusion/issues/9519
   
   (it turns out that you can already define AnalyzerRules). I will make a PR to improve the documentation around this



-- 
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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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

   @guojidan I'm think of importing udfs with feature flag like this


-- 
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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   So it seems like ideally that users who want to supply their own implementations for `array_expressions` should also supply their own Analyzer passes.
   
   Following that logic, it seems like the `datafusion_array_functions` crate should supply its own analyzer pass that had array function specific rewrites. 
   
   Does that make sense  @jayzhan211  and @guojidan?
   
   If so,   I will file a ticket to track the request / work.  
   
   Note that since I don't think users can actually add their own Analyzer passes today, we can't implement this idea yet. Thus I think we can still merge this PR. 
   
   I also think it would help to explain this rationale in comments. For example
   
   ```suggestion
   // Note This rewrite is only done if the built in DataFusion `array_expressions` feature is enabled. 
   // Even if users  implement their own array functions, those functions are not equal to the DataFusion
   // udf based array functions, so this rewrite is not corrrect
   #[cfg(feature = "array_expressions")]
   ```



-- 
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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   This rule is disabled, but other analyzer rules are not. As long as `array_expressions ` is disabled, related function should be disabled too. Even there implement their own array functions, those functions are not equal to our udf based array functions, so it makes sense to me that the rewrite rule is disabled too.



##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   This rule is disabled, but other analyzer rules are not. As long as `array_expressions ` is disabled, related function should be disabled too. Even their implement their own array functions, those functions are not equal to our udf based array functions, so it makes sense to me that the rewrite rule is disabled 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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   This rule is disabled, but other analyzer rules are not. As long as `array_expressions ` is disabled, related function should be disabled 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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   > So it seems like ideally that users who want to supply their own implementations for `array_expressions` should also supply their own Analyzer passes.
   > 
   > Following that logic, it seems like the `datafusion_array_functions` crate should supply its own analyzer pass that had array function specific rewrites.
   > 
   > Does that make sense @jayzhan211 and @guojidan?
   > 
   > If so, I will file a ticket to track the request / work.
   > 
   > Note that since I don't think users can actually add their own Analyzer passes today, we can't implement this idea yet. Thus I think we can still merge this PR.
   > 
   > I also think it would help to explain this rationale in comments. For example
   
   I'm not sure if there are any concrete cases, but if they can have an analyzer that not only deals with `array_expressions` but also other expressions that would be more flexible.
   
   However, the first step is to build an user-defined analyzer rule and find a way to register them to existing rules.



-- 
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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   @guojidan I'm thinking of importing udfs with feature flag like this.



-- 
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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


-- 
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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   PR to improve documentation: https://github.com/apache/arrow-datafusion/pull/9520



-- 
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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   > So it seems like ideally that users who want to supply their own implementations for `array_expressions` should also supply their own Analyzer passes.
   > 
   > Following that logic, it seems like the `datafusion_array_functions` crate should supply its own analyzer pass that had array function specific rewrites.
   > 
   > Does that make sense @jayzhan211 and @guojidan?
   > 
   > If so, I will file a ticket to track the request / work.
   > 
   > Note that since I don't think users can actually add their own Analyzer passes today, we can't implement this idea yet. Thus I think we can still merge this PR.
   > 
   > I also think it would help to explain this rationale in comments. For example
   
   I'm not sure if there are any concrete cases, but if they can have an analyzer that not only deals with `array_expressions` but also other expressions that would be more flexible.
   
   However, the first step is to build a user-defined analyzer rule and find a way to register them to existing rules.



-- 
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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   This rule is disabled, but other analyzer rules are not. As long as `array_expressions ` is disabled, related function should be disabled too. Even they implement their own array functions, those functions are not equal to our udf based array functions, so it makes sense to me that the rewrite rule is disabled 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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   This rule is disabled, but other analyzer rules are not.



-- 
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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   if user disable `array_expressions` featrue, and implement array function by themselves, this analyzer will not be called 😕 



-- 
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] Port ArrayHas family to `functions-array` [arrow-datafusion]

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


##########
datafusion/optimizer/src/analyzer/rewrite_expr.rs:
##########
@@ -118,11 +118,59 @@ impl TreeNodeRewriter for OperatorToFunctionRewriter {
                     args: vec![left, right],
                 })));
             }
+
+            // TODO: change OperatorToFunction to OperatoToArrayFunction and configure it with array_expressions feature
+            // after other array functions are udf-based
+            #[cfg(feature = "array_expressions")]
+            if let Some(expr) = rewrite_array_has_all_operator_to_func(left, op, right) {
+                return Ok(Transformed::yes(expr));
+            }
         }
         Ok(Transformed::no(expr))
     }
 }
 
+#[cfg(feature = "array_expressions")]

Review Comment:
   This rule is disabled, but other analyzer rules are not. As long as `array_expressions ` is disabled, related function should be disabled too. Even they implement their own array functions, those functions are not equal to our udf based array functions, so it makes sense to me that the rewrite rule is disabled.



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