Skip to content

Commit cf85134

Browse files
authored
YQL-20425: Move RH Hash Map to new api (#26412)
1 parent e7b879f commit cf85134

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

ydb/core/kqp/tools/combiner_perf/hashmaps.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,23 @@ struct TRobinHoodMapImplBase
4242
bool isNew = false;
4343
auto ptr = map.Insert(key, isNew);
4444
if (isNew) {
45+
#if defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
46+
auto* payloadPtr = map.GetMutablePayloadPtr(ptr);
47+
WriteUnaligned<V>(payloadPtr, delta);
48+
#else
4549
*(V*)map.GetMutablePayload(ptr) = delta;
50+
#endif // defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
4651
map.CheckGrow();
4752
} else {
53+
#if defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
54+
auto* payloadPtr = map.GetMutablePayloadPtr(ptr);
55+
auto newValue =
56+
ReadUnaligned<V>(payloadPtr);
57+
newValue += delta;
58+
WriteUnaligned<V>(payloadPtr, newValue);
59+
#else
4860
*(V*)map.GetMutablePayload(ptr) += delta;
61+
#endif // defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
4962
}
5063
}
5164

@@ -55,20 +68,36 @@ struct TRobinHoodMapImplBase
5568
if (existingPtr == nullptr) {
5669
return;
5770
}
71+
#if defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
72+
auto* payloadPtr = map.GetMutablePayloadPtr(existingPtr);
73+
auto newValue =
74+
ReadUnaligned<V>(payloadPtr);
75+
newValue += delta;
76+
WriteUnaligned<V>(payloadPtr, newValue);
77+
#else
5878
*(V*)map.GetMutablePayload(existingPtr) += delta;
79+
#endif // defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
5980
}
6081

6182
template<typename Callback>
6283
static void IteratePairs(const TMapType& map, Callback&& callback)
6384
{
64-
// TODO: GetPayload and IsValid should be const
6585
for (const char* iter = map.Begin(); iter != map.End(); map.Advance(iter)) {
86+
#if defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
87+
if (!map.IsValid(iter)) {
88+
continue;
89+
}
90+
const auto& key = map.GetKeyValue(iter);
91+
const auto& value = ReadUnaligned<V>(map.GetPayloadPtr(iter));
92+
callback(key, value);
93+
#else
6694
if (!const_cast<TMapType&>(map).IsValid(iter)) {
6795
continue;
6896
}
6997
const auto& key = map.GetKey(iter);
7098
const auto& value = *(V*)(const_cast<TMapType&>(map)).GetPayload(iter);
7199
callback(key, value);
100+
#endif // defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
72101
}
73102
}
74103

ydb/library/formats/arrow/replace_key.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class TReplaceKeyTemplate {
6767
}
6868
return result;
6969
}
70+
TReplaceKeyTemplate() = default;
7071

7172
TReplaceKeyTemplate(TArrayVecPtr columns, const ui64 position)
7273
: Columns(columns)
@@ -334,6 +335,8 @@ class TReplaceKeyHashable: public TReplaceKeyTemplate<const TArrayVec*> {
334335
}
335336
}
336337

338+
TReplaceKeyHashable() = default;
339+
337340
TReplaceKeyHashable(
338341
const std::vector<std::shared_ptr<arrow::Array>>& columns, const ui64 position, const std::vector<arrow::Type::type>& types)
339342
: TBase(&columns, position)

ydb/library/yql/dq/comp_nodes/dq_hash_combine.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,11 @@ class TBaseAggregationState: public TComputationValue<TBaseAggregationState>
347347
if (isNew) {
348348
statePtr = static_cast<char *>(KeyStateBuffer) + StatesOffset;
349349
} else {
350+
#if defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
351+
TUnboxedValuePod* mapKeyPtr = Map->GetKeyValue(mapIt);
352+
#else
350353
TUnboxedValuePod* mapKeyPtr = Map->GetKey(mapIt);
354+
#endif // defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
351355
statePtr = reinterpret_cast<char *>(mapKeyPtr) + StatesOffset;
352356
}
353357

@@ -495,7 +499,11 @@ class TBaseAggregationState: public TComputationValue<TBaseAggregationState>
495499
if (!Map->IsValid(mapIter)) {
496500
continue;
497501
}
502+
#if defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
503+
auto* entry = Map->GetKeyValue(mapIter);
504+
#else
498505
auto* entry = Map->GetKey(mapIter);
506+
#endif // defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
499507
auto entryMem = MemoryHelper.EstimateKeySize(entry);
500508
if (!entryMem.has_value()) {
501509
unbounded = true;
@@ -681,7 +689,11 @@ class TWideAggregationState: public TBaseAggregationState
681689
return false;
682690
}
683691

692+
#if defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
693+
const auto key = Map->GetKeyValue(DrainMapIterator);
694+
#else
684695
const auto key = Map->GetKey(DrainMapIterator);
696+
#endif // defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
685697

686698
if (HasGenericAggregation) {
687699
auto keyIter = key;
@@ -726,7 +738,11 @@ class TWideAggregationState: public TBaseAggregationState
726738
if (!Map->IsValid(DrainMapIterator)) {
727739
continue;
728740
}
741+
#if defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
742+
const auto key = Map->GetKeyValue(DrainMapIterator);
743+
#else
729744
const auto key = Map->GetKey(DrainMapIterator);
745+
#endif // defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
730746
char* statePtr = static_cast<char *>(static_cast<void *>(key)) + StatesOffset;
731747
for (auto& agg : Aggs) {
732748
agg->ForgetState(statePtr);
@@ -936,7 +952,11 @@ class TBlockAggregationState: public TBaseAggregationState
936952
continue;
937953
}
938954

955+
#if defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
956+
const auto key = Map->GetKeyValue(DrainMapIterator);
957+
#else
939958
const auto key = Map->GetKey(DrainMapIterator);
959+
#endif // defined(MKQL_RH_HASH_MOVE_API_TO_NEW_VERSION)
940960
if (HasGenericAggregation) {
941961
auto keyIter = key;
942962
for (ui32 i = 0U; i < Nodes.FinishKeyNodes.size(); ++i) {

0 commit comments

Comments
 (0)