diff options
| author | vvvv <[email protected]> | 2025-10-09 12:25:18 +0300 |
|---|---|---|
| committer | vvvv <[email protected]> | 2025-10-09 12:57:17 +0300 |
| commit | cb77d014972b2cdb27d2e6d979fc3a2772b27ad4 (patch) | |
| tree | 7f3bcd8ce71c6bd0f3ccc11e31b9f665475b819e /yql/essentials/minikql/computation/mkql_computation_node_impl.h | |
| parent | d58a8990d353b051c27e1069141117fdfde64358 (diff) | |
YQL-20086 minikql
commit_hash:e96f7390db5fcbe7e9f64f898141a263ad522daa
Diffstat (limited to 'yql/essentials/minikql/computation/mkql_computation_node_impl.h')
| -rw-r--r-- | yql/essentials/minikql/computation/mkql_computation_node_impl.h | 406 |
1 files changed, 255 insertions, 151 deletions
diff --git a/yql/essentials/minikql/computation/mkql_computation_node_impl.h b/yql/essentials/minikql/computation/mkql_computation_node_impl.h index e406df2e46d..0a1d3fd05d8 100644 --- a/yql/essentials/minikql/computation/mkql_computation_node_impl.h +++ b/yql/essentials/minikql/computation/mkql_computation_node_impl.h @@ -22,7 +22,7 @@ enum class EContainerOptMode { }; template <class IComputationNodeInterface> -class TRefCountedComputationNode : public IComputationNodeInterface { +class TRefCountedComputationNode: public IComputationNodeInterface { private: void Ref() final; @@ -34,15 +34,15 @@ private: ui32 Refs_ = 0; }; -class TUnboxedImmutableComputationNode: public TRefCountedComputationNode<IComputationNode> -{ +class TUnboxedImmutableComputationNode: public TRefCountedComputationNode<IComputationNode> { public: TUnboxedImmutableComputationNode(TMemoryUsageInfo* memInfo, NUdf::TUnboxedValue&& value); ~TUnboxedImmutableComputationNode() override; private: - void InitNode(TComputationContext&) const override {} + void InitNode(TComputationContext&) const override { + } NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const final; @@ -69,7 +69,8 @@ private: EValueRepresentation GetRepresentation() const final; - TMemoryUsageInfo *const MemInfo_; + TMemoryUsageInfo* const MemInfo_; + protected: const NUdf::TUnboxedValue UnboxedValue_; const EValueRepresentation RepresentationKind_; @@ -81,7 +82,7 @@ protected: ~TStatefulComputationNodeBase(); void AddDependenceImpl(const IComputationNode* node); void CollectDependentIndexesImpl(const IComputationNode* self, const IComputationNode* owner, - IComputationNode::TIndexesMap& dependencies, bool stateless) const; + IComputationNode::TIndexesMap& dependencies, bool stateless) const; TConstComputationNodePtrVector Dependencies_; @@ -90,8 +91,7 @@ protected: }; template <class IComputationNodeInterface, bool SerializableState = false> -class TStatefulComputationNode: public TRefCountedComputationNode<IComputationNodeInterface>, protected TStatefulComputationNodeBase -{ +class TStatefulComputationNode: public TRefCountedComputationNode<IComputationNodeInterface>, protected TStatefulComputationNodeBase { protected: TStatefulComputationNode(TComputationMutables& mutables, EValueRepresentation kind); @@ -112,19 +112,18 @@ private: ui32 GetDependencesCount() const final; }; -class TExternalComputationNode: public TStatefulComputationNode<IComputationExternalNode> -{ +class TExternalComputationNode: public TStatefulComputationNode<IComputationExternalNode> { public: TExternalComputationNode(TComputationMutables& mutables, EValueRepresentation kind = EValueRepresentation::Any); protected: - NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const override; NUdf::TUnboxedValue& RefValue(TComputationContext& compCtx) const override; void SetValue(TComputationContext& compCtx, NUdf::TUnboxedValue&& value) const override; TString DebugString() const final; + private: ui32 GetDependencyWeight() const final; @@ -146,6 +145,7 @@ private: void InvalidateValue(TComputationContext& compCtx) const final; const IComputationNode* GetSource() const final; + protected: std::vector<std::pair<ui32, EValueRepresentation>> InvalidationSet_; TGetter Getter_; @@ -164,9 +164,9 @@ protected: template <typename TDerived, bool SerializableState = false> class TStatefulSourceComputationNode: public TStatefulComputationNode<IComputationNode, SerializableState>, - protected TStatefulSourceComputationNodeBase -{ + protected TStatefulSourceComputationNodeBase { using TStatefulComputationNode = TStatefulComputationNode<IComputationNode, SerializableState>; + private: bool IsTemporaryValue() const final { return *Stateless_; @@ -180,17 +180,22 @@ private: PrepareStageOneImpl(this->Dependencies_); } - void PrepareStageTwo() final {} + void PrepareStageTwo() final { + } void CollectDependentIndexes(const IComputationNode* owner, IComputationNode::TIndexesMap& dependencies) const final { this->CollectDependentIndexesImpl(this, owner, dependencies, *Stateless_); } - const IComputationNode* GetSource() const final { return this; } + const IComputationNode* GetSource() const final { + return this; + } + protected: TStatefulSourceComputationNode(TComputationMutables& mutables, EValueRepresentation kind = EValueRepresentation::Any) : TStatefulComputationNode(mutables, kind) - {} + { + } void DependsOn(IComputationNode* node) const { if (node) { @@ -217,8 +222,9 @@ protected: using TStatefulSourceComputationNode<TDerived>::TStatefulSourceComputationNode; NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const override { - if (*this->Stateless_) + if (*this->Stateless_) { return static_cast<const TDerived*>(this)->DoCalculate(compCtx); + } NUdf::TUnboxedValue& valueRef = this->ValueRef(compCtx); if (valueRef.IsInvalid()) { valueRef = static_cast<const TDerived*>(this)->DoCalculate(compCtx); @@ -229,13 +235,14 @@ protected: }; template <typename TDerived, typename IFlowInterface> -class TFlowSourceBaseComputationNode: public TStatefulComputationNode<IFlowInterface> -{ +class TFlowSourceBaseComputationNode: public TStatefulComputationNode<IFlowInterface> { using TBase = TStatefulComputationNode<IFlowInterface>; + protected: TFlowSourceBaseComputationNode(TComputationMutables& mutables, EValueRepresentation stateKind) : TBase(mutables, stateKind) - {} + { + } TString DebugString() const override { return TypeName<TDerived>(); @@ -254,6 +261,7 @@ protected: node->SetOwner(this); } } + private: bool IsTemporaryValue() const final { return true; @@ -267,22 +275,28 @@ private: this->CollectDependentIndexesImpl(this, owner, dependencies, false); } - void PrepareStageOne() final {} - void PrepareStageTwo() final {} + void PrepareStageOne() final { + } + void PrepareStageTwo() final { + } - const IComputationNode* GetSource() const final { return this; } + const IComputationNode* GetSource() const final { + return this; + } mutable std::unordered_set<const IComputationNode*> Sources_; // TODO: remove const and mutable. }; template <typename TDerived> -class TFlowSourceComputationNode: public TFlowSourceBaseComputationNode<TDerived, IComputationNode> -{ +class TFlowSourceComputationNode: public TFlowSourceBaseComputationNode<TDerived, IComputationNode> { using TBase = TFlowSourceBaseComputationNode<TDerived, IComputationNode>; + protected: TFlowSourceComputationNode(TComputationMutables& mutables, EValueRepresentation kind, EValueRepresentation stateKind) - : TBase(mutables, stateKind), RepresentationKind_(kind) - {} + : TBase(mutables, stateKind) + , RepresentationKind_(kind) + { + } private: EValueRepresentation GetRepresentation() const final { @@ -292,18 +306,21 @@ private: NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const final { return static_cast<const TDerived*>(this)->DoCalculate(this->ValueRef(compCtx), compCtx); } + private: const EValueRepresentation RepresentationKind_; }; template <typename TDerived> -class TWideFlowSourceComputationNode: public TFlowSourceBaseComputationNode<TDerived, IComputationWideFlowNode> -{ +class TWideFlowSourceComputationNode: public TFlowSourceBaseComputationNode<TDerived, IComputationWideFlowNode> { using TBase = TFlowSourceBaseComputationNode<TDerived, IComputationWideFlowNode>; + protected: TWideFlowSourceComputationNode(TComputationMutables& mutables, EValueRepresentation stateKind) : TBase(mutables, stateKind) - {} + { + } + private: EValueRepresentation GetRepresentation() const final { THROW yexception() << "Failed to get representation kind."; @@ -313,18 +330,21 @@ private: THROW yexception() << "Failed to get value from wide flow node."; } - EFetchResult FetchValues(TComputationContext& compCtx, NUdf::TUnboxedValue*const* values) const final { + EFetchResult FetchValues(TComputationContext& compCtx, NUdf::TUnboxedValue* const* values) const final { return static_cast<const TDerived*>(this)->DoCalculate(this->ValueRef(compCtx), compCtx, values); } }; template <typename TDerived, typename IFlowInterface> -class TFlowBaseComputationNode: public TRefCountedComputationNode<IFlowInterface> -{ +class TFlowBaseComputationNode: public TRefCountedComputationNode<IFlowInterface> { protected: - TFlowBaseComputationNode(const IComputationNode* source) : Source_(source) {} + TFlowBaseComputationNode(const IComputationNode* source) + : Source_(source) + { + } - void InitNode(TComputationContext&) const override {} + void InitNode(TComputationContext&) const override { + } TString DebugString() const override { return TypeName<TDerived>(); @@ -332,10 +352,13 @@ protected: IComputationNode* FlowDependsOn(IComputationNode* node) const { if (node) { - if (const auto source = node->AddDependence(this); dynamic_cast<IComputationExternalNode*>(source) || dynamic_cast<IComputationWideFlowProxyNode*>(source)) + if (const auto source = node->AddDependence(this); + dynamic_cast<IComputationExternalNode*>(source) || + dynamic_cast<IComputationWideFlowProxyNode*>(source)) { return const_cast<IComputationNode*>(static_cast<const IComputationNode*>(this)); // TODO: remove const in RegisterDependencies. - else + } else { return source; + } } return nullptr; } @@ -344,8 +367,9 @@ protected: const auto flowOne = FlowDependsOn(one); const auto flowTwo = FlowDependsOn(two); if (flowOne && flowTwo) { - if (flowOne == flowTwo) + if (flowOne == flowTwo) { return flowOne; + } const auto flow = const_cast<IComputationNode*>(static_cast<const IComputationNode*>(this)); DependsOn(flow, flowOne); DependsOn(flow, flowTwo); @@ -361,13 +385,16 @@ protected: IComputationNode* FlowDependsOnAll(const std::vector<IFlowInterface*, TMKQLAllocator<IFlowInterface*>>& sources) const { std::unordered_set<IComputationNode*> flows(sources.size()); - for (const auto& source : sources) - if (const auto flow = FlowDependsOn(source)) + for (const auto& source : sources) { + if (const auto flow = FlowDependsOn(source)) { flows.emplace(flow); + } + } if (flows.size() > 1U) { const auto flow = const_cast<IComputationNode*>(static_cast<const IComputationNode*>(this)); - std::for_each(flows.cbegin(), flows.cend(), std::bind(&TFlowBaseComputationNode::DependsOn, flow, std::placeholders::_1)); + std::for_each(flows.cbegin(), flows.cend(), + std::bind(&TFlowBaseComputationNode::DependsOn, flow, std::placeholders::_1)); return flow; } @@ -391,8 +418,11 @@ protected: node->SetOwner(source); } } + private: - ui32 GetDependencyWeight() const final { return 42U; } + ui32 GetDependencyWeight() const final { + return 42U; + } ui32 GetDependencesCount() const final { return Dependences_.size(); @@ -407,27 +437,34 @@ private: return true; } - void PrepareStageOne() final {} - void PrepareStageTwo() final {} + void PrepareStageOne() final { + } + void PrepareStageTwo() final { + } const IComputationNode* GetSource() const final { - if (Source_ && Source_ != this) - if (const auto s = Source_->GetSource()) + if (Source_ && Source_ != this) { + if (const auto s = Source_->GetSource()) { return s; + } + } return this; } + protected: - const IComputationNode *const Source_; + const IComputationNode* const Source_; TConstComputationNodePtrVector Dependences_; }; template <typename TDerived> -class TBaseFlowBaseComputationNode: public TFlowBaseComputationNode<TDerived, IComputationNode> -{ +class TBaseFlowBaseComputationNode: public TFlowBaseComputationNode<TDerived, IComputationNode> { protected: TBaseFlowBaseComputationNode(const IComputationNode* source, EValueRepresentation kind) - : TFlowBaseComputationNode<TDerived, IComputationNode>(source), RepresentationKind_(kind) - {} + : TFlowBaseComputationNode<TDerived, IComputationNode>(source) + , RepresentationKind_(kind) + { + } + private: EValueRepresentation GetRepresentation() const final { return RepresentationKind_; @@ -440,25 +477,27 @@ class TStatelessFlowComputationNodeBase { protected: ui32 GetIndexImpl() const; void CollectDependentIndexesImpl(const IComputationNode* self, - const IComputationNode* owner, IComputationNode::TIndexesMap& dependencies, - const TConstComputationNodePtrVector& dependences) const; + const IComputationNode* owner, IComputationNode::TIndexesMap& dependencies, + const TConstComputationNodePtrVector& dependences) const; }; template <typename TDerived> -class TStatelessFlowComputationNode: public TBaseFlowBaseComputationNode<TDerived>, protected TStatelessFlowComputationNodeBase -{ +class TStatelessFlowComputationNode: public TBaseFlowBaseComputationNode<TDerived>, protected TStatelessFlowComputationNodeBase { protected: TStatelessFlowComputationNode(const IComputationNode* source, EValueRepresentation kind) : TBaseFlowBaseComputationNode<TDerived>(source, kind) - {} + { + } TStatelessFlowComputationNode(TComputationMutables&, const IComputationNode* source, EValueRepresentation kind) : TBaseFlowBaseComputationNode<TDerived>(source, kind) - {} + { + } NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const override { return static_cast<const TDerived*>(this)->DoCalculate(compCtx); } + private: ui32 GetIndex() const final { return GetIndexImpl(); @@ -472,19 +511,24 @@ private: class TStatefulFlowComputationNodeBase { protected: TStatefulFlowComputationNodeBase(ui32 stateIndex, EValueRepresentation stateKind); - void CollectDependentIndexesImpl(const IComputationNode* self, const IComputationNode* owner, - IComputationNode::TIndexesMap& dependencies, const TConstComputationNodePtrVector& dependences) const; + void CollectDependentIndexesImpl(const IComputationNode* self, + const IComputationNode* owner, + IComputationNode::TIndexesMap& dependencies, + const TConstComputationNodePtrVector& dependences) const; const ui32 StateIndex_; const EValueRepresentation StateKind_; }; template <typename TDerived, bool SerializableState = false> -class TStatefulFlowComputationNode: public TBaseFlowBaseComputationNode<TDerived>, protected TStatefulFlowComputationNodeBase -{ +class TStatefulFlowComputationNode: public TBaseFlowBaseComputationNode<TDerived>, protected TStatefulFlowComputationNodeBase { protected: - TStatefulFlowComputationNode(TComputationMutables& mutables, const IComputationNode* source, EValueRepresentation kind, EValueRepresentation stateKind = EValueRepresentation::Any) - : TBaseFlowBaseComputationNode<TDerived>(source, kind), TStatefulFlowComputationNodeBase(mutables.CurValueIndex++, stateKind) + TStatefulFlowComputationNode(TComputationMutables& mutables, + const IComputationNode* source, + EValueRepresentation kind, + EValueRepresentation stateKind = EValueRepresentation::Any) + : TBaseFlowBaseComputationNode<TDerived>(source, kind) + , TStatefulFlowComputationNodeBase(mutables.CurValueIndex++, stateKind) { if constexpr (SerializableState) { mutables.SerializableValues.push_back(StateIndex_); @@ -514,26 +558,33 @@ const IComputationNode* GetCommonSource(const IComputationNode* first, const ICo class TPairStateFlowComputationNodeBase { protected: TPairStateFlowComputationNodeBase(ui32 stateIndex, EValueRepresentation firstKind, EValueRepresentation secondKind); - void CollectDependentIndexesImpl(const IComputationNode* self, const IComputationNode* owner, - IComputationNode::TIndexesMap& dependencies, const TConstComputationNodePtrVector& dependences) const; + void CollectDependentIndexesImpl(const IComputationNode* self, + const IComputationNode* owner, + IComputationNode::TIndexesMap& dependencies, + const TConstComputationNodePtrVector& dependences) const; const ui32 StateIndex_; const EValueRepresentation FirstKind_, SecondKind_; }; template <typename TDerived> -class TPairStateFlowComputationNode: public TBaseFlowBaseComputationNode<TDerived>, protected TPairStateFlowComputationNodeBase -{ +class TPairStateFlowComputationNode: public TBaseFlowBaseComputationNode<TDerived>, protected TPairStateFlowComputationNodeBase { protected: - TPairStateFlowComputationNode(TComputationMutables& mutables, const IComputationNode* source, EValueRepresentation kind, EValueRepresentation firstKind = EValueRepresentation::Any, EValueRepresentation secondKind = EValueRepresentation::Any) - : TBaseFlowBaseComputationNode<TDerived>(source, kind), TPairStateFlowComputationNodeBase(mutables.CurValueIndex++, firstKind, secondKind) + TPairStateFlowComputationNode(TComputationMutables& mutables, + const IComputationNode* source, + EValueRepresentation kind, + EValueRepresentation firstKind = EValueRepresentation::Any, + EValueRepresentation secondKind = EValueRepresentation::Any) + : TBaseFlowBaseComputationNode<TDerived>(source, kind) + , TPairStateFlowComputationNodeBase(mutables.CurValueIndex++, firstKind, secondKind) { ++mutables.CurValueIndex; } private: NUdf::TUnboxedValue GetValue(TComputationContext& compCtx) const final { - return static_cast<const TDerived*>(this)->DoCalculate(compCtx.MutableValues[StateIndex_], compCtx.MutableValues[StateIndex_ + 1U], compCtx); + return static_cast<const TDerived*>(this)->DoCalculate( + compCtx.MutableValues[StateIndex_], compCtx.MutableValues[StateIndex_ + 1U], compCtx); } ui32 GetIndex() const final { @@ -545,14 +596,16 @@ private: } }; -class TWideFlowProxyComputationNode: public TRefCountedComputationNode<IComputationWideFlowProxyNode> -{ +class TWideFlowProxyComputationNode: public TRefCountedComputationNode<IComputationWideFlowProxyNode> { public: TWideFlowProxyComputationNode() = default; + protected: TString DebugString() const final; + private: - void InitNode(TComputationContext&) const override {} + void InitNode(TComputationContext&) const override { + } EValueRepresentation GetRepresentation() const final; @@ -584,7 +637,7 @@ private: void SetFetcher(TFetcher&& fetcher) final; - EFetchResult FetchValues(TComputationContext& ctx, NUdf::TUnboxedValue*const* values) const final; + EFetchResult FetchValues(TComputationContext& ctx, NUdf::TUnboxedValue* const* values) const final; protected: TConstComputationNodePtrVector Dependences_; @@ -601,12 +654,13 @@ protected: template <typename TDerived> class TWideFlowBaseComputationNode: public TFlowBaseComputationNode<TDerived, IComputationWideFlowNode>, - protected TWideFlowBaseComputationNodeBase -{ + protected TWideFlowBaseComputationNodeBase { protected: TWideFlowBaseComputationNode(const IComputationNode* source) : TFlowBaseComputationNode<TDerived, IComputationWideFlowNode>(source) - {} + { + } + private: EValueRepresentation GetRepresentation() const final { return GetRepresentationImpl(); @@ -620,20 +674,23 @@ private: class TStatelessWideFlowComputationNodeBase { protected: ui32 GetIndexImpl() const; - void CollectDependentIndexesImpl(const IComputationNode* self, const IComputationNode* owner, - IComputationNode::TIndexesMap& dependencies, const TConstComputationNodePtrVector& dependences) const; + void CollectDependentIndexesImpl(const IComputationNode* self, + const IComputationNode* owner, + IComputationNode::TIndexesMap& dependencies, + const TConstComputationNodePtrVector& dependences) const; }; template <typename TDerived> -class TStatelessWideFlowComputationNode: public TWideFlowBaseComputationNode<TDerived>, protected TStatelessWideFlowComputationNodeBase -{ +class TStatelessWideFlowComputationNode: public TWideFlowBaseComputationNode<TDerived>, + protected TStatelessWideFlowComputationNodeBase { protected: TStatelessWideFlowComputationNode(const IComputationNode* source) - :TWideFlowBaseComputationNode<TDerived>(source) - {} + : TWideFlowBaseComputationNode<TDerived>(source) + { + } private: - EFetchResult FetchValues(TComputationContext& compCtx, NUdf::TUnboxedValue*const* values) const final { + EFetchResult FetchValues(TComputationContext& compCtx, NUdf::TUnboxedValue* const* values) const final { return static_cast<const TDerived*>(this)->DoCalculate(compCtx, values); } @@ -650,18 +707,21 @@ class TStatefulWideFlowComputationNodeBase { protected: TStatefulWideFlowComputationNodeBase(ui32 stateIndex, EValueRepresentation stateKind); void CollectDependentIndexesImpl(const IComputationNode* self, - const IComputationNode* owner, IComputationNode::TIndexesMap& dependencies, const TConstComputationNodePtrVector& dependences) const; + const IComputationNode* owner, + IComputationNode::TIndexesMap& dependencies, + const TConstComputationNodePtrVector& dependences) const; const ui32 StateIndex_; const EValueRepresentation StateKind_; }; template <typename TDerived, bool SerializableState = false> -class TStatefulWideFlowComputationNode: public TWideFlowBaseComputationNode<TDerived>, protected TStatefulWideFlowComputationNodeBase -{ +class TStatefulWideFlowComputationNode: public TWideFlowBaseComputationNode<TDerived>, + protected TStatefulWideFlowComputationNodeBase { protected: TStatefulWideFlowComputationNode(TComputationMutables& mutables, const IComputationNode* source, EValueRepresentation stateKind) - : TWideFlowBaseComputationNode<TDerived>(source), TStatefulWideFlowComputationNodeBase(mutables.CurValueIndex++, stateKind) + : TWideFlowBaseComputationNode<TDerived>(source) + , TStatefulWideFlowComputationNodeBase(mutables.CurValueIndex++, stateKind) { if constexpr (SerializableState) { mutables.SerializableValues.push_back(StateIndex_); @@ -671,8 +731,9 @@ protected: NUdf::TUnboxedValue& RefState(TComputationContext& compCtx) const { return compCtx.MutableValues[GetIndex()]; } + private: - EFetchResult FetchValues(TComputationContext& compCtx, NUdf::TUnboxedValue*const* values) const final { + EFetchResult FetchValues(TComputationContext& compCtx, NUdf::TUnboxedValue* const* values) const final { return static_cast<const TDerived*>(this)->DoCalculate(compCtx.MutableValues[StateIndex_], compCtx, values); } @@ -688,26 +749,33 @@ private: class TPairStateWideFlowComputationNodeBase { protected: TPairStateWideFlowComputationNodeBase(ui32 stateIndex, EValueRepresentation firstKind, EValueRepresentation secondKind); - void CollectDependentIndexesImpl(const IComputationNode* self, const IComputationNode* owner, - IComputationNode::TIndexesMap& dependencies, const TConstComputationNodePtrVector& dependences) const; + void CollectDependentIndexesImpl(const IComputationNode* self, + const IComputationNode* owner, + IComputationNode::TIndexesMap& dependencies, + const TConstComputationNodePtrVector& dependences) const; const ui32 StateIndex_; const EValueRepresentation FirstKind_, SecondKind_; }; template <typename TDerived> -class TPairStateWideFlowComputationNode: public TWideFlowBaseComputationNode<TDerived>, protected TPairStateWideFlowComputationNodeBase -{ +class TPairStateWideFlowComputationNode: public TWideFlowBaseComputationNode<TDerived>, + protected TPairStateWideFlowComputationNodeBase { protected: - TPairStateWideFlowComputationNode(TComputationMutables& mutables, const IComputationNode* source, EValueRepresentation firstKind, EValueRepresentation secondKind) - : TWideFlowBaseComputationNode<TDerived>(source), TPairStateWideFlowComputationNodeBase(mutables.CurValueIndex++, firstKind, secondKind) + TPairStateWideFlowComputationNode(TComputationMutables& mutables, + const IComputationNode* source, + EValueRepresentation firstKind, + EValueRepresentation secondKind) + : TWideFlowBaseComputationNode<TDerived>(source) + , TPairStateWideFlowComputationNodeBase(mutables.CurValueIndex++, firstKind, secondKind) { ++mutables.CurValueIndex; } private: - EFetchResult FetchValues(TComputationContext& compCtx, NUdf::TUnboxedValue*const* values) const final { - return static_cast<const TDerived*>(this)->DoCalculate(compCtx.MutableValues[StateIndex_], compCtx.MutableValues[StateIndex_ + 1U], compCtx, values); + EFetchResult FetchValues(TComputationContext& compCtx, NUdf::TUnboxedValue* const* values) const final { + return static_cast<const TDerived*>(this)->DoCalculate( + compCtx.MutableValues[StateIndex_], compCtx.MutableValues[StateIndex_ + 1U], compCtx, values); } ui32 GetIndex() const final { @@ -725,33 +793,47 @@ protected: ui32 GetIndexImpl() const; TString DebugStringImpl(const TString& typeName) const; - IComputationNode *const Node_; + IComputationNode* const Node_; const EValueRepresentation Kind_; }; template <typename TDerived> -class TDecoratorComputationNode: public TRefCountedComputationNode<IComputationNode>, protected TDecoratorComputationNodeBase -{ +class TDecoratorComputationNode: public TRefCountedComputationNode<IComputationNode>, + protected TDecoratorComputationNodeBase { private: - void InitNode(TComputationContext&) const final {} + void InitNode(TComputationContext&) const final { + } - const IComputationNode* GetSource() const final { return Node_; } + const IComputationNode* GetSource() const final { + return Node_; + } IComputationNode* AddDependence(const IComputationNode* node) final { return Node_->AddDependence(node); } - EValueRepresentation GetRepresentation() const final { return Kind_; } - bool IsTemporaryValue() const final { return true; } + EValueRepresentation GetRepresentation() const final { + return Kind_; + } + bool IsTemporaryValue() const final { + return true; + } - void PrepareStageOne() final {} - void PrepareStageTwo() final {} + void PrepareStageOne() final { + } + void PrepareStageTwo() final { + } - void RegisterDependencies() const final { Node_->AddDependence(this); } + void RegisterDependencies() const final { + Node_->AddDependence(this); + } - void CollectDependentIndexes(const IComputationNode*, TIndexesMap&) const final {} + void CollectDependentIndexes(const IComputationNode*, TIndexesMap&) const final { + } - ui32 GetDependencyWeight() const final { return 0U; } + ui32 GetDependencyWeight() const final { + return 0U; + } ui32 GetDependencesCount() const final { return Node_->GetDependencesCount(); @@ -768,12 +850,13 @@ private: protected: TDecoratorComputationNode(IComputationNode* node, EValueRepresentation kind) : TDecoratorComputationNodeBase(node, kind) - {} + { + } TDecoratorComputationNode(IComputationNode* node) : TDecoratorComputationNodeBase(node, node->GetRepresentation()) - {} - + { + } TString DebugString() const override { return DebugStringImpl(TypeName<TDerived>()); @@ -786,14 +869,14 @@ protected: ui32 GetIndexImpl() const; TString DebugStringImpl(const TString& typeName) const; - IComputationNode *const Left_; - IComputationNode *const Right_; + IComputationNode* const Left_; + IComputationNode* const Right_; const EValueRepresentation Kind_; }; template <typename TDerived> -class TBinaryComputationNode: public TRefCountedComputationNode<IComputationNode>, protected TBinaryComputationNodeBase -{ +class TBinaryComputationNode: public TRefCountedComputationNode<IComputationNode>, + protected TBinaryComputationNodeBase { private: NUdf::TUnboxedValue GetValue(TComputationContext& ctx) const final { return static_cast<const TDerived*>(this)->DoCalculate(ctx); @@ -803,7 +886,9 @@ private: return GetCommonSource(Left_, Right_, this); } - void InitNode(TComputationContext&) const final {} + void InitNode(TComputationContext&) const final { + } + protected: TString DebugString() const override { return DebugStringImpl(TypeName<TDerived>()); @@ -813,8 +898,12 @@ protected: const auto l = Left_->AddDependence(node); const auto r = Right_->AddDependence(node); - if (!l) return r; - if (!r) return l; + if (!l) { + return r; + } + if (!r) { + return l; + } return this; } @@ -823,19 +912,26 @@ protected: return Kind_; } - bool IsTemporaryValue() const final { return true; } + bool IsTemporaryValue() const final { + return true; + } - void PrepareStageOne() final {} - void PrepareStageTwo() final {} + void PrepareStageOne() final { + } + void PrepareStageTwo() final { + } void RegisterDependencies() const final { Left_->AddDependence(this); Right_->AddDependence(this); } - void CollectDependentIndexes(const IComputationNode*, TIndexesMap&) const final {} + void CollectDependentIndexes(const IComputationNode*, TIndexesMap&) const final { + } - ui32 GetDependencyWeight() const final { return 0U; } + ui32 GetDependencyWeight() const final { + return 0U; + } ui32 GetDependencesCount() const final { return Left_->GetDependencesCount() + Right_->GetDependencesCount(); @@ -852,13 +948,12 @@ protected: }; [[noreturn]] -void ThrowNotSupportedImplForClass(const TString& className, const char *func); - +void ThrowNotSupportedImplForClass(const TString& className, const char* func); -class TComputationValueBaseNotSupportedStub: public NYql::NUdf::IBoxedValue -{ +class TComputationValueBaseNotSupportedStub: public NYql::NUdf::IBoxedValue { private: using TBase = NYql::NUdf::IBoxedValue; + public: template <typename... Args> TComputationValueBaseNotSupportedStub(Args&&... args) @@ -884,17 +979,17 @@ private: NUdf::TStringRef GetResourceTag() const override; void* GetResource() override; void Apply(NUdf::IApplyContext& applyCtx) const override; - NUdf::TUnboxedValue GetListIterator() const override ; + NUdf::TUnboxedValue GetListIterator() const override; NUdf::TUnboxedValue GetDictIterator() const override; NUdf::TUnboxedValue GetKeysIterator() const override; NUdf::TUnboxedValue GetPayloadsIterator() const override; bool Contains(const NUdf::TUnboxedValuePod& key) const override; NUdf::TUnboxedValue Lookup(const NUdf::TUnboxedValuePod& key) const override; - NUdf::TUnboxedValue GetElement(ui32 index) const override ; + NUdf::TUnboxedValue GetElement(ui32 index) const override; const NUdf::TUnboxedValue* GetElements() const override; NUdf::TUnboxedValue Run( - const NUdf::IValueBuilder* valueBuilder, - const NUdf::TUnboxedValuePod* args) const override; + const NUdf::IValueBuilder* valueBuilder, + const NUdf::TUnboxedValuePod* args) const override; bool Skip() override; bool Next(NUdf::TUnboxedValue&) override; bool NextPair(NUdf::TUnboxedValue&, NUdf::TUnboxedValue&) override; @@ -920,12 +1015,11 @@ protected: [[noreturn]] virtual void ThrowNotSupported(const char* func) const = 0; }; - template <typename TDerived> -class TComputationValueBase: public TComputationValueBaseNotSupportedStub -{ +class TComputationValueBase: public TComputationValueBaseNotSupportedStub { private: using TBase = TComputationValueBaseNotSupportedStub; + public: template <typename... Args> TComputationValueBase(Args&&... args) @@ -948,9 +1042,10 @@ protected: template <typename TDerived, EMemorySubPool MemoryPool> class TComputationValueImpl: public TComputationValueBase<TDerived>, - public TWithMiniKQLAlloc<MemoryPool> { + public TWithMiniKQLAlloc<MemoryPool> { private: using TBase = TComputationValueBase<TDerived>; + protected: inline TMemoryUsageInfo* GetMemInfo() const { #ifndef NDEBUG @@ -961,10 +1056,12 @@ protected: } using TWithMiniKQLAlloc<MemoryPool>::AllocWithSize; using TWithMiniKQLAlloc<MemoryPool>::FreeWithSize; + public: template <typename... Args> TComputationValueImpl(TMemoryUsageInfo* memInfo, Args&&... args) - : TBase(std::forward<Args>(args)...) { + : TBase(std::forward<Args>(args)...) + { #ifndef NDEBUG M_.MemInfo = memInfo; MKQL_MEM_TAKE(memInfo, this, sizeof(TDerived), __MKQL_LOCATION__); @@ -978,6 +1075,7 @@ public: MKQL_MEM_RETURN(GetMemInfo(), this, sizeof(TDerived)); #endif } + private: #ifndef NDEBUG struct { @@ -990,6 +1088,7 @@ template <typename TDerived> class TTemporaryComputationValue: public TComputationValueImpl<TDerived, EMemorySubPool::Temporary> { private: using TBase = TComputationValueImpl<TDerived, EMemorySubPool::Temporary>; + public: using TBase::TBase; }; @@ -998,37 +1097,42 @@ template <typename TDerived> class TComputationValue: public TComputationValueImpl<TDerived, EMemorySubPool::Default> { private: using TBase = TComputationValueImpl<TDerived, EMemorySubPool::Default>; + public: using TBase::TBase; }; -template<bool IsStream> +template <bool IsStream> struct TThresher; -template<> +template <> struct TThresher<true> { - template<class Handler> + template <class Handler> static void DoForEachItem(const NUdf::TUnboxedValuePod& stream, const Handler& handler) { for (NUdf::TUnboxedValue item;; handler(std::move(item))) { const auto status = stream.Fetch(item); MKQL_ENSURE(status != NUdf::EFetchStatus::Yield, "Unexpected stream status!"); - if (status == NUdf::EFetchStatus::Finish) + if (status == NUdf::EFetchStatus::Finish) { break; + } } } }; -template<> +template <> struct TThresher<false> { - template<class Handler> + template <class Handler> static void DoForEachItem(const NUdf::TUnboxedValuePod& list, const Handler& handler) { if (auto ptr = list.GetElements()) { - if (auto size = list.GetListLength()) do { - handler(NUdf::TUnboxedValue(*ptr++)); - } while (--size); + if (auto size = list.GetListLength()) { + do { + handler(NUdf::TUnboxedValue(*ptr++)); + } while (--size); + } } else if (const auto& iter = list.GetListIterator()) { - for (NUdf::TUnboxedValue item; iter.Next(item); handler(std::move(item))) + for (NUdf::TUnboxedValue item; iter.Next(item); handler(std::move(item))) { continue; + } } } }; @@ -1040,10 +1144,10 @@ IComputationExternalNode* LocateExternalNode(const TNodeLocator& nodeLocator, TC using TPasstroughtMap = std::vector<std::optional<size_t>>; using TPassthroughSpan = std::vector<std::optional<size_t>>; -template<class TContainerOne, class TContainerTwo> +template <class TContainerOne, class TContainerTwo> TPasstroughtMap GetPasstroughtMap(const TContainerOne& from, const TContainerTwo& to); -template<class TContainerOne, class TContainerTwo> +template <class TContainerOne, class TContainerTwo> TPasstroughtMap GetPasstroughtMapOneToOne(const TContainerOne& from, const TContainerTwo& to); std::optional<size_t> IsPasstrought(const IComputationNode* root, const TComputationExternalNodePtrVector& args); @@ -1053,5 +1157,5 @@ TPasstroughtMap MergePasstroughtMaps(const TPasstroughtMap& lhs, const TPasstrou void ApplyChanges(const NUdf::TUnboxedValue& value, NUdf::IApplyContext& applyCtx); void CleanupCurrentContext(); -} -} +} // namespace NMiniKQL +} // namespace NKikimr |
