-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-46366][SQL] Use WITH expression in BETWEEN to avoid duplicate expressions #44299
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
Closed
Closed
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
c018e6a
intial prototype
dbatomic 8c17973
Adding test to plan generation test suite
dbatomic 8c929c2
Adding explain check
dbatomic e5da5c5
adding new comment
dbatomic 38f3ea6
Merge remote-tracking branch 'upstream/master' into between_expressio…
dbatomic 57d7994
Merge branch 'apache:master' into between_expression_v2
dbatomic feceae3
fixing test in expressionparsersuite
dbatomic 765e499
Fixing streaming logic
dbatomic 1b25d4f
Updating golden files
dbatomic a69dd57
Removing unresolved between expression.
dbatomic a038faa
Renaming BetweenExpr -> Between
dbatomic d0462ff
Fixing golden files
dbatomic 596befe
Adding comments.
dbatomic 1a2ec50
Adding more rigid coercion rules for between, there are more alike if…
dbatomic 0faa792
Using built in function for resolution.
dbatomic 7f6b0c9
Updating changed plans
dbatomic a1dc501
Updating golden files
dbatomic 6569653
Updating golden files for sql-expression-schema. Removing between fro…
dbatomic e64fc19
Doc update for between expression
dbatomic 57c88ee
Updating expression documentation
dbatomic 1776f8a
Merge branch 'apache:master' into between_expression_v2
dbatomic 26653f0
fixing failing doc test
dbatomic dc36be3
Documentation update
dbatomic ad61074
Merge branch 'apache:master' into between_expression_v2
dbatomic 3cf76b1
Resolving PR comments
dbatomic 550fa3d
Merge branch 'between_expression_v2' of github.com:dbatomic/spark int…
dbatomic 7dfd72d
PR comments
dbatomic 4fb6631
PR comment on better documentation
dbatomic a960c91
doc update
dbatomic 1ce26eb
adding rand example to predicate function golden files.
dbatomic 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
3 changes: 3 additions & 0 deletions
3
connector/connect/common/src/test/resources/query-tests/explain-results/between_expr.explain
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,3 @@ | ||
| Project [((_common_expr_0#0 >= cast(0.1 as double)) AND (_common_expr_0#0 <= cast(0.2 as double))) AS between(rand(123), 0.1, 0.2)#0] | ||
| +- Project [id#0L, a#0, b#0, rand(123) AS _common_expr_0#0] | ||
| +- LocalRelation <empty>, [id#0L, a#0, b#0] |
20 changes: 20 additions & 0 deletions
20
connector/connect/common/src/test/resources/query-tests/queries/between_expr.json
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,20 @@ | ||
| { | ||
| "common": { | ||
| "planId": "1" | ||
| }, | ||
| "project": { | ||
| "input": { | ||
| "common": { | ||
| "planId": "0" | ||
| }, | ||
| "localRelation": { | ||
| "schema": "struct\u003cid:bigint,a:int,b:double\u003e" | ||
| } | ||
| }, | ||
| "expressions": [{ | ||
| "expressionString": { | ||
| "expression": "rand(123) BETWEEN 0.1 AND 0.2" | ||
| } | ||
| }] | ||
| } | ||
| } |
Binary file added
BIN
+83 Bytes
connector/connect/common/src/test/resources/query-tests/queries/between_expr.proto.bin
Binary file not shown.
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
58 changes: 58 additions & 0 deletions
58
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Between.scala
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,58 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.catalyst.expressions | ||
|
|
||
| // scalastyle:off line.size.limit | ||
| @ExpressionDescription( | ||
| usage = "Usage: input [NOT] BETWEEN lower AND upper - evaluate if `input` is [not] in between `lower` and `upper`", | ||
| examples = """ | ||
| Examples: | ||
| > SELECT 0.5 _FUNC_ 0.1 AND 1.0; | ||
| true | ||
| """, | ||
| arguments = """ | ||
| Arguments: | ||
| * input - An expression that is being compared with lower and upper bound. | ||
| * lower - Lower bound of the between check. | ||
| * upper - Upper bound of the between check. | ||
| """, | ||
| since = "4.0.0", | ||
| group = "conditional_funcs") | ||
| case class Between private(input: Expression, lower: Expression, upper: Expression, replacement: Expression) | ||
| extends RuntimeReplaceable with InheritAnalysisRules { | ||
| def this(input: Expression, lower: Expression, upper: Expression) = { | ||
| this(input, lower, upper, { | ||
| val commonExpr = CommonExpressionDef(input) | ||
| val ref = new CommonExpressionRef(commonExpr) | ||
| val replacement = And(GreaterThanOrEqual(ref, lower), LessThanOrEqual(ref, upper)) | ||
| With(replacement, Seq(commonExpr)) | ||
| }) | ||
| }; | ||
|
|
||
| override def parameters: Seq[Expression] = Seq(input, lower, upper) | ||
|
|
||
| override protected def withNewChildInternal(newChild: Expression): Between = { | ||
| copy(replacement = newChild) | ||
| } | ||
| } | ||
|
|
||
| object Between { | ||
| def apply(input: Expression, lower: Expression, upper: Expression): Between = { | ||
| new Between(input, lower, upper) | ||
| } | ||
| } |
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.