-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-22333][SQL]timeFunctionCall(CURRENT_DATE, CURRENT_TIMESTAMP) has conflicts with columnReference #19559
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 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
60a5a56
spark-22333
DonnyZone c38ab56
fix in analysis phase
DonnyZone d485e25
fix typo
DonnyZone 2d42abf
Refactor in ResolveReferece
DonnyZone 5323fbb
end-to-end test schema
DonnyZone 6c932b7
Distinguish NamedExpression and Expression
DonnyZone b8075e1
remove test for current date/timestamp braceless expressions
DonnyZone 4b13343
move from DateFunctionsSuite to end-to-end tests
DonnyZone a96d945
typo error
DonnyZone 36b4bbb
support literal function in resolveExpression
DonnyZone 87c2073
typo
DonnyZone 5baf98e
fix error
DonnyZone 7e7a25c
add new test
DonnyZone 846cee4
test
DonnyZone 2efd4f7
remove semicolon
DonnyZone a57fb81
resolve conflicts
DonnyZone 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -783,6 +783,25 @@ class Analyzer( | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Literal functions do not require the user to specify braces when calling them | ||
| * When an attributes is not resolvable, we try to resolve it as a literal function. | ||
| */ | ||
| private def resolveAsLiteralFunctions(nameParts: Seq[String]): Option[NamedExpression] = { | ||
| if (nameParts.length != 1) { | ||
| return None | ||
| } | ||
| // support CURRENT_DATE and CURRENT_TIMESTAMP | ||
| val literalFunctions = Seq(CurrentDate(), CurrentTimestamp()) | ||
| val name = nameParts.head | ||
| val func = literalFunctions.find(e => resolver(e.prettyName, name)) | ||
| if (func.isDefined) { | ||
| Some(Alias(func.get, toPrettySQL(func.get))()) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
|
|
||
| def apply(plan: LogicalPlan): LogicalPlan = plan.resolveOperators { | ||
| case p: LogicalPlan if !p.childrenResolved => p | ||
|
|
||
|
|
@@ -844,7 +863,12 @@ class Analyzer( | |
| q.transformExpressionsUp { | ||
| case u @ UnresolvedAttribute(nameParts) => | ||
| // Leave unchanged if resolution fails. Hopefully will be resolved next round. | ||
| val result = withPosition(u) { q.resolveChildren(nameParts, resolver).getOrElse(u) } | ||
| val result = | ||
| withPosition(u) { | ||
| q.resolveChildren(nameParts, resolver).getOrElse { | ||
|
Contributor
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. You can also use |
||
| resolveAsLiteralFunctions(nameParts).getOrElse(u) | ||
| } | ||
| } | ||
| logDebug(s"Resolving $u to $result") | ||
| result | ||
| case UnresolvedExtractValue(child, fieldExpr) if child.resolved => | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,24 @@ class DateFunctionsSuite extends QueryTest with SharedSQLContext { | |
| checkAnswer(sql("""SELECT CURRENT_TIMESTAMP() = NOW()"""), Row(true)) | ||
| } | ||
|
|
||
| test("SPARK-22333: timeFunctionCall has conflicts with columnReference ") { | ||
| val df = Seq((1, 2), (2, 3)).toDF("current_date", "current_timestamp") | ||
| df.createOrReplaceTempView("ttf") | ||
| withTempView("ttf") { | ||
| checkAnswer(sql("SELECT current_date, current_timestamp FROM ttf"), | ||
| Seq(Row(1, 2), Row(2, 3))) | ||
| } | ||
|
|
||
| val df1 = Seq((1, 2), (2, 3)).toDF("a", "b") | ||
| df1.createOrReplaceTempView("ttf1") | ||
| withTempView("ttf1") { | ||
| checkAnswer( | ||
| sql("SELECT current_date = current_date(), current_timestamp = current_timestamp(), " + | ||
| "a, b FROM ttf1"), | ||
| Seq(Row(true, true, 1, 2), Row(true, true, 2, 3))) | ||
| } | ||
| } | ||
|
Member
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. Move these to |
||
|
|
||
| val sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US) | ||
| val sdfDate = new SimpleDateFormat("yyyy-MM-dd", Locale.US) | ||
| val d = new Date(sdf.parse("2015-04-08 13:10:15").getTime) | ||
|
|
||
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.
Just map over the
funcoption.