Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ydb/library/yql/dq/runtime/dq_output_consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ using namespace NKikimr;
using namespace NMiniKQL;
using namespace NUdf;

inline ui64 SpreadHash(ui64 hash) {
// https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/
return ((unsigned __int128)hash * 11400714819323198485llu) >> 64;
}


class TDqOutputMultiConsumer : public IDqOutputConsumer {
public:
Expand Down Expand Up @@ -189,6 +194,9 @@ class TDqOutputHashPartitionConsumer : public IDqOutputConsumer {
hash = CombineHashes(hash, HashColumn(keyId, columnValue));
}


hash = SpreadHash(hash);

return hash % Outputs.size();
}

Expand All @@ -200,6 +208,8 @@ class TDqOutputHashPartitionConsumer : public IDqOutputConsumer {
hash = CombineHashes(hash, HashColumn(keyId, values[KeyColumns[keyId].Index]));
}

hash = SpreadHash(hash);

return hash % Outputs.size();
}

Expand Down Expand Up @@ -303,6 +313,8 @@ class TDqOutputHashPartitionConsumerScalar : public IDqOutputConsumer {
hash = CombineHashes(hash, HashColumn(keyId, values[KeyColumns_[keyId].Index]));
}

hash = SpreadHash(hash);

return hash % Outputs_.size();
}

Expand Down Expand Up @@ -500,6 +512,9 @@ class TDqOutputHashPartitionConsumerBlock : public IDqOutputConsumer {
}
hash = CombineHashes(hash, keyHash);
}

hash = SpreadHash(hash);

return hash % Outputs_.size();
}

Expand Down