Skip to content

[SPARK-31146][SQL] Leverage the helper method for aliasing in built-in SQL expressions - #27901

Closed
HyukjinKwon wants to merge 3 commits into
apache:masterfrom
HyukjinKwon:31146
Closed

[SPARK-31146][SQL] Leverage the helper method for aliasing in built-in SQL expressions #27901
HyukjinKwon wants to merge 3 commits into
apache:masterfrom
HyukjinKwon:31146

Conversation

@HyukjinKwon

@HyukjinKwonHyukjinKwon commented Mar 13, 2020

Copy link
Copy Markdown
Member

What changes were proposed in this pull request?

This PR is kind of a followup of #26808. It leverages the helper method for aliasing in built-in SQL expressions to use the alias as its output column name where it's applicable.

  • Expression, UnaryMathExpression and BinaryMathExpression search the alias in the tags by default.
  • When the naming is different in its implementation, it has to be overwritten for the expression specifically. E.g., CallMethodViaReflection, Remainder, CurrentTimestamp,
    FormatString and XPathDouble.

This PR fixes the aliases of the functions below:

classalias
Randrandom
Ceilceiling
Remaindermod
Powpow
Signumsign
Chrchar
Lengthchar_length
Lengthcharacter_length
FormatStringprintf
Substringsubstr
Upperucase
XPathDoublexpath_number
DayOfMonthday
CurrentTimestampnow
Sizecardinality
Sha1sha
CallMethodViaReflectionjava_method

Note: EqualTo, = and == aliases were excluded because it's unable to leverage this helper method. It should fix the parser.

Note: this PR also excludes some instances such as ToDegrees, ToRadians, UnaryMinus and UnaryPositive that needs an explicit name overwritten to make the scope of this PR smaller.

Why are the changes needed?

To respect expression name.

Does this PR introduce any user-facing change?

Yes, it will change the output column name.

How was this patch tested?

Manually tested, and unittests were added.

@SparkQA

This comment has been minimized.

@HyukjinKwonHyukjinKwon changed the title [SPARK-31146][SQL] Leverage the helper method for aliasing in all SQL expressions [SPARK-31146][SQL] Leverage the helper method for aliasing in built-in SQL expressions Mar 13, 2020
@SparkQA

This comment has been minimized.

@SparkQA

This comment has been minimized.

@dongjoon-hyun

Copy link
Copy Markdown
Member

Retest this please.

select ln(1.2345678e-28)
-- !query schema
struct<LOG(1.2345678E-28):double>
struct<log(1.2345678E-28):double>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have ln instead of log?

@HyukjinKwonHyukjinKwonMar 15, 2020

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually realised that there are some more instances such as ToDegrees, ToRadians, UnaryMinus and UnaryPositive.. let me exclude these to make the scope my PR addresses smaller

@SparkQA

This comment has been minimized.

@dongjoon-hyun

Copy link
Copy Markdown
Member

Oh, R failure is relevant one.

test_sparkSQL.R:1785: failure: column binary mathfunctions
collect(select(df, atan2(df$a, df$b)))[1, "ATAN2(a, b)"] not equal to atan2(1, 5).
target is NULL, current is numeric

@maropu

Copy link
Copy Markdown
Member

Looks nice. For easy trackability in commit logs, could you add a list of the functions (that this PR adds alias flags for) in the PR description?

Comment threadsql/core/src/test/resources/sql-tests/results/postgreSQL/float8.sql.out Outdated
@HyukjinKwon

Copy link
Copy Markdown
MemberAuthor

cc @cloud-fan too - I realised that you touched lots of codes related to this during commit history search.

@SparkQA

This comment has been minimized.

@HyukjinKwon

Copy link
Copy Markdown
MemberAuthor

retest this please

@SparkQA

Copy link
Copy Markdown

Test build #119813 has finished for PR 27901 at commit b3f40a1.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@viiryaviirya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If users code refers the output column name, will such change break user code? Should we update migration guide too?

@HyukjinKwon

Copy link
Copy Markdown
MemberAuthor

I don't think we have made guarantee on the output column name. Also, I would think this is as a rather bug fix. We have already made such changes a lot in the history.

@dongjoon-hyundongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM. Thank you, @HyukjinKwon and all.
Merged to master/3.0.

dongjoon-hyun pushed a commit that referenced this pull request Mar 16, 2020
…n SQL expressions
### What changes were proposed in this pull request?
This PR is kind of a followup of #26808. It leverages the helper method for aliasing in built-in SQL expressions to use the alias as its output column name where it's applicable.
- `Expression`, `UnaryMathExpression` and `BinaryMathExpression` search the alias in the tags by default.
- When the naming is different in its implementation, it has to be overwritten for the expression specifically. E.g., `CallMethodViaReflection`, `Remainder`, `CurrentTimestamp`,
`FormatString` and `XPathDouble`.
This PR fixes the aliases of the functions below:
| class | alias |
|--------------------------|------------------|
|`Rand` |`random` |
|`Ceil` |`ceiling` |
|`Remainder` |`mod` |
|`Pow` |`pow` |
|`Signum` |`sign` |
|`Chr` |`char` |
|`Length` |`char_length` |
|`Length` |`character_length`|
|`FormatString` |`printf` |
|`Substring` |`substr` |
|`Upper` |`ucase` |
|`XPathDouble` |`xpath_number` |
|`DayOfMonth` |`day` |
|`CurrentTimestamp` |`now` |
|`Size` |`cardinality` |
|`Sha1` |`sha` |
|`CallMethodViaReflection` |`java_method` |
Note: `EqualTo`, `=` and `==` aliases were excluded because it's unable to leverage this helper method. It should fix the parser.
Note: this PR also excludes some instances such as `ToDegrees`, `ToRadians`, `UnaryMinus` and `UnaryPositive` that needs an explicit name overwritten to make the scope of this PR smaller.
### Why are the changes needed?
To respect expression name.
### Does this PR introduce any user-facing change?
Yes, it will change the output column name.
### How was this patch tested?
Manually tested, and unittests were added.
Closes#27901 from HyukjinKwon/31146.
Authored-by: HyukjinKwon <gurwls223@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 6704103)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
@HyukjinKwon

Copy link
Copy Markdown
MemberAuthor

Thank you guys!

@gatorsmile

Copy link
Copy Markdown
Member

We need to update the migration guide. This impacts the output schema of SQL queries.

@HyukjinKwon

HyukjinKwon commented Apr 1, 2020

Copy link
Copy Markdown
MemberAuthor

Sure. I am sorry, I rushed to read. I think we haven't documented such output column names in the migration so far, e.g., #26808. Let me leave it out for now.

@HyukjinKwon

Copy link
Copy Markdown
MemberAuthor

And I think we don't also guarantee on output columns names (#27901 (comment)).

sjincho pushed a commit to sjincho/spark that referenced this pull request Apr 15, 2020
…n SQL expressions
### What changes were proposed in this pull request?
This PR is kind of a followup of apache#26808. It leverages the helper method for aliasing in built-in SQL expressions to use the alias as its output column name where it's applicable.
- `Expression`, `UnaryMathExpression` and `BinaryMathExpression` search the alias in the tags by default.
- When the naming is different in its implementation, it has to be overwritten for the expression specifically. E.g., `CallMethodViaReflection`, `Remainder`, `CurrentTimestamp`,
`FormatString` and `XPathDouble`.
This PR fixes the aliases of the functions below:
| class | alias |
|--------------------------|------------------|
|`Rand` |`random` |
|`Ceil` |`ceiling` |
|`Remainder` |`mod` |
|`Pow` |`pow` |
|`Signum` |`sign` |
|`Chr` |`char` |
|`Length` |`char_length` |
|`Length` |`character_length`|
|`FormatString` |`printf` |
|`Substring` |`substr` |
|`Upper` |`ucase` |
|`XPathDouble` |`xpath_number` |
|`DayOfMonth` |`day` |
|`CurrentTimestamp` |`now` |
|`Size` |`cardinality` |
|`Sha1` |`sha` |
|`CallMethodViaReflection` |`java_method` |
Note: `EqualTo`, `=` and `==` aliases were excluded because it's unable to leverage this helper method. It should fix the parser.
Note: this PR also excludes some instances such as `ToDegrees`, `ToRadians`, `UnaryMinus` and `UnaryPositive` that needs an explicit name overwritten to make the scope of this PR smaller.
### Why are the changes needed?
To respect expression name.
### Does this PR introduce any user-facing change?
Yes, it will change the output column name.
### How was this patch tested?
Manually tested, and unittests were added.
Closesapache#27901 from HyukjinKwon/31146.
Authored-by: HyukjinKwon <gurwls223@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
@HyukjinKwon
HyukjinKwon deleted the 31146 branch July 27, 2020 07:45
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@HyukjinKwon@SparkQA@dongjoon-hyun@maropu@gatorsmile@viirya@cloud-fan