presort.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include <yql/essentials/minikql/mkql_node.h>
  3. #include <yql/essentials/public/udf/udf_value.h>
  4. #include <util/generic/vector.h>
  5. namespace NKikimr {
  6. namespace NMiniKQL {
  7. class TPresortCodec {
  8. public:
  9. TPresortCodec() = default;
  10. struct TTypeInfo {
  11. NUdf::EDataSlot Slot;
  12. bool IsOptional;
  13. bool IsDesc;
  14. };
  15. void AddType(NUdf::EDataSlot slot, bool isOptional = false, bool isDesc = false);
  16. protected:
  17. size_t Current = 0;
  18. TVector<TTypeInfo> Types;
  19. };
  20. class TPresortEncoder : public TPresortCodec {
  21. public:
  22. TPresortEncoder() = default;
  23. void Start();
  24. void Start(TStringBuf prefix);
  25. void Encode(const NUdf::TUnboxedValuePod& value);
  26. TStringBuf Finish(); // user must copy
  27. private:
  28. TVector<ui8> Output;
  29. };
  30. class TPresortDecoder : public TPresortCodec {
  31. public:
  32. TPresortDecoder() = default;
  33. void Start(TStringBuf input);
  34. NUdf::TUnboxedValue Decode();
  35. void Finish();
  36. private:
  37. TVector<ui8> Buffer;
  38. TStringBuf Input;
  39. };
  40. class THolderFactory;
  41. class TGenericPresortEncoder {
  42. public:
  43. TGenericPresortEncoder(TType* type);
  44. TStringBuf Encode(const NUdf::TUnboxedValue& value, bool desc); // user must copy
  45. NUdf::TUnboxedValue Decode(TStringBuf buf, bool desc, const THolderFactory& factory);
  46. private:
  47. TType* Type;
  48. TVector<ui8> Output;
  49. TVector<ui8> Buffer;
  50. };
  51. } // NMiniKQL
  52. } // NKikimr