You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jackwener (via GitHub)" <gi...@apache.org> on 2023/06/08 05:33:22 UTC

[GitHub] [arrow-datafusion] jackwener opened a new pull request, #6595: expression return wrong expression

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

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


[GitHub] [arrow-datafusion] jackwener commented on pull request #6595: fix: from_plan shouldn't use original schema

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

   I prepare to merge this PR in tomorrow. I will continue doing more job.


-- 
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] jackwener commented on a diff in pull request #6595: fix: simplify expression sometimes need to convert type.

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


##########
datafusion/expr/src/utils.rs:
##########
@@ -730,13 +730,10 @@ pub fn from_plan(
     inputs: &[LogicalPlan],
 ) -> Result<LogicalPlan> {
     match plan {
-        LogicalPlan::Projection(Projection { schema, .. }) => {
-            Ok(LogicalPlan::Projection(Projection::try_new_with_schema(
-                expr.to_vec(),
-                Arc::new(inputs[0].clone()),
-                schema.clone(),
-            )?))
-        }

Review Comment:
   Here exist a bug, we shouldn't use original `schema`, because it can be changed.
   Original code hidden some BUG.



-- 
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 #6595: fix: from_plan shouldn't use original schema

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


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -512,15 +512,22 @@ async fn test_regex_expressions() -> Result<()> {
 
 #[tokio::test]
 async fn test_cast_expressions() -> Result<()> {
+    test_expression!("CAST('0' AS INT)", "0");

Review Comment:
   Maybe a good follow on PR
   
   Seems like the hope to was to move it to slt as part of https://github.com/apache/arrow-datafusion/issues/6210 but wasn't completed 🤔 



-- 
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 #6595: fix: from_plan shouldn't use original schema & simplify expression need to convert type.

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


##########
datafusion/core/tests/sql/group_by.rs:
##########
@@ -18,6 +18,8 @@
 use super::*;
 
 #[tokio::test]
+#[ignore]
+// TODO: issue: https://github.com/apache/arrow-datafusion/issues/6623

Review Comment:
   I think we have fixed the date_trunc issues now, so these workarounds should no longer be necessary



-- 
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] izveigor commented on pull request #6595: fix: from_plan shouldn't use original schema

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

   I created PR about the 'nulls' problem: https://github.com/apache/arrow-datafusion/pull/6662. So I think it can solve the regression.


-- 
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] jackwener commented on a diff in pull request #6595: fix: from_plan shouldn't use original schema

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


##########
datafusion/common/src/dfschema.rs:
##########
@@ -384,8 +384,7 @@ impl DFSchema {
         let self_fields = self.fields().iter();
         let other_fields = other.fields().iter();
         self_fields.zip(other_fields).all(|(f1, f2)| {
-            f1.qualifier() == f2.qualifier()
-                && f1.name() == f2.name()
+            f1.qualified_name() == f2.qualified_name()

Review Comment:
   About this, I have a new idea on weekend. we may need handle alias `schema()` to specify the schema.
   
   Because `alias('t1.a')`, `field` is `qualifier: none, name: t1.a`, we hope `field` is `qualifier: t1, name: a`.
   
   I will do it in the future.



-- 
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 #6595: fix: from_plan shouldn't use original schema

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


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -512,15 +512,22 @@ async fn test_regex_expressions() -> Result<()> {
 
 #[tokio::test]
 async fn test_cast_expressions() -> Result<()> {
+    test_expression!("CAST('0' AS INT)", "0");

Review Comment:
   can we move it to slt? 



-- 
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] jackwener commented on a diff in pull request #6595: fix: from_plan shouldn't use original schema & simplify expression need to convert type.

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


##########
datafusion/common/src/dfschema.rs:
##########
@@ -384,8 +384,7 @@ impl DFSchema {
         let self_fields = self.fields().iter();
         let other_fields = other.fields().iter();
         self_fields.zip(other_fields).all(|(f1, f2)| {
-            f1.qualifier() == f2.qualifier()
-                && f1.name() == f2.name()
+            f1.qualified_name() == f2.qualified_name()

Review Comment:
   About this, I have a new idea on weekend. we may need an `alias_with_schema()` function that allows us to not only add alias, but also specify the schema.
   
   Because `alias('t1.a')`, `field` is `qualifier: none, name: t1.a`, we hope `field` is `qualifier: t1, name: a`.
   
   I think `alias_with_schema()` can achieve this goal.



-- 
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] jackwener commented on pull request #6595: fix: from_plan shouldn't use original schema & simplify expression need to convert type.

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

   this PR wait #6599


-- 
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 #6595: fix: from_plan shouldn't use original schema & simplify expression need to convert type.

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


##########
datafusion/common/src/dfschema.rs:
##########
@@ -384,8 +384,7 @@ impl DFSchema {
         let self_fields = self.fields().iter();
         let other_fields = other.fields().iter();
         self_fields.zip(other_fields).all(|(f1, f2)| {
-            f1.qualifier() == f2.qualifier()
-                && f1.name() == f2.name()
+            f1.qualified_name() == f2.qualified_name()

Review Comment:
   I am not sure if it matters, but I believe that `qualified_name` creates a new `String` where the previous version avoids that allocation.



##########
datafusion/core/tests/sqllogictests/test_files/array.slt:
##########
@@ -110,10 +111,10 @@ select array_position(['h', 'e', 'l', 'l', 'o'], 'l', 4), array_position([1, 2,
 4 5 2
 
 # array_positions scalar function
-query III
+query error DataFusion error: SQL error: ParserError\("Expected an SQL statement, found: caused"\)

Review Comment:
   these errors look not quite right -- I think there is something wrong with sqllogictest `--complete` with multi-line errors 🤔 



##########
datafusion/core/tests/sql/group_by.rs:
##########
@@ -18,6 +18,8 @@
 use super::*;
 
 #[tokio::test]
+#[ignore]
+// TODO: issue: https://github.com/apache/arrow-datafusion/issues/6623

Review Comment:
   Here is a proposed fix: https://github.com/apache/arrow-datafusion/pull/6632



##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -206,7 +206,16 @@ impl<'a> TreeNodeRewriter for ConstEvaluator<'a> {
 
     fn mutate(&mut self, expr: Expr) -> Result<Expr> {
         match self.can_evaluate.pop() {
-            Some(true) => Ok(Expr::Literal(self.evaluate_to_scalar(expr)?)),
+            Some(true) => {
+                // After simplifying the expression, data_type may change, so we need to cast it.

Review Comment:
   This seems wrong to me -- the type of the expression should always be the same before/after simplification. If it isn't the same that is a bug (perhaps we could raise an internal error 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


[GitHub] [arrow-datafusion] jackwener commented on a diff in pull request #6595: fix: from_plan shouldn't use original schema

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


##########
datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs:
##########
@@ -206,7 +206,16 @@ impl<'a> TreeNodeRewriter for ConstEvaluator<'a> {
 
     fn mutate(&mut self, expr: Expr) -> Result<Expr> {
         match self.can_evaluate.pop() {
-            Some(true) => Ok(Expr::Literal(self.evaluate_to_scalar(expr)?)),
+            Some(true) => {
+                // After simplifying the expression, data_type may change, so we need to cast it.

Review Comment:
   Correct 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


[GitHub] [arrow-datafusion] jackwener commented on a diff in pull request #6595: fix: from_plan shouldn't use original schema

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


##########
datafusion/common/src/dfschema.rs:
##########
@@ -384,8 +384,7 @@ impl DFSchema {
         let self_fields = self.fields().iter();
         let other_fields = other.fields().iter();
         self_fields.zip(other_fields).all(|(f1, f2)| {
-            f1.qualifier() == f2.qualifier()
-                && f1.name() == f2.name()
+            f1.qualified_name() == f2.qualified_name()

Review Comment:
   related issue #6681



-- 
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] jackwener merged pull request #6595: fix: from_plan shouldn't use original schema

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


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