-
Notifications
You must be signed in to change notification settings - Fork 146
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
Open
huaxingao
wants to merge
7
commits into
apache:main
Choose a base branch
from
huaxingao:range_offset
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1104697
fix: window function range offset should be long instead of int
huaxingao 423bcc3
fix error
huaxingao 63822c1
fall back to Spark if range offset is not int or long
huaxingao a1e829c
uncomment tests
huaxingao e164d11
rebase
huaxingao 8cc5772
fix offset datatype
huaxingao 0d84fd2
fix data type
huaxingao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,15 +255,17 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde with CometExprShim | |
(None, exprToProto(windowExpr.windowFunction, output)) | ||
} | ||
|
||
if (aggExpr.isEmpty && builtinFunc.isEmpty) { | ||
return None | ||
} | ||
|
||
val f = windowExpr.windowSpec.frameSpecification | ||
|
||
val (frameType, lowerBound, upperBound) = f match { | ||
case SpecifiedWindowFrame(frameType, lBound, uBound) => | ||
val frameProto = frameType match { | ||
case RowFrame => OperatorOuterClass.WindowFrameType.Rows | ||
case RangeFrame => | ||
withInfo(windowExpr, "Range frame is not supported") | ||
return None | ||
case RangeFrame => OperatorOuterClass.WindowFrameType.Range | ||
} | ||
|
||
val lBoundProto = lBound match { | ||
|
@@ -278,12 +280,17 @@ 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 _ => return None | ||
} | ||
OperatorOuterClass.LowerWindowFrameBound | ||
.newBuilder() | ||
.setPreceding( | ||
OperatorOuterClass.Preceding | ||
.newBuilder() | ||
.setOffset(e.eval().asInstanceOf[Int]) | ||
.setOffset(offset) | ||
.build()) | ||
.build() | ||
} | ||
|
@@ -300,12 +307,18 @@ 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 _ => return None | ||
} | ||
|
||
OperatorOuterClass.UpperWindowFrameBound | ||
.newBuilder() | ||
.setFollowing( | ||
OperatorOuterClass.Following | ||
.newBuilder() | ||
.setOffset(e.eval().asInstanceOf[Int]) | ||
.setOffset(offset) | ||
.build()) | ||
.build() | ||
} | ||
|
@@ -2774,6 +2787,11 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde with CometExprShim | |
return None | ||
} | ||
|
||
if (partitionSpec.nonEmpty && orderSpec.nonEmpty && | ||
!validatePartitionAndSortSpecsForWindowFunc(partitionSpec, orderSpec, op)) { | ||
return None | ||
} | ||
|
||
val windowExprProto = winExprs.map(windowExprToProto(_, output, op.conf)) | ||
val partitionExprs = partitionSpec.map(exprToProto(_, child.output)) | ||
|
||
|
@@ -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 | ||
} | ||
Comment on lines
+3327
to
+3330
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we use
Groups
?