Skip to content

Commit 8a5b980

Browse files
authored
YQL: Add seed optional argument to Digest::CityHash() call (#9409)
1 parent 6b6fafa commit 8a5b980

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

ydb/docs/en/core/yql/reference/yql-core/udf/list/digest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A set of commonly used hash functions.
1212
* `Digest::MurMurHash32(String{Flags:AutoMap}) -> Uint32`
1313
* `Digest::MurMurHash2A(String{Flags:AutoMap}) -> Uint64`
1414
* `Digest::MurMurHash2A32(String{Flags:AutoMap}) -> Uint32`
15-
* `Digest::CityHash(String{Flags:AutoMap}) -> Uint64`
15+
* `Digest::CityHash(String{Flags:AutoMap}, [Uint64?]) -> Uint64`: The second optional argument is seed
1616
* `Digest::CityHash128(String{Flags:AutoMap}) -> Tuple<Uint64,Uint64>`
1717
* `Digest::NumericHash(Uint64{Flags:AutoMap}) -> Uint64`
1818
* `Digest::Md5Hex(String{Flags:AutoMap}) -> String`

ydb/docs/ru/core/yql/reference/yql-core/udf/list/digest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* `Digest::MurMurHash32(String{Flags:AutoMap}) -> Uint32`
1616
* `Digest::MurMurHash2A(String{Flags:AutoMap}) -> Uint64`
1717
* `Digest::MurMurHash2A32(String{Flags:AutoMap}) -> Uint32`
18-
* `Digest::CityHash(String{Flags:AutoMap}) -> Uint64`
18+
* `Digest::CityHash(String{Flags:AutoMap}, [Uint64?]) -> Uint64`: Второй опциональный аргумент задает seed
1919
* `Digest::CityHash128(String{Flags:AutoMap}) -> Tuple<Uint64,Uint64>`
2020

2121
CityHash функция для байтовой строки с результатом типа uint128. Результат представлен как пара из двух uint64 чисел `<low, high>`

ydb/library/yql/udfs/common/digest/digest_udf.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,15 @@ namespace {
8282
return TUnboxedValuePod(hash);
8383
}
8484

85-
SIMPLE_STRICT_UDF(TCityHash, ui64(TAutoMap<char*>)) {
85+
SIMPLE_STRICT_UDF_WITH_OPTIONAL_ARGS(TCityHash, ui64(TAutoMap<char*>, TOptional<ui64>), 1) {
8686
Y_UNUSED(valueBuilder);
8787
const auto& inputRef = args[0].AsStringRef();
88-
ui64 hash = CityHash64(inputRef.Data(), inputRef.Size());
88+
ui64 hash;
89+
if (args[1]) {
90+
hash = CityHash64WithSeed(inputRef.Data(), inputRef.Size(), args[1].Get<ui64>());
91+
} else {
92+
hash = CityHash64(inputRef.Data(), inputRef.Size());
93+
}
8994
return TUnboxedValuePod(hash);
9095
}
9196

ydb/library/yql/udfs/common/digest/test/canondata/test.test_Basic_/results.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@
7070
"Uint64"
7171
]
7272
];
73+
[
74+
"cityWithSeed";
75+
[
76+
"DataType";
77+
"Uint64"
78+
]
79+
];
7380
[
7481
"city128";
7582
[
@@ -268,6 +275,7 @@
268275
"5654386555365545660";
269276
"1466639702";
270277
"11413460447292444913";
278+
"684814019408231284";
271279
[
272280
"125830901799957853";
273281
"7569582475522398857"
@@ -326,6 +334,7 @@
326334
"16472888669357673283";
327335
"2351653828";
328336
"17472595041006102391";
337+
"8016373356242392939";
329338
[
330339
"13426016195983081906";
331340
"17051066397148972982"
@@ -384,6 +393,7 @@
384393
"6734453432295282525";
385394
"2128480519";
386395
"11275350073939794026";
396+
"1669883546352889947";
387397
[
388398
"15168680716710346397";
389399
"13490672353767795293"
@@ -442,6 +452,7 @@
442452
"0";
443453
"0";
444454
"11160318154034397263";
455+
"12607432989128692740";
445456
[
446457
"18085479540095642321";
447458
"11079402499652051579"

ydb/library/yql/udfs/common/digest/test/cases/Basic.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ SELECT
99
Digest::MurMurHash2A(key) AS murmur2a,
1010
Digest::MurMurHash2A32(key) AS murmur2a32,
1111
Digest::CityHash(key) AS city,
12+
Digest::CityHash(key, 111) AS cityWithSeed,
1213
Digest::CityHash128(key) AS city128,
1314
Digest::NumericHash(COALESCE(CAST(key AS Uint64), 0)) AS numeric,
1415
Digest::Md5Hex(key) AS md5hex,

0 commit comments

Comments
 (0)