mkql_match_recognize_measure_arg.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "mkql_match_recognize_measure_arg.h"
  2. namespace NKikimr::NMiniKQL::NMatchRecognize {
  3. TRowForMeasureValue::TRowForMeasureValue(
  4. TMemoryUsageInfo* memInfo,
  5. NUdf::TUnboxedValue inputRow,
  6. ui64 rowIndex,
  7. const TMeasureInputColumnOrder& columnOrder,
  8. const NUdf::TUnboxedValue& matchedVars,
  9. const TUnboxedValueVector& varNames,
  10. ui64 matchNumber)
  11. : TComputationValue<TRowForMeasureValue>(memInfo)
  12. , InputRow(inputRow)
  13. , RowIndex(rowIndex)
  14. , ColumnOrder(columnOrder)
  15. , MatchedVars(matchedVars)
  16. , VarNames(varNames)
  17. , MatchNumber(matchNumber)
  18. {}
  19. NUdf::TUnboxedValue TRowForMeasureValue::GetElement(ui32 index) const {
  20. switch(ColumnOrder[index].first) {
  21. case NYql::NMatchRecognize::EMeasureInputDataSpecialColumns::Classifier: {
  22. auto varIterator = MatchedVars.GetListIterator();
  23. MKQL_ENSURE(varIterator, "Internal logic error");
  24. NUdf::TUnboxedValue var;
  25. size_t varIndex = 0;
  26. while(varIterator.Next(var)) {
  27. auto rangeIterator = var.GetListIterator();
  28. MKQL_ENSURE(varIterator, "Internal logic error");
  29. NUdf::TUnboxedValue range;
  30. while(rangeIterator.Next(range)) {
  31. const auto from = range.GetElement(0).Get<ui64>();
  32. const auto to = range.GetElement(1).Get<ui64>();
  33. if (RowIndex >= from and RowIndex <= to) {
  34. return VarNames[varIndex];
  35. }
  36. }
  37. ++varIndex;
  38. }
  39. MKQL_ENSURE(MatchedVars.GetListLength() == varIndex, "Internal logic error");
  40. return MakeString("");
  41. }
  42. case NYql::NMatchRecognize::EMeasureInputDataSpecialColumns::MatchNumber:
  43. return NUdf::TUnboxedValuePod(MatchNumber);
  44. case NYql::NMatchRecognize::EMeasureInputDataSpecialColumns::Last: //Last corresponds to columns from the input table row
  45. return InputRow.GetElement(ColumnOrder[index].second);
  46. }
  47. }
  48. TMeasureInputDataValue::TMeasureInputDataValue(
  49. TMemoryUsageInfo* memInfo,
  50. const NUdf::TUnboxedValue& inputData,
  51. const TMeasureInputColumnOrder& columnOrder,
  52. const NUdf::TUnboxedValue& matchedVars,
  53. const TUnboxedValueVector& varNames,
  54. ui64 matchNumber)
  55. : TComputationValue<TMeasureInputDataValue>(memInfo)
  56. , InputData(inputData)
  57. , ColumnOrder(columnOrder)
  58. , MatchedVars(matchedVars)
  59. , VarNames(varNames)
  60. , MatchNumber(matchNumber)
  61. {}
  62. bool TMeasureInputDataValue::HasFastListLength() const {
  63. return true;
  64. }
  65. ui64 TMeasureInputDataValue::GetListLength() const {
  66. return GetDictLength();
  67. }
  68. ui64 TMeasureInputDataValue::GetEstimatedListLength() const {
  69. return GetListLength();
  70. }
  71. NUdf::TUnboxedValue TMeasureInputDataValue::GetListIterator() const {
  72. return GetPayloadsIterator();
  73. }
  74. bool TMeasureInputDataValue::HasListItems() const {
  75. return HasDictItems();
  76. }
  77. NUdf::IBoxedValuePtr TMeasureInputDataValue::ToIndexDictImpl(const NUdf::IValueBuilder& builder) const {
  78. Y_UNUSED(builder);
  79. return const_cast<TMeasureInputDataValue*>(this);
  80. }
  81. ui64 TMeasureInputDataValue::GetDictLength() const {
  82. return InputData.GetDictLength();
  83. }
  84. NUdf::TUnboxedValue TMeasureInputDataValue::GetDictIterator() const {
  85. return InputData.GetDictIterator();
  86. }
  87. NUdf::TUnboxedValue TMeasureInputDataValue::GetKeysIterator() const {
  88. return InputData.GetKeysIterator();
  89. }
  90. NUdf::TUnboxedValue TMeasureInputDataValue::GetPayloadsIterator() const {
  91. return InputData.GetPayloadsIterator();
  92. }
  93. bool TMeasureInputDataValue::Contains(const NUdf::TUnboxedValuePod& key) const {
  94. return InputData.Contains(key);
  95. }
  96. NUdf::TUnboxedValue TMeasureInputDataValue::Lookup(const NUdf::TUnboxedValuePod& key) const {
  97. return NUdf::TUnboxedValuePod{new TRowForMeasureValue(
  98. GetMemInfo(),
  99. InputData.Lookup(key),
  100. key.Get<ui64>(),
  101. ColumnOrder,
  102. MatchedVars,
  103. VarNames,
  104. MatchNumber
  105. )};
  106. }
  107. bool TMeasureInputDataValue::HasDictItems() const {
  108. return InputData.HasDictItems();
  109. }
  110. } // namespace NKikimr::NMiniKQL::NMatchRecognize