-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-33989][SQL] Strip auto-generated cast when using Cast.sql #31034
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
25 commits
Select commit
Hold shift + click to select a range
d66ecc1
init
ulysses-you 52440cd
add cast tag
ulysses-you eb0ad21
add test
ulysses-you c82c928
sql output golden file
ulysses-you 68fe16e
Merge branch 'master' of https://github.com/apache/spark into SPARK-3…
ulysses-you e398dd3
test name
ulysses-you a67e915
plan golden file
ulysses-you dd891e5
fix sql output
ulysses-you 7b00641
fix sql output
ulysses-you ad6a6f7
fix sql-expression-schem
ulysses-you 264f5bb
fix explainSuite
ulysses-you a160d62
fix context.py
ulysses-you dc367bd
use PrettyAttribute
ulysses-you fd097a7
fix ExplainSuite
ulysses-you 3823289
fix session.py
ulysses-you f1dcb64
fix anti_cast
ulysses-you c4f2cf7
fix sql test
ulysses-you 0256af5
revert analyzer
ulysses-you 601e45a
track cast
ulysses-you ab827fc
dsl
ulysses-you f925de5
tag name
ulysses-you e5294fe
comment
ulysses-you 3c23778
parameter name
ulysses-you 3217d5b
migration docs
ulysses-you 2d13353
docs
ulysses-you 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
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
83 changes: 83 additions & 0 deletions
83
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ResolveAliasesSuite.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,83 @@ | ||
| /* | ||
| * 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.analysis | ||
|
|
||
| import scala.collection.mutable.ArrayBuffer | ||
|
|
||
| import org.apache.spark.sql.catalyst.dsl.expressions._ | ||
| import org.apache.spark.sql.catalyst.dsl.plans._ | ||
| import org.apache.spark.sql.catalyst.expressions._ | ||
| import org.apache.spark.sql.catalyst.plans.logical.{LocalRelation, LogicalPlan, Project} | ||
| import org.apache.spark.sql.types.{DoubleType, IntegerType, LongType, StringType} | ||
|
|
||
| class ResolveAliasesSuite extends AnalysisTest { | ||
|
|
||
| private lazy val t1 = LocalRelation("a".attr.int) | ||
| private lazy val t2 = LocalRelation("b".attr.long) | ||
|
|
||
| private def checkAliasName(plan: LogicalPlan, expected: String): Unit = { | ||
| val analyzed = getAnalyzer.execute(plan) | ||
| val actual = analyzed.find(_.isInstanceOf[Project]).get.asInstanceOf[Project] | ||
| .projectList.head.asInstanceOf[Alias].name | ||
| assert(actual == expected) | ||
| } | ||
|
|
||
| private def checkSubqueryAliasName(plan: LogicalPlan, expected: String): Unit = { | ||
| val analyzed = getAnalyzer.execute(plan) | ||
| val subqueryExpression = new ArrayBuffer[SubqueryExpression]() | ||
| analyzed.transformExpressions { | ||
| case e: SubqueryExpression => | ||
| subqueryExpression.append(e) | ||
| e | ||
| } | ||
| assert(subqueryExpression.length == 1) | ||
| val actual = subqueryExpression.head.plan.find(_.isInstanceOf[Project]).get | ||
| .asInstanceOf[Project].projectList.head.asInstanceOf[Alias].name | ||
| assert(actual == expected) | ||
| } | ||
|
|
||
| test("SPARK-33989: test unary expression") { | ||
| checkAliasName(t1.select(Floor(Literal(null))), "FLOOR(NULL)") | ||
| checkAliasName(t1.select(Floor("a".attr)), "FLOOR(a)") | ||
| checkAliasName(t1.select(Floor("a".attr.cast(DoubleType))), "FLOOR(CAST(a AS DOUBLE))") | ||
| } | ||
|
|
||
| test("SPARK-33989: test binary expression") { | ||
| checkAliasName(t1.select(EqualTo("a".attr, Literal(null))), "(a = NULL)") | ||
| checkAliasName(t1.select(EqualTo("a".attr.cast(LongType), Literal(1))), | ||
| "(CAST(a AS BIGINT) = 1)") | ||
| checkAliasName(t1.select(EqualTo("a".attr.cast(LongType), Literal("2").cast(LongType))), | ||
| "(CAST(a AS BIGINT) = CAST(2 AS BIGINT))") | ||
| } | ||
|
|
||
| test("SPARK-33989: test nested expression") { | ||
| checkAliasName(t1.select(StringSplit("a".attr + 1, ",", Literal(-1))), | ||
| "split((a + 1), ,, -1)") | ||
| checkAliasName(t1.select(StringSplit(("a".attr + 1).cast(StringType), ",", Literal(-1))), | ||
| "split(CAST((a + 1) AS STRING), ,, -1)") | ||
| } | ||
|
|
||
| test("SPARK-33989: test subquery expression") { | ||
| checkSubqueryAliasName( | ||
| t1.select(ScalarSubquery(t2.select(EqualTo("b".attr, Literal(null))))), | ||
| "(b = NULL)") | ||
| checkSubqueryAliasName( | ||
| t1.select(ScalarSubquery(t2.select(EqualTo("b".attr.cast(IntegerType), Literal(1))))), | ||
| "(CAST(b AS INT) = 1)") | ||
| } | ||
| } |
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.
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.
So the purpose is to strip Cast only from
toPrettySQL? Only for changing column name but the actual Cast expression still works?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.
Could you elaborate it clearly in the PR description?
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, it's the only place which we changed. Update the description.