-
Couldn't load subscription status.
- Fork 28.9k
[SPARK-8269][SQL]string function: initcap #7208
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
8 commits
Select commit
Hold shift + click to select a range
7ce416b
support initcap rebase code
hujy c79482d
support soundex
hujy 6a0b958
add column
hujy 7e0c604
Merge branch 'master' of https://github.com/apache/spark into initcap
hujy 1f5a0ef
add codegen
hujy b616c0e
add python api
hujy 2cd43e5
fix python style check
hujy 8b2506a
Update functions.py
hujy 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1752,6 +1752,24 @@ object functions { | |
| FormatString((lit(format) +: arguments).map(_.expr): _*) | ||
| } | ||
|
|
||
| /** | ||
| * Returns string, with the first letter of each word in uppercase, | ||
| * all other letters in lowercase. Words are delimited by whitespace. | ||
| * | ||
| * @group string_funcs | ||
| * @since 1.5.0 | ||
| */ | ||
| def initcap(e: Column): Column = InitCap(e.expr) | ||
|
|
||
| /** | ||
| * Returns string, with the first letter of each word in uppercase, | ||
| * all other letters in lowercase. Words are delimited by whitespace. | ||
| * | ||
| * @group string_funcs | ||
| * @since 1.5.0 | ||
| */ | ||
| def initcap(columnName: String): Column = initcap(Column(columnName)) | ||
|
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. As @rxin made some clean up for the DF function, we'd better remove the |
||
|
|
||
| /** | ||
| * Locate the position of the first occurrence of substr column in the given string. | ||
| * Returns null if either of the arguments are null. | ||
|
|
||
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
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.
I think we should consider implement all of this on bytes directly. The conversion to
Charisn't safe. I'm not sure, what happens if a character doesn't fit intoChar. Using the assumption that a lower case and a upper case character have always the same number of bytes, we could easily useArray[Byte]. Even tough this isn't guaranteed by Unicode it seems to be true (maybe we could propose this to Unicode). But we can do this in a follow up PR.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.
My idea would be that we check if the next character fits
Char. If yes we convert it to Char, callCharacter.toUpperCase(c)and change the result int the array. If we cannot convert it to Char, we "ignore" it and don't change it. But as Reynold mentioned, we can do this in a second step.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 conversion from byte to char will cause some extra efforts. We can do it directly on bytes(like code below). However, I cannot assure I have the total number-letter table of all Europe special letters.
i = value of Ñ;
} // Ññ