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

[PR] fix: window function range offset should be long instead of int [datafusion-comet]

huaxingao opened a new pull request, #733:
URL: https://github.com/apache/datafusion-comet/pull/733

   ## 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.
   -->
   
   ## How 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)?
   -->
   


-- 
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@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: window function range offset should be long instead of int [datafusion-comet]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #733:
URL: https://github.com/apache/datafusion-comet/pull/733#issuecomment-2305946074

   ## [Codecov](https://app.codecov.io/gh/apache/datafusion-comet/pull/733?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `52.94118%` with `16 lines` in your changes missing coverage. Please review.
   > Project coverage is 34.03%. Comparing base [(`9d8730d`)](https://app.codecov.io/gh/apache/datafusion-comet/commit/9d8730d8ac7bfeb3656ff57968644028323b364b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`2777d18`)](https://app.codecov.io/gh/apache/datafusion-comet/commit/2777d182047bb78b7940fa46c0d28ddecc7dc354?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   > Report is 7 commits behind head on main.
   
   | [Files](https://app.codecov.io/gh/apache/datafusion-comet/pull/733?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [.../scala/org/apache/comet/serde/QueryPlanSerde.scala](https://app.codecov.io/gh/apache/datafusion-comet/pull/733?src=pr&el=tree&filepath=spark%2Fsrc%2Fmain%2Fscala%2Forg%2Fapache%2Fcomet%2Fserde%2FQueryPlanSerde.scala&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3Bhcmsvc3JjL21haW4vc2NhbGEvb3JnL2FwYWNoZS9jb21ldC9zZXJkZS9RdWVyeVBsYW5TZXJkZS5zY2FsYQ==) | 52.94% | [6 Missing and 10 partials :warning: ](https://app.codecov.io/gh/apache/datafusion-comet/pull/733?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@              Coverage Diff              @@
   ##               main     #733       +/-   ##
   =============================================
   - Coverage     55.16%   34.03%   -21.13%     
   - Complexity      857      876       +19     
   =============================================
     Files           109      112        +3     
     Lines         10542    42949    +32407     
     Branches       2010     9491     +7481     
   =============================================
   + Hits           5815    14619     +8804     
   - Misses         3714    25314    +21600     
   - Partials       1013     3016     +2003     
   ```
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/datafusion-comet/pull/733?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
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@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: window function range offset should be long instead of int [datafusion-comet]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #733:
URL: https://github.com/apache/datafusion-comet/pull/733#discussion_r1768920385


##########
native/core/src/execution/datafusion/planner.rs:
##########
@@ -1692,16 +1692,33 @@ impl PhysicalPlanner {
             .and_then(|inner| inner.lower_frame_bound_struct.as_ref())
         {
             Some(l) => match l {
-                LowerFrameBoundStruct::UnboundedPreceding(_) => {
-                    WindowFrameBound::Preceding(ScalarValue::UInt64(None))
-                }
+                LowerFrameBoundStruct::UnboundedPreceding(_) => match units {
+                    WindowFrameUnits::Rows => {
+                        WindowFrameBound::Preceding(ScalarValue::UInt64(None))
+                    }
+                    WindowFrameUnits::Range | WindowFrameUnits::Groups => {

Review Comment:
   Do we use `Groups`?



-- 
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@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: window function range offset should be long instead of int [datafusion-comet]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #733:
URL: https://github.com/apache/datafusion-comet/pull/733#discussion_r1693784042


##########
spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala:
##########
@@ -275,12 +284,20 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde with CometExprShim
               .setCurrentRow(OperatorOuterClass.CurrentRow.newBuilder().build())
               .build()
           case e =>
+            val offset = e.eval() match {
+              case i: Integer => i.toLong
+              case l: Long => l
+              case _ =>
+                throw new IllegalArgumentException(
+                  "Unsupported data type for window function row/range offset")

Review Comment:
   You will fail the query directly instead of falling back to Spark.



-- 
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@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: window function range offset should be long instead of int [datafusion-comet]

Posted by "kazuyukitanimura (via GitHub)" <gi...@apache.org>.
kazuyukitanimura commented on code in PR #733:
URL: https://github.com/apache/datafusion-comet/pull/733#discussion_r1693772777


##########
spark/src/test/scala/org/apache/comet/exec/CometExecSuite.scala:
##########
@@ -63,23 +63,35 @@ class CometExecSuite extends CometTestBase {
     }
   }
 
-  test("Window range frame should fall back to Spark") {
+  test("Window range frame with Long") {
     val df =
       Seq((1L, "1"), (1L, "1"), (2147483650L, "1"), (3L, "2"), (2L, "1"), (2147483650L, "2"))
         .toDF("key", "value")
 
     checkAnswer(
       df.select(
         $"key",
-        count("key").over(
+        sum("key").over(

Review Comment:
   So this test fails before this change?



-- 
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@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: window function range offset should be long instead of int [datafusion-comet]

Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on code in PR #733:
URL: https://github.com/apache/datafusion-comet/pull/733#discussion_r1693980607


##########
spark/src/test/scala/org/apache/comet/exec/CometExecSuite.scala:
##########
@@ -63,23 +63,35 @@ class CometExecSuite extends CometTestBase {
     }
   }
 
-  test("Window range frame should fall back to Spark") {
+  test("Window range frame with Long") {
     val df =
       Seq((1L, "1"), (1L, "1"), (2147483650L, "1"), (3L, "2"), (2L, "1"), (2147483650L, "2"))
         .toDF("key", "value")
 
     checkAnswer(
       df.select(
         $"key",
-        count("key").over(
+        sum("key").over(

Review Comment:
   We currently don't support `count` so change to `sum`. Previously, even if the aggregate function is not supported, it still goes to the window frame code. In this PR, I return None directly if aggregate function is not supported. 



-- 
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@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: window function range offset should be long instead of int [datafusion-comet]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #733:
URL: https://github.com/apache/datafusion-comet/pull/733#discussion_r1768932963


##########
spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala:
##########
@@ -3277,4 +3295,41 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde with CometExprShim
       true
     }
   }
+
+  private def validatePartitionAndSortSpecsForWindowFunc(
+      partitionSpec: Seq[Expression],
+      orderSpec: Seq[SortOrder],
+      op: SparkPlan): Boolean = {
+    if (partitionSpec.length != orderSpec.length) {
+      withInfo(op, "Partitioning and sorting specifications do not match")
+      return false
+    } else {
+      val partitionColumnNames = partitionSpec.collect { case a: AttributeReference =>
+        a.name
+      }
+
+      if (partitionColumnNames.length != partitionSpec.length) {
+        withInfo(op, "Unsupported partitioning specification")
+        return false
+      }
+
+      val orderColumnNames = orderSpec.collect { case s: SortOrder =>
+        s.child match {
+          case a: AttributeReference => a.name
+        }
+      }
+
+      if (orderColumnNames.length != orderSpec.length) {
+        withInfo(op, "Unsupported SortOrder")
+        return false
+      }
+
+      if (partitionColumnNames.toSet != orderColumnNames.toSet) {
+        withInfo(op, "Partitioning and sorting specifications do not match")
+        return false
+      }

Review Comment:
   Maybe check the partition column and order column one by one instead of a set? I'm not sure if `(PARTITION BY k, v ORDER BY v, k)` work.



-- 
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@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: window function range offset should be long instead of int [datafusion-comet]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #733:
URL: https://github.com/apache/datafusion-comet/pull/733#discussion_r1771896989


##########
native/core/src/execution/datafusion/planner.rs:
##########
@@ -1692,16 +1692,33 @@ impl PhysicalPlanner {
             .and_then(|inner| inner.lower_frame_bound_struct.as_ref())
         {
             Some(l) => match l {
-                LowerFrameBoundStruct::UnboundedPreceding(_) => {
-                    WindowFrameBound::Preceding(ScalarValue::UInt64(None))
-                }
+                LowerFrameBoundStruct::UnboundedPreceding(_) => match units {
+                    WindowFrameUnits::Rows => {
+                        WindowFrameBound::Preceding(ScalarValue::UInt64(None))
+                    }
+                    WindowFrameUnits::Range | WindowFrameUnits::Groups => {

Review Comment:
   Can we add it as separate pattern branch and return error?



-- 
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@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: window function range offset should be long instead of int [datafusion-comet]

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


-- 
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@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: window function range offset should be long instead of int [datafusion-comet]

Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on code in PR #733:
URL: https://github.com/apache/datafusion-comet/pull/733#discussion_r1771810211


##########
native/core/src/execution/datafusion/planner.rs:
##########
@@ -1692,16 +1692,33 @@ impl PhysicalPlanner {
             .and_then(|inner| inner.lower_frame_bound_struct.as_ref())
         {
             Some(l) => match l {
-                LowerFrameBoundStruct::UnboundedPreceding(_) => {
-                    WindowFrameBound::Preceding(ScalarValue::UInt64(None))
-                }
+                LowerFrameBoundStruct::UnboundedPreceding(_) => match units {
+                    WindowFrameUnits::Rows => {
+                        WindowFrameBound::Preceding(ScalarValue::UInt64(None))
+                    }
+                    WindowFrameUnits::Range | WindowFrameUnits::Groups => {

Review Comment:
   We don't use `Groups`, but if we don't specify this case, `UpperFrameBoundStruct::UnboundedFollowing(_) => match units` fails with `pattern datafusion_expr::WindowFrameUnits::Groups not covered`.



##########
spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala:
##########
@@ -3277,4 +3295,41 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde with CometExprShim
       true
     }
   }
+
+  private def validatePartitionAndSortSpecsForWindowFunc(
+      partitionSpec: Seq[Expression],
+      orderSpec: Seq[SortOrder],
+      op: SparkPlan): Boolean = {
+    if (partitionSpec.length != orderSpec.length) {
+      withInfo(op, "Partitioning and sorting specifications do not match")
+      return false
+    } else {
+      val partitionColumnNames = partitionSpec.collect { case a: AttributeReference =>
+        a.name
+      }
+
+      if (partitionColumnNames.length != partitionSpec.length) {
+        withInfo(op, "Unsupported partitioning specification")
+        return false
+      }
+
+      val orderColumnNames = orderSpec.collect { case s: SortOrder =>
+        s.child match {
+          case a: AttributeReference => a.name
+        }
+      }
+
+      if (orderColumnNames.length != orderSpec.length) {
+        withInfo(op, "Unsupported SortOrder")
+        return false
+      }
+
+      if (partitionColumnNames.toSet != orderColumnNames.toSet) {
+        withInfo(op, "Partitioning and sorting specifications do not match")
+        return false
+      }

Review Comment:
   Fixed. Thanks!



-- 
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@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: window function range offset should be long instead of int [datafusion-comet]

Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on code in PR #733:
URL: https://github.com/apache/datafusion-comet/pull/733#discussion_r1693979682


##########
spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala:
##########
@@ -275,12 +284,20 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde with CometExprShim
               .setCurrentRow(OperatorOuterClass.CurrentRow.newBuilder().build())
               .build()
           case e =>
+            val offset = e.eval() match {
+              case i: Integer => i.toLong
+              case l: Long => l
+              case _ =>
+                throw new IllegalArgumentException(
+                  "Unsupported data type for window function row/range offset")

Review Comment:
   changed to `return None` to fall back to Spark



-- 
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@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] fix: window function range offset should be long instead of int [datafusion-comet]

Posted by "huaxingao (via GitHub)" <gi...@apache.org>.
huaxingao commented on PR #733:
URL: https://github.com/apache/datafusion-comet/pull/733#issuecomment-2369399687

   Merged. Thanks @viirya @kazuyukitanimura 


-- 
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@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org