-
Notifications
You must be signed in to change notification settings - Fork 29k
[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
Conversation
| | identifier #columnReference | ||
| | base=primaryExpression '.' fieldName=identifier #dereference | ||
| | '(' expression ')' #parenthesizedExpression | ||
| | name=(CURRENT_DATE | CURRENT_TIMESTAMP) #timeFunctionCall |
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.
Won't this break every use of CURRENT_DATE/CURRENT_TIMESTAMP? They will now be interpreted as an identifier.
|
ok to test |
|
Test build #82988 has finished for PR 19559 at commit
|
|
@hvanhovell Yes! I made something wrong. The For SPARK-16836, How about your idea? |
|
@DonnyZone Analyzer is the best place to fix the issue. |
|
@gatorsmile Thank for your advice, I will work on it. |
|
Test build #83044 has finished for PR 19559 at commit
|
| ExtractGenerator :: | ||
| ResolveGenerate :: | ||
| ResolveFunctions :: | ||
| ResolveLiteralFunctions :: |
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.
The order matters. It assumes ResolveReferences should be run before this rule. However, ResolveReferences might need multiple passes to resolve all the references. Thus, how about moving the logics into ResolveReferences ? If the attributes are not resolvable, we try to see whether it is a function literal?
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.
Agree! I will refactor it.
|
Test build #83071 has finished for PR 19559 at commit
|
|
Test build #83076 has finished for PR 19559 at commit
|
|
Test build #83077 has finished for PR 19559 at commit
|
|
retest this please |
| val literalFunctions = Seq(CurrentDate(), CurrentTimestamp()) | ||
| val name = nameParts.head | ||
| val func = literalFunctions.find(e => resolver(e.prettyName, name)) | ||
| if (func.isDefined) { |
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 func option.
|
@gatorsmile @gatorsmile |
| val result = withPosition(u) { q.resolveChildren(nameParts, resolver).getOrElse(u) } | ||
| val result = | ||
| withPosition(u) { | ||
| q.resolveChildren(nameParts, resolver).getOrElse { |
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.
You can also use orElse:
q.resolveChildren(nameParts, resolver).orElse(resolveAsLiteralFunctions(nameParts)).getOrElse(u)
|
Test build #83078 has finished for PR 19559 at commit
|
|
Test build #83080 has finished for PR 19559 at commit
|
|
Test build #83081 has finished for PR 19559 at commit
|
| f => Alias(f, toPrettySQL(f))() | ||
| } else { | ||
| f => f | ||
| } |
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.
if (nameParts.length != 1) return None
val isNamedExpression = plan match {
case Aggregate(_, aggs, _) => aggs.contains(attribute)
case Project(projList, _) => projList.contains(attribute)
case Window(windowExpressions, _, _, _) => windowExpressions.contains(attribute)
case _ => false
}
val wrapper: Expression => Expression =
if (isNamedExpression) f => Alias(f, toPrettySQL(f))() else identity| true | ||
| case p @ Project(projList, _) if (projList.contains(attribute)) => | ||
| true | ||
| case _ => |
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.
Miss Windows
| "a, b FROM ttf1"), | ||
| Seq(Row(true, true, 1, 2), Row(true, true, 2, 3))) | ||
| } | ||
| } |
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.
Move these to datetime.sql?
|
Yes, ordering in |
|
Test build #83112 has finished for PR 19559 at commit
|
|
Test build #83110 has finished for PR 19559 at commit
|
|
Test build #83111 has finished for PR 19559 at commit
|
|
Test build #83114 has finished for PR 19559 at commit
|
|
Test build #83117 has finished for PR 19559 at commit
|
|
Test build #83121 has finished for PR 19559 at commit
|
## What changes were proposed in this pull request? This PR is to clean the related codes majorly based on the today's code review on apache#19559 ## How was this patch tested? N/A Author: gatorsmile <gatorsmile@gmail.com> Closes apache#19585 from gatorsmile/trivialFixes.
|
Test build #83122 has finished for PR 19559 at commit
|
|
Test build #83138 has finished for PR 19559 at commit
|
|
Thanks! Merged to master. |
|
Could you submit a backport PR to 2.2? |
|
Sure, I will submit it later. |
…NT_TIMESTAMP) has conflicts with columnReference ## What changes were proposed in this pull request? This is a backport pr of apache#19559 for branch-2.2 ## How was this patch tested? unit tests Author: donnyzone <wellfengzhu@gmail.com> Closes apache#19606 from DonnyZone/branch-2.2.
What changes were proposed in this pull request?
https://issues.apache.org/jira/browse/SPARK-22333
In current version, users can use CURRENT_DATE() and CURRENT_TIMESTAMP() without specifying braces.
However, when a table has columns named as "current_date" or "current_timestamp", it will still be parsed as function call.
There are many such cases in our production cluster. We get the wrong answer due to this inappropriate behevior. In general, ColumnReference should get higher priority than timeFunctionCall.
How was this patch tested?
unit test
manul test