-
Notifications
You must be signed in to change notification settings - Fork 314
feat: Support Spark expression window_time #3732
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
Draft
0lai0
wants to merge
10
commits into
apache:main
Choose a base branch
from
0lai0:expression_window_time
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.
+85
−28
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0d2f579
feat: Support Spark expression window time
0lai0 9046b80
add SQL test and fix error
0lai0 1e4201a
Simplify annotations
0lai0 83f83ab
Apply suggestion from @andygrove
0lai0 9a618d8
Merge branch 'main' into expression_window_time
0lai0 4bd328b
add list of supported expressions to expressions.md and add test
0lai0 041008c
Merge branch 'main' into expression_window_time
0lai0 dfb3c7d
fix error
0lai0 d425ec4
Merge branch 'main' into expression_window_time
0lai0 56c39f2
Merge remote-tracking branch 'upstream/main' into expression_window_time
0lai0 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 hidden or 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 hidden or 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 hidden or 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
33 changes: 33 additions & 0 deletions
33
spark/src/test/resources/sql-tests/expressions/datetime/window_time.sql
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| -- Licensed to the Apache Software Foundation (ASF) under one | ||
| -- or more contributor license agreements. See the NOTICE file | ||
| -- distributed with this work for additional information | ||
| -- regarding copyright ownership. The ASF licenses this file | ||
| -- to you under the Apache License, Version 2.0 (the | ||
| -- "License"); you may not use this file except in compliance | ||
| -- with the License. You may obtain a copy of the License at | ||
| -- | ||
| -- http://www.apache.org/licenses/LICENSE-2.0 | ||
| -- | ||
| -- Unless required by applicable law or agreed to in writing, | ||
| -- software distributed under the License is distributed on an | ||
| -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| -- KIND, either express or implied. See the License for the | ||
| -- specific language governing permissions and limitations | ||
| -- under the License. | ||
|
|
||
|
|
||
| statement | ||
| CREATE TABLE test_window_time(time timestamp, value int) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_window_time VALUES (timestamp('2023-01-01 12:00:00'), 1), (timestamp('2023-01-01 12:05:00'), 2), (timestamp('2023-01-01 12:15:00'), 3), (NULL, 4) | ||
|
|
||
| -- spark_answer_only: window() is expanded by Spark with unsupported KnownNullable | ||
|
|
||
| -- basic window_time with tumbling window | ||
| query spark_answer_only | ||
| SELECT max(window_time(window)), sum(value) FROM (SELECT window(time, '10 minutes') AS window, value FROM test_window_time) GROUP BY window | ||
|
|
||
| -- window_time with sliding window | ||
| query spark_answer_only | ||
| SELECT max(window_time(window)), count(value) FROM (SELECT window(time, '10 minutes', '5 minutes') AS window, value FROM test_window_time) GROUP BY window | ||
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.
Both queries use
spark_answer_only. Is there a reason these can't run with the default mode that verifies native execution? If there's another operator in the plan that causes fallback, could you note which one?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.
Thanks @andygrove for review.
While this PR supports native execution, Spark's
window()introduces unsupported ops that trigger a full fallback. Therefore, we temporarily usespark_answer_onlyfor result verification. I'll add an inline comment to document this.If I have misunderstood, please correct me.
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.
Yes, windowed aggregates are marked as incompatible. Maybe you can enable in the test with
spark.comet.operator.WindowExec.allowIncompatible=true? You may need to check exact config key but it should be something like this.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.
Thanks @andygrove . I dug into this and tried enabling the config
spark.comet.operator.WindowExec.allowIncompatible=true, but the test still fails if I removespark_answer_only.The root cause might be at the expression level: Spark's
TimeWindowinganalyzer rule automatically expandswindow()into aCreateNamedStructwrapped inside aKnownNullableexpression. Since Comet doesn't currently support KnownNullable natively, the planner is forced to fall back to Spark anyway.https://github.com/search?q=repo%3Aapache%2Fspark+KnownNullable&type=code
Fully supporting native struct creation and KnownNullable would be a broader effort outside the scope of this PR (which focuses on
PreciseTimestampConversionissue forwindow_time).Because of this, it might be better to keep
spark_answer_onlyhere and open a follow-up issue for those specific expressions. I'll make sure to update the inline comment to explicitly document the exact cause of the fallback for future reference.Let me know your thoughts on this.