Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: window function range offset should be long instead of int #733

Merged
merged 10 commits into from
Sep 23, 2024

Conversation

huaxingao
Copy link
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

What changes are included in this PR?

How are these changes tested?

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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this test fails before this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 291 to 292
throw new IllegalArgumentException(
"Unsupported data type for window function row/range offset")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to return None to fall back to Spark

@huaxingao huaxingao force-pushed the range_offset branch 3 times, most recently from 2e03816 to 1f8a29e Compare August 22, 2024 17:00
@codecov-commenter
Copy link

codecov-commenter commented Aug 23, 2024

Codecov Report

Attention: Patch coverage is 52.94118% with 16 lines in your changes missing coverage. Please review.

Project coverage is 34.16%. Comparing base (9d8730d) to head (2777d18).
Report is 7 commits behind head on main.

Files Patch % Lines
.../scala/org/apache/comet/serde/QueryPlanSerde.scala 52.94% 6 Missing and 10 partials ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##               main     #733       +/-   ##
=============================================
- Coverage     55.16%   34.16%   -21.00%     
- Complexity      857      881       +24     
=============================================
  Files           109      112        +3     
  Lines         10542    42949    +32407     
  Branches       2010     9491     +7481     
=============================================
+ Hits           5815    14673     +8858     
- Misses         3714    25274    +21560     
- Partials       1013     3002     +1989     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

WindowFrameUnits::Rows => {
WindowFrameBound::Preceding(ScalarValue::UInt64(None))
}
WindowFrameUnits::Range | WindowFrameUnits::Groups => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use Groups?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines 3327 to 3330
if (partitionColumnNames.toSet != orderColumnNames.toSet) {
withInfo(op, "Partitioning and sorting specifications do not match")
return false
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks!

@huaxingao huaxingao merged commit 459b2b0 into apache:main Sep 23, 2024
74 checks passed
@huaxingao huaxingao deleted the range_offset branch September 23, 2024 21:12
@huaxingao
Copy link
Contributor Author

Merged. Thanks @viirya @kazuyukitanimura

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants