You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "RTEnzyme (via GitHub)" <gi...@apache.org> on 2023/04/07 02:31:57 UTC

[GitHub] [arrow-datafusion] RTEnzyme opened a new pull request, #5902: feat: Implement the bitwise_not in NotExpr

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

   # 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 #5700. Because the SQL dialect use `Generic`, sqlparser can't parse operator `~` as unary Bitwise_not. But we can use `not` to complement integer instead of operator `~` in SQL.
   
   # 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.
   -->
   Extending Expr::Not to work with integral types so that it can evaluate Bitwise_not expression.
   
   # 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)?
   -->
   Pass Integrated tests.
   
   Add United tests for bitwise_not integral types.
   
   # Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   Yes.  The `not` can NOT boolean type and Bitwise_not integer in sql.
   
   <!--
   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


[GitHub] [arrow-datafusion] RTEnzyme commented on a diff in pull request #5902: feat: Implement the bitwise_not in NotExpr

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


##########
datafusion/physical-expr/src/expressions/not.rs:
##########
@@ -59,8 +63,25 @@ impl PhysicalExpr for NotExpr {
         self
     }
 
-    fn data_type(&self, _input_schema: &Schema) -> Result<DataType> {
-        Ok(DataType::Boolean)
+    fn data_type(&self, input_schema: &Schema) -> Result<DataType> {
+        // Ok(DataType::Boolean)
+        let data_type = self.arg.data_type(input_schema)?;

Review Comment:
   As @alamb [suggestion](https://github.com/apache/arrow-datafusion/issues/5700#issuecomment-1481132344), I embed bitwise_not into NotExpr. But I agree that this way will break `NotExpr` original struct.  I think I should further discuss the implementation in the issue #5700



-- 
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 #5902: feat: Implement the bitwise_not in NotExpr

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


-- 
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 #5902: feat: Implement the bitwise_not in NotExpr

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


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -622,6 +622,17 @@ async fn test_not_expressions() -> Result<()> {
     ];
     assert_batches_eq!(expected, &actual);
 
+    let sql = "SELECT not(1), not(0)";
+    let actual = execute_to_batches(&ctx, sql).await;

Review Comment:
   Follow on PR to port the tests: https://github.com/apache/arrow-datafusion/pull/5968



-- 
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] comphead commented on a diff in pull request #5902: feat: Implement the bitwise_not in NotExpr

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


##########
datafusion/physical-expr/src/expressions/not.rs:
##########
@@ -59,8 +63,25 @@ impl PhysicalExpr for NotExpr {
         self
     }
 
-    fn data_type(&self, _input_schema: &Schema) -> Result<DataType> {
-        Ok(DataType::Boolean)
+    fn data_type(&self, input_schema: &Schema) -> Result<DataType> {
+        // Ok(DataType::Boolean)
+        let data_type = self.arg.data_type(input_schema)?;

Review Comment:
   ok, sounds good



-- 
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 pull request #5902: feat: Implement the bitwise_not in NotExpr

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

   Thanks again @RTEnzyme and @comphead 


-- 
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 #5902: feat: Implement the bitwise_not in NotExpr

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


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -622,6 +622,17 @@ async fn test_not_expressions() -> Result<()> {
     ];
     assert_batches_eq!(expected, &actual);
 
+    let sql = "SELECT not(1), not(0)";
+    let actual = execute_to_batches(&ctx, sql).await;

Review Comment:
   I agree it would be nice to move to https://github.com/apache/arrow-datafusion/blob/main/datafusion/core/tests/sqllogictests/test_files/scalar.slt but we can do that potentially as a follow on PR



-- 
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] comphead commented on a diff in pull request #5902: feat: Implement the bitwise_not in NotExpr

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


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -622,6 +622,17 @@ async fn test_not_expressions() -> Result<()> {
     ];
     assert_batches_eq!(expected, &actual);
 
+    let sql = "SELECT not(1), not(0)";
+    let actual = execute_to_batches(&ctx, sql).await;

Review Comment:
   maybe lets move it to `scalar.slt` sqllogic test?



##########
datafusion/physical-expr/src/expressions/not.rs:
##########
@@ -59,8 +63,25 @@ impl PhysicalExpr for NotExpr {
         self
     }
 
-    fn data_type(&self, _input_schema: &Schema) -> Result<DataType> {
-        Ok(DataType::Boolean)
+    fn data_type(&self, input_schema: &Schema) -> Result<DataType> {
+        // Ok(DataType::Boolean)
+        let data_type = self.arg.data_type(input_schema)?;

Review Comment:
   That looks breaking imho... I would propose to have the own `BitwiseNotExpr` instead of making `NotExpr` universal



-- 
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 #5902: feat: Implement the bitwise_not in NotExpr

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


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -622,6 +622,17 @@ async fn test_not_expressions() -> Result<()> {
     ];
     assert_batches_eq!(expected, &actual);
 
+    let sql = "SELECT not(1), not(0)";
+    let actual = execute_to_batches(&ctx, sql).await;

Review Comment:
   I will port some tests over



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