-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-12480][SQL] add Hash expression that can calculate hash value for a group of expressions #10435
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
[SPARK-12480][SQL] add Hash expression that can calculate hash value for a group of expressions #10435
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1863,6 +1863,17 @@ object functions extends LegacyFunctions { | |
| */ | ||
| def crc32(e: Column): Column = withExpr { Crc32(e.expr) } | ||
|
|
||
| /** | ||
| * Calculates the hash code of given columns, and returns the result as a int column. | ||
| * | ||
| * @group misc_funcs | ||
| * @since 2.0 | ||
| */ | ||
| @scala.annotation.varargs | ||
| def hash(col: Column, cols: Column*): Column = withExpr { | ||
|
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. this should just be a single column vararg, rather than one followed by vararg?
Contributor
Author
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. the hash function should take at least one parameter, does
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 use the following form: |
||
| new Murmur3Hash((col +: cols).map(_.expr)) | ||
| } | ||
|
|
||
| ////////////////////////////////////////////////////////////////////////////////////////////// | ||
| // String functions | ||
| ////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
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.
use 42 as default seed, which is same with
UnsafeRow.hashCode, should we make42a constant variable inMurmur3_x86_32?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 this is fine.
Can you file a follow up jira to look at this again? I think we want to remove the projection to unsafe row soon (before we ship this and persist metadata that way). This should be decoupled from unsafe row ideally. For example, if the row is (int, double, string): the generated hash function shoudl be something like
int hash = seed;
hash = murmur3(getInt(0), hash)
hash = murmur3(getDouble(1), hash)
hash = murmur3(getString(2), hash)
return hash
This is likely not the currently computed hash value so can't defer this for too long.