-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-31393][SQL] Show the correct alias in schema for expression #28164
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
|
Test build #121013 has finished for PR 28164 at commit
|
|
Test build #121019 has finished for PR 28164 at commit
|
|
Test build #121036 has finished for PR 28164 at commit
|
|
cc @HyukjinKwon |
|
|
||
| override def toString: String = s"-$child" | ||
|
|
||
| override def prettyName: String = "-" |
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.
@HyukjinKwon Should we change "-" to "negative" ?
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.
I think it should be negative but should show - when it's used as the sql operator. You should be able to do this with if-else. e.g.)
getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse("-")
You might need to override sql IIRC.
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.
OK.
|
Test build #121142 has finished for PR 28164 at commit
|
43beb20 to
67c868b
Compare
|
Test build #121144 has finished for PR 28164 at commit
|
|
|
||
| override def prettyName: String = "max_by" | ||
|
|
||
| override protected def funcName: String = "max_by" |
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.
Seems like you can remove this and replace it to prettyName.
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. I will replace it.
But wait for #28194 merged.
Then I could update golden file.
|
Test build #122129 has finished for PR 28164 at commit
|
|
Test build #122154 has finished for PR 28164 at commit
|
|
Test build #122159 has finished for PR 28164 at commit
|
|
Test build #122300 has finished for PR 28164 at commit
|
|
retest this please |
|
Test build #122309 has finished for PR 28164 at commit
|
|
cc @HyukjinKwon |
|
cc @gatorsmile |
|
Merged to master and branch-3.0. |
### What changes were proposed in this pull request? Some alias of expression can not display correctly in schema. This PR will fix them. - `TimeWindow` - `MaxBy` - `MinBy` - `UnaryMinus` - `BitwiseCount` This PR also fix a typo issue, please look at https://github.com/apache/spark/blob/b7cde42b04b21c9bfee6535199cf385855c15853/sql/core/src/test/scala/org/apache/spark/sql/ExpressionsSchemaSuite.scala#L142 Note: 1. `MaxBy` and `MinBy` extends `MaxMinBy` and the latter add a method `funcName` not needed. We can reuse `prettyName` to replace `funcName`. 2. Spark SQL exists some function no elegant implementation.For example: `BitwiseCount` override the sql method show below: `override def sql: String = s"bit_count(${child.sql})"` I don't think it's elegant enough. Because `Expression` gives the following definitions. ``` def sql: String = { val childrenSQL = children.map(_.sql).mkString(", ") s"$prettyName($childrenSQL)" } ``` By this definition, `BitwiseCount` should override `prettyName` method. ### Why are the changes needed? Improve the implement of some expression. ### Does this PR introduce any user-facing change? 'Yes'. This PR will let user see the correct alias in schema. ### How was this patch tested? Jenkins test. Closes #28164 from beliefer/elegant-pretty-name-for-function. Lead-authored-by: beliefer <[email protected]> Co-authored-by: gengjiaan <[email protected]> Signed-off-by: HyukjinKwon <[email protected]> (cherry picked from commit a89006a) Signed-off-by: HyukjinKwon <[email protected]>
|
@HyukjinKwon Thanks! |
What changes were proposed in this pull request?
Some alias of expression can not display correctly in schema. This PR will fix them.
TimeWindowMaxByMinByUnaryMinusBitwiseCountThis PR also fix a typo issue, please look at
spark/sql/core/src/test/scala/org/apache/spark/sql/ExpressionsSchemaSuite.scala
Line 142 in b7cde42
Note:
MaxByandMinByextendsMaxMinByand the latter add a methodfuncNamenot needed. We can reuseprettyNameto replacefuncName.BitwiseCountoverride the sql method show below:override def sql: String = s"bit_count(${child.sql})"I don't think it's elegant enough. Because
Expressiongives the following definitions.By this definition,
BitwiseCountshould overrideprettyNamemethod.Why are the changes needed?
Improve the implement of some expression.
Does this PR introduce any user-facing change?
'Yes'. This PR will let user see the correct alias in schema.
How was this patch tested?
Jenkins test.