Skip to content

Commit c34e8e2

Browse files
authored
ESQL Add esql hash function (elastic#117989) (elastic#118927)
This change introduces esql hash(alg, input) function that relies on the Java MessageDigest to compute the hash.
1 parent 222627c commit c34e8e2

File tree

21 files changed

+991
-2
lines changed

21 files changed

+991
-2
lines changed

docs/changelog/117989.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 117989
2+
summary: ESQL Add esql hash function
3+
area: ES|QL
4+
type: enhancement
5+
issues: []

docs/reference/esql/functions/description/hash.asciidoc

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/kibana/definition/hash.json

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/kibana/docs/hash.md

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/layout/hash.asciidoc

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/parameters/hash.asciidoc

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/signature/hash.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/reference/esql/functions/string-functions.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* <<esql-concat>>
1414
* <<esql-ends_with>>
1515
* <<esql-from_base64>>
16+
* <<esql-hash>>
1617
* <<esql-left>>
1718
* <<esql-length>>
1819
* <<esql-locate>>
@@ -37,6 +38,7 @@ include::layout/byte_length.asciidoc[]
3738
include::layout/concat.asciidoc[]
3839
include::layout/ends_with.asciidoc[]
3940
include::layout/from_base64.asciidoc[]
41+
include::layout/hash.asciidoc[]
4042
include::layout/left.asciidoc[]
4143
include::layout/length.asciidoc[]
4244
include::layout/locate.asciidoc[]

docs/reference/esql/functions/types/hash.asciidoc

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
hash
2+
required_capability: hash_function
3+
4+
FROM sample_data
5+
| WHERE message != "Connection error"
6+
| EVAL md5 = hash("md5", message), sha256 = hash("sha256", message)
7+
| KEEP message, md5, sha256;
8+
ignoreOrder:true
9+
10+
message:keyword | md5:keyword | sha256:keyword
11+
Connected to 10.1.0.1 | abd7d1ce2bb636842a29246b3512dcae | 6d8372129ad78770f7185554dd39864749a62690216460752d6c075fa38ad85c
12+
Connected to 10.1.0.2 | 8f8f1cb60832d153f5b9ec6dc828b93f | b0db24720f15857091b3c99f4c4833586d0ea3229911b8777efb8d917cf27e9a
13+
Connected to 10.1.0.3 | 912b6dc13503165a15de43304bb77c78 | 75b0480188db8acc4d5cc666a51227eb2bc5b989cd8ca912609f33e0846eff57
14+
Disconnected | ef70e46fd3bbc21e3e1f0b6815e750c0 | 04dfac3671b494ad53fcd152f7a14511bfb35747278aad8ce254a0d6e4ba4718
15+
;
16+
17+
18+
hashOfConvertedType
19+
required_capability: hash_function
20+
21+
FROM sample_data
22+
| WHERE message != "Connection error"
23+
| EVAL input = event_duration::STRING, md5 = hash("md5", input), sha256 = hash("sha256", input)
24+
| KEEP message, input, md5, sha256;
25+
ignoreOrder:true
26+
27+
message:keyword | input:keyword | md5:keyword | sha256:keyword
28+
Connected to 10.1.0.1 | 1756467 | c4fc1c57ee9b1d2b2023b70c8c167b54 | 8376a50a7ba7e6bd1bf9ad0c32d27d2f49fd0fa422573f98f239e21048b078f3
29+
Connected to 10.1.0.2 | 2764889 | 8e8cf005e11a7b5df1d9478a4715a444 | 1031f2bef8eaecbf47319505422300b27ea1f7c38b6717d41332325062f9a56a
30+
Connected to 10.1.0.3 | 3450233 | 09f2c64f5a55e9edf8ffbad336b561d8 | f77d7545769c4ecc85092f4f0b7ec8c20f467e4beb15fe67ca29f9aa8e9a6900
31+
Disconnected | 1232382 | 6beac1485638d51e13c2c53990a2f611 | 9a03c1274a3ebb6c1cb85d170ce0a6fdb9d2232724e06b9f5e7cb9274af3cad6
32+
;
33+
34+
35+
hashOfEmptyInput
36+
required_capability: hash_function
37+
38+
ROW input="" | EVAL md5 = hash("md5", input), sha256 = hash("sha256", input);
39+
40+
input:keyword | md5:keyword | sha256:keyword
41+
| d41d8cd98f00b204e9800998ecf8427e | e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
42+
;
43+
44+
hashOfNullInput
45+
required_capability: hash_function
46+
47+
ROW input=null::STRING | EVAL md5 = hash("md5", input), sha256 = hash("sha256", input);
48+
49+
input:keyword | md5:keyword | sha256:keyword
50+
null | null | null
51+
;
52+
53+
54+
hashWithNullAlgorithm
55+
required_capability: hash_function
56+
57+
ROW input="input" | EVAL hash = hash(null, input);
58+
59+
input:keyword | hash:keyword
60+
input | null
61+
;
62+
63+
64+
hashWithMv
65+
required_capability: hash_function
66+
67+
ROW input=["foo", "bar"] | mv_expand input | EVAL md5 = hash("md5", input), sha256 = hash("sha256", input);
68+
69+
input:keyword | md5:keyword | sha256:keyword
70+
foo | acbd18db4cc2f85cedef654fccc4a4d8 | 2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae
71+
bar | 37b51d194a7513e45b56f6524f2d51f2 | fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9
72+
;
73+
74+
75+
hashWithNestedFunctions
76+
required_capability: hash_function
77+
78+
ROW input=["foo", "bar"] | EVAL hash = concat(hash("md5", mv_concat(input, "-")), "-", hash("sha256", mv_concat(input, "-")));
79+
80+
input:keyword | hash:keyword
81+
["foo", "bar"] | e5f9ec048d1dbe19c70f720e002f9cb1-7d89c4f517e3bd4b5e8e76687937005b602ea00c5cba3e25ef1fc6575a55103e
82+
;
83+
84+
85+
hashWithConvertedTypes
86+
required_capability: hash_function
87+
88+
ROW input=42 | EVAL md5 = hash("md5", input::STRING), sha256 = hash("sha256", to_string(input));
89+
90+
input:integer | md5:keyword | sha256:keyword
91+
42 | a1d0c6e83f027327d8461063f4ac58a6 | 73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049
92+
;
93+
94+
95+
hashWithStats
96+
required_capability: hash_function
97+
98+
FROM sample_data
99+
| EVAL md5="md5"
100+
| STATS count = count(*) by hash(md5, message)
101+
| WHERE count > 1;
102+
103+
count:long | hash(md5, message):keyword
104+
3 | 2e92ae79ff32b37fee4368a594792183
105+
;

0 commit comments

Comments
 (0)