#include "mkql_window_range_pg_caller.h" #include #include #include #include namespace NKikimr::NMiniKQL { namespace { class TInRangeComputationValue: public TComputationValue { public: TInRangeComputationValue(TMemoryUsageInfo* memInfo, const NYql::TPgInRange& inRange) : TComputationValue(memInfo) , State_(inRange.MakeCallState()) { } NUdf::TUnboxedValue Call(NUdf::TUnboxedValue from, NUdf::TUnboxedValue to, NUdf::TUnboxedValue columnToTest, bool sub, bool less) const { return State_->Call(to, from, columnToTest, sub, less); } private: THolder State_; }; TInRangeComputationValue& GetInRangeState(const NYql::TPgInRange& inRange, TComputationContext& ctx, ui32 ctxIndex) { auto& result = ctx.MutableValues[ctxIndex]; if (!result.HasValue()) { result = ctx.HolderFactory.Create(inRange); } return *static_cast(result.AsBoxed().Get()); } } // namespace TPgWindowRangeCaller::TPgWindowRangeCaller(NKikimr::NMiniKQL::TPgType* columnType, std::variant> delta, ui32 ctxIndex) : Delta_(std::visit(TOverloaded{ [&](TCurrentRowTag) -> std::variant> { return MakePgEquate(columnType); }, [&](std::tuple tuple) -> std::variant> { auto [procId, deltaNode, offsetType] = tuple; MKQL_ENSURE(offsetType, "Offset type is not specified."); MKQL_ENSURE(deltaNode, "Delta node is not specified."); return std::pair(deltaNode, NYql::TPgInRange(procId, columnType, offsetType)); }}, delta)) , CtxIndex_(ctxIndex) { } bool TPgWindowRangeCaller::IsBelongToInterval(EInfBoundary infBoundary, EDirection direction, NUdf::TUnboxedValue from, NUdf::TUnboxedValue to, TComputationContext& ctx) const { return std::visit(TOverloaded{ [&](const NYql::NUdf::IEquate::TPtr& equate) -> bool { return equate->Equals(from, to); }, [&](const std::pair& pair) -> bool { bool less = EInfBoundary::Left == infBoundary; bool sub = direction == EDirection::Preceding ? true : false; auto& state = GetInRangeState(pair.second, ctx, CtxIndex_); return state.Call(from, to, pair.first->GetValue(ctx), sub, less).Get(); }}, Delta_); } TPgWindowRangeCaller::~TPgWindowRangeCaller() = default; } // namespace NKikimr::NMiniKQL