-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Hash functions #118938
Hash functions #118938
Conversation
Documentation preview: |
Pinging @elastic/es-analytical-engine (Team:Analytics) |
Hi @idegtiarenko, I've created a changelog YAML for you. |
While this is open we might add couple more functions as well. This digests are defined and used in ES: elasticsearch/server/src/main/java/org/elasticsearch/common/hash/MessageDigests.java Lines 41 to 44 in a59c182
Following algorithms seems to be available in several JVMs I checked:
|
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.
Looks good!
|
||
private static final HashFunction MD5 = HashFunction.create("MD5"); | ||
|
||
@FunctionInfo(returnType = "keyword", description = "Computes MD5 hash of the input.") |
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.
We can add the md5Hash
test as an examples = @Example(...)
here
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.
👍
|
||
@Override | ||
public Expression replaceChildren(List<Expression> newChildren) { | ||
return new Md5(source(), field); |
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.
return new Md5(source(), field); | |
return new Md5(source(), newChildren.get(0)); |
Edit: Oh, looks like EsqlNodeSubclassTests.testReplaceChildren
failed successfully with this in CI
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.
👍
|
||
private static final HashFunction MD5 = HashFunction.create("MD5"); | ||
|
||
@FunctionInfo(returnType = "keyword", description = "Computes MD5 hash of the input.") |
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.
@FunctionInfo(returnType = "keyword", description = "Computes MD5 hash of the input.") | |
@FunctionInfo(returnType = "keyword", description = "Computes the MD5 hash of the input.") |
@@ -87,12 +87,28 @@ private static TestCaseSupplier createTestCase(String algorithm, boolean forceLi | |||
}); | |||
} | |||
|
|||
static List<TestCaseSupplier> createHashFunctionTestCases(String algorithm) { | |||
return List.of(createHashFunctionTestCase(algorithm, DataType.KEYWORD), createHashFunctionTestCase(algorithm, DataType.TEXT)); |
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 use TestCaseSupplier.forUnaryStrings(...)
instead of manually creating the TestCaseSupplier
s. It will also take care of both KEYWORD and TEXT types
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 would add some extra test cases, to double check both the:
- One with a FROM command
- Something like
FROM x | EVAL input = "...", hash = MD5(input)
? Trying to "break" thereplaceChildren()
comment bug with it MD5(123::keyword)
- Maybe having MD5() as a STATS grouping
|
||
private static final HashFunction MD5 = HashFunction.create("MD5"); | ||
|
||
@FunctionInfo(returnType = "keyword", description = "Computes MD5 hash of the input.") |
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.
👍
|
||
@Override | ||
public Expression replaceChildren(List<Expression> newChildren) { | ||
return new Md5(source(), field); |
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.
👍
Let's get this in - this will be handy for security queries! |
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.
LGTM. Could you link the other new hash functions in? Maybe add an example for them?
@@ -43,6 +43,7 @@ include::layout/left.asciidoc[] | |||
include::layout/length.asciidoc[] | |||
include::layout/locate.asciidoc[] | |||
include::layout/ltrim.asciidoc[] | |||
include::layout/md5.asciidoc[] |
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.
Can you link the other new functions?
💚 Backport successful
|
This change adds md5, sha1 and sha256 hash functions.
This change adds infrastructure to add more hash functions easier as well as
md5
implementation to demonstrate it.