Skip to content

Commit

Permalink
YQL: Add seed optional argument to Digest::CityHash() call (ydb-platf…
Browse files Browse the repository at this point in the history
  • Loading branch information
mxkovalev authored Sep 19, 2024
1 parent 6b6fafa commit 8a5b980
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ydb/docs/en/core/yql/reference/yql-core/udf/list/digest.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A set of commonly used hash functions.
* `Digest::MurMurHash32(String{Flags:AutoMap}) -> Uint32`
* `Digest::MurMurHash2A(String{Flags:AutoMap}) -> Uint64`
* `Digest::MurMurHash2A32(String{Flags:AutoMap}) -> Uint32`
* `Digest::CityHash(String{Flags:AutoMap}) -> Uint64`
* `Digest::CityHash(String{Flags:AutoMap}, [Uint64?]) -> Uint64`: The second optional argument is seed
* `Digest::CityHash128(String{Flags:AutoMap}) -> Tuple<Uint64,Uint64>`
* `Digest::NumericHash(Uint64{Flags:AutoMap}) -> Uint64`
* `Digest::Md5Hex(String{Flags:AutoMap}) -> String`
Expand Down
2 changes: 1 addition & 1 deletion ydb/docs/ru/core/yql/reference/yql-core/udf/list/digest.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* `Digest::MurMurHash32(String{Flags:AutoMap}) -> Uint32`
* `Digest::MurMurHash2A(String{Flags:AutoMap}) -> Uint64`
* `Digest::MurMurHash2A32(String{Flags:AutoMap}) -> Uint32`
* `Digest::CityHash(String{Flags:AutoMap}) -> Uint64`
* `Digest::CityHash(String{Flags:AutoMap}, [Uint64?]) -> Uint64`: Второй опциональный аргумент задает seed
* `Digest::CityHash128(String{Flags:AutoMap}) -> Tuple<Uint64,Uint64>`

CityHash функция для байтовой строки с результатом типа uint128. Результат представлен как пара из двух uint64 чисел `<low, high>`
Expand Down
9 changes: 7 additions & 2 deletions ydb/library/yql/udfs/common/digest/digest_udf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ namespace {
return TUnboxedValuePod(hash);
}

SIMPLE_STRICT_UDF(TCityHash, ui64(TAutoMap<char*>)) {
SIMPLE_STRICT_UDF_WITH_OPTIONAL_ARGS(TCityHash, ui64(TAutoMap<char*>, TOptional<ui64>), 1) {
Y_UNUSED(valueBuilder);
const auto& inputRef = args[0].AsStringRef();
ui64 hash = CityHash64(inputRef.Data(), inputRef.Size());
ui64 hash;
if (args[1]) {
hash = CityHash64WithSeed(inputRef.Data(), inputRef.Size(), args[1].Get<ui64>());
} else {
hash = CityHash64(inputRef.Data(), inputRef.Size());
}
return TUnboxedValuePod(hash);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@
"Uint64"
]
];
[
"cityWithSeed";
[
"DataType";
"Uint64"
]
];
[
"city128";
[
Expand Down Expand Up @@ -268,6 +275,7 @@
"5654386555365545660";
"1466639702";
"11413460447292444913";
"684814019408231284";
[
"125830901799957853";
"7569582475522398857"
Expand Down Expand Up @@ -326,6 +334,7 @@
"16472888669357673283";
"2351653828";
"17472595041006102391";
"8016373356242392939";
[
"13426016195983081906";
"17051066397148972982"
Expand Down Expand Up @@ -384,6 +393,7 @@
"6734453432295282525";
"2128480519";
"11275350073939794026";
"1669883546352889947";
[
"15168680716710346397";
"13490672353767795293"
Expand Down Expand Up @@ -442,6 +452,7 @@
"0";
"0";
"11160318154034397263";
"12607432989128692740";
[
"18085479540095642321";
"11079402499652051579"
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/udfs/common/digest/test/cases/Basic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SELECT
Digest::MurMurHash2A(key) AS murmur2a,
Digest::MurMurHash2A32(key) AS murmur2a32,
Digest::CityHash(key) AS city,
Digest::CityHash(key, 111) AS cityWithSeed,
Digest::CityHash128(key) AS city128,
Digest::NumericHash(COALESCE(CAST(key AS Uint64), 0)) AS numeric,
Digest::Md5Hex(key) AS md5hex,
Expand Down

0 comments on commit 8a5b980

Please sign in to comment.