mkql_custom_list.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #pragma once
  2. #include <yql/essentials/minikql/computation/mkql_computation_node_impl.h>
  3. #include <yql/essentials/minikql/computation/mkql_computation_node_holders.h>
  4. namespace NKikimr {
  5. namespace NMiniKQL {
  6. class TCustomListValue : public TComputationValue<TCustomListValue> {
  7. public:
  8. TCustomListValue(TMemoryUsageInfo* memInfo)
  9. : TComputationValue(memInfo)
  10. {
  11. }
  12. private:
  13. bool HasFastListLength() const override {
  14. return bool(Length);
  15. }
  16. ui64 GetListLength() const override {
  17. if (!Length) {
  18. ui64 length = Iterator ? 1ULL : 0ULL;
  19. for (const auto it = Iterator ? std::move(Iterator) : NUdf::TBoxedValueAccessor::GetListIterator(*this); it.Skip();) {
  20. ++length;
  21. }
  22. Length = length;
  23. }
  24. return *Length;
  25. }
  26. ui64 GetEstimatedListLength() const override {
  27. return GetListLength();
  28. }
  29. bool HasListItems() const override {
  30. if (HasItems) {
  31. return *HasItems;
  32. }
  33. if (Length) {
  34. HasItems = (*Length != 0);
  35. return *HasItems;
  36. }
  37. auto iter = NUdf::TBoxedValueAccessor::GetListIterator(*this);
  38. HasItems = iter.Skip();
  39. if (*HasItems) {
  40. Iterator = std::move(iter);
  41. }
  42. return *HasItems;
  43. }
  44. protected:
  45. mutable std::optional<ui64> Length;
  46. mutable std::optional<bool> HasItems;
  47. mutable NUdf::TUnboxedValue Iterator;
  48. };
  49. class TForwardListValue : public TCustomListValue {
  50. public:
  51. class TIterator : public TComputationValue<TIterator> {
  52. public:
  53. TIterator(TMemoryUsageInfo* memInfo, NUdf::TUnboxedValue&& stream);
  54. private:
  55. bool Next(NUdf::TUnboxedValue& value) override;
  56. const NUdf::TUnboxedValue Stream;
  57. };
  58. TForwardListValue(TMemoryUsageInfo* memInfo, NUdf::TUnboxedValue&& stream);
  59. private:
  60. NUdf::TUnboxedValue GetListIterator() const override;
  61. mutable NUdf::TUnboxedValue Stream;
  62. };
  63. class TExtendListValue : public TCustomListValue {
  64. public:
  65. class TIterator : public TComputationValue<TIterator> {
  66. public:
  67. TIterator(TMemoryUsageInfo* memInfo, TUnboxedValueVector&& iters);
  68. ~TIterator();
  69. private:
  70. bool Next(NUdf::TUnboxedValue& value) override;
  71. bool Skip() override;
  72. const TUnboxedValueVector Iters;
  73. ui32 Index;
  74. };
  75. TExtendListValue(TMemoryUsageInfo* memInfo, TUnboxedValueVector&& lists);
  76. ~TExtendListValue();
  77. private:
  78. NUdf::TUnboxedValue GetListIterator() const override;
  79. ui64 GetListLength() const override;
  80. bool HasListItems() const override;
  81. const TUnboxedValueVector Lists;
  82. };
  83. class TExtendStreamValue : public TComputationValue<TExtendStreamValue> {
  84. public:
  85. using TBase = TComputationValue<TExtendStreamValue>;
  86. TExtendStreamValue(TMemoryUsageInfo* memInfo, TUnboxedValueVector&& lists);
  87. ~TExtendStreamValue();
  88. private:
  89. NUdf::EFetchStatus Fetch(NUdf::TUnboxedValue& value);
  90. const TUnboxedValueVector Lists;
  91. ui32 Index = 0;
  92. };
  93. }
  94. }