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/23 22:11:05 UTC

[PR] Add Expr->String for ScalarFunction and InList [arrow-datafusion]

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

   ## 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.
   -->
   
   Related #9726.
   
   ## 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] Add Expr->String for ScalarFunction and InList [arrow-datafusion]

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


-- 
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] Add Expr->String for ScalarFunction and InList [arrow-datafusion]

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


##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -561,6 +636,31 @@ mod tests {
                 }),
                 r#"CAST("a" AS INTEGER UNSIGNED)"#,
             ),
+            (
+                Expr::InList(InList {
+                    expr: Box::new(col("a")),
+                    list: vec![lit(1), lit(2), lit(3)],
+                    negated: false,
+                }),
+                r#""a" IN (1, 2, 3)"#,
+            ),
+            (
+                Expr::InList(InList {
+                    expr: Box::new(col("a")),
+                    list: vec![lit(1), lit(2), lit(3)],
+                    negated: true,
+                }),
+                r#""a" NOT IN (1, 2, 3)"#,
+            ),
+            (
+                Expr::ScalarFunction(ScalarFunction {
+                    func_def: ScalarFunctionDefinition::UDF(Arc::new(
+                        ScalarUDF::new_from_impl(DummyUDF::new()),
+                    )),
+                    args: vec![col("a"), col("b")],
+                }),

Review Comment:
   Love this, more concise!



##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -561,6 +636,31 @@ mod tests {
                 }),
                 r#"CAST("a" AS INTEGER UNSIGNED)"#,
             ),
+            (
+                Expr::InList(InList {

Review Comment:
   That's very cool!



-- 
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] Add Expr->String for ScalarFunction and InList [arrow-datafusion]

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


##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -561,6 +636,31 @@ mod tests {
                 }),
                 r#"CAST("a" AS INTEGER UNSIGNED)"#,
             ),
+            (
+                Expr::InList(InList {
+                    expr: Box::new(col("a")),
+                    list: vec![lit(1), lit(2), lit(3)],
+                    negated: false,
+                }),
+                r#""a" IN (1, 2, 3)"#,
+            ),
+            (
+                Expr::InList(InList {
+                    expr: Box::new(col("a")),
+                    list: vec![lit(1), lit(2), lit(3)],
+                    negated: true,
+                }),
+                r#""a" NOT IN (1, 2, 3)"#,
+            ),
+            (
+                Expr::ScalarFunction(ScalarFunction {
+                    func_def: ScalarFunctionDefinition::UDF(Arc::new(
+                        ScalarUDF::new_from_impl(DummyUDF::new()),
+                    )),
+                    args: vec![col("a"), col("b")],
+                }),
+                r#"dummy_udf("a", "b")"#,
+            ),

Review Comment:
   I think for `ScalarFunction`, it's better to add test cases for `UDF` and `BuiltIn`.
   But since the function port work is going to be finished, I doubt whether it's necessary to do that. :)



-- 
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] Add Expr->String for ScalarFunction and InList [arrow-datafusion]

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


##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -561,6 +636,31 @@ mod tests {
                 }),
                 r#"CAST("a" AS INTEGER UNSIGNED)"#,
             ),
+            (
+                Expr::InList(InList {

Review Comment:
   I think you can write this more concisely with the expr API -- https://docs.rs/datafusion/latest/datafusion/logical_expr/enum.Expr.html#method.in_list
   
   Something like
   ```rust
   col("a").in(vec![lit(1), lit(2), lit(3)])
   ```
   
   Likewise for NOT IN
   
   ```rust
   col("a").not_in(vec![lit(1), lit(2), lit(3)])
   ```
   
   



##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -561,6 +636,31 @@ mod tests {
                 }),
                 r#"CAST("a" AS INTEGER UNSIGNED)"#,
             ),
+            (
+                Expr::InList(InList {
+                    expr: Box::new(col("a")),
+                    list: vec![lit(1), lit(2), lit(3)],
+                    negated: false,
+                }),
+                r#""a" IN (1, 2, 3)"#,
+            ),
+            (
+                Expr::InList(InList {
+                    expr: Box::new(col("a")),
+                    list: vec![lit(1), lit(2), lit(3)],
+                    negated: true,
+                }),
+                r#""a" NOT IN (1, 2, 3)"#,
+            ),
+            (
+                Expr::ScalarFunction(ScalarFunction {
+                    func_def: ScalarFunctionDefinition::UDF(Arc::new(
+                        ScalarUDF::new_from_impl(DummyUDF::new()),
+                    )),
+                    args: vec![col("a"), col("b")],
+                }),
+                r#"dummy_udf("a", "b")"#,
+            ),

Review Comment:
   Since there is no code specific to `BuiltInScalarFunction` in the unparser code, I agree there is no reason to add a specific test here 



##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -561,6 +636,31 @@ mod tests {
                 }),
                 r#"CAST("a" AS INTEGER UNSIGNED)"#,
             ),
+            (
+                Expr::InList(InList {
+                    expr: Box::new(col("a")),
+                    list: vec![lit(1), lit(2), lit(3)],
+                    negated: false,
+                }),
+                r#""a" IN (1, 2, 3)"#,
+            ),
+            (
+                Expr::InList(InList {
+                    expr: Box::new(col("a")),
+                    list: vec![lit(1), lit(2), lit(3)],
+                    negated: true,
+                }),
+                r#""a" NOT IN (1, 2, 3)"#,
+            ),
+            (
+                Expr::ScalarFunction(ScalarFunction {
+                    func_def: ScalarFunctionDefinition::UDF(Arc::new(
+                        ScalarUDF::new_from_impl(DummyUDF::new()),
+                    )),
+                    args: vec![col("a"), col("b")],
+                }),

Review Comment:
   How about using the call API https://docs.rs/datafusion/latest/datafusion/logical_expr/struct.ScalarUDF.html#method.call
   
   ```rust
   ScalarUDF::new_from_impl(DummyUDF::new())
    .call(vec![col("a"), col("b")])
   ```



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