string.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #pragma once
  2. #include "column.h"
  3. #include <util/generic/string.h>
  4. namespace NClickHouse {
  5. /**
  6. * Represents column of fixed-length strings.
  7. */
  8. class TColumnFixedString: public TColumn {
  9. public:
  10. static TIntrusivePtr<TColumnFixedString> Create(size_t n);
  11. static TIntrusivePtr<TColumnFixedString> Create(size_t n, const TVector<TString>& data);
  12. /// Appends one element to the column.
  13. void Append(const TString& str);
  14. /// Returns element at given row number.
  15. const TString& At(size_t n) const;
  16. /// Returns element at given row number.
  17. const TString& operator[](size_t n) const;
  18. /// Set element at given row number.
  19. void SetAt(size_t n, const TString& value);
  20. public:
  21. /// Appends content of given column to the end of current one.
  22. void Append(TColumnRef column) override;
  23. /// Loads column data from input stream.
  24. bool Load(TCodedInputStream* input, size_t rows) override;
  25. /// Saves column data to output stream.
  26. void Save(TCodedOutputStream* output) override;
  27. /// Returns count of rows in the column.
  28. size_t Size() const override;
  29. /// Makes slice of the current column.
  30. TColumnRef Slice(size_t begin, size_t len) override;
  31. private:
  32. TColumnFixedString(size_t n);
  33. TColumnFixedString(size_t n, const TVector<TString>& data);
  34. const size_t StringSize_;
  35. TVector<TString> Data_;
  36. };
  37. /**
  38. * Represents column of variable-length strings.
  39. */
  40. class TColumnString: public TColumn {
  41. public:
  42. static TIntrusivePtr<TColumnString> Create();
  43. static TIntrusivePtr<TColumnString> Create(const TVector<TString>& data);
  44. static TIntrusivePtr<TColumnString> Create(TVector<TString>&& data);
  45. /// Appends one element to the column.
  46. void Append(const TString& str);
  47. /// Returns element at given row number.
  48. const TString& At(size_t n) const;
  49. /// Returns element at given row number.
  50. const TString& operator[](size_t n) const;
  51. /// Set element at given row number.
  52. void SetAt(size_t n, const TString& value);
  53. public:
  54. /// Appends content of given column to the end of current one.
  55. void Append(TColumnRef column) override;
  56. /// Loads column data from input stream.
  57. bool Load(TCodedInputStream* input, size_t rows) override;
  58. /// Saves column data to output stream.
  59. void Save(TCodedOutputStream* output) override;
  60. /// Returns count of rows in the column.
  61. size_t Size() const override;
  62. /// Makes slice of the current column.
  63. TColumnRef Slice(size_t begin, size_t len) override;
  64. private:
  65. TColumnString();
  66. TColumnString(const TVector<TString>& data);
  67. TColumnString(TVector<TString>&& data);
  68. TVector<TString> Data_;
  69. };
  70. /**
  71. * Represents column of variable-length strings but use TStringBuf instead TString.
  72. */
  73. class TColumnStringBuf: public NClickHouse::TColumn {
  74. public:
  75. static TIntrusivePtr<TColumnStringBuf> Create();
  76. static TIntrusivePtr<TColumnStringBuf> Create(const TVector<TStringBuf>& data);
  77. static TIntrusivePtr<TColumnStringBuf> Create(TVector<TStringBuf>&& data);
  78. /// Appends one element to the column.
  79. void Append(TStringBuf str);
  80. /// Returns element at given row number.
  81. const TStringBuf& At(size_t n) const;
  82. /// Returns element at given row number.
  83. const TStringBuf& operator[](size_t n) const;
  84. /// Set element at given row number.
  85. void SetAt(size_t n, TStringBuf value);
  86. public:
  87. /// Appends content of given column to the end of current one.
  88. void Append(NClickHouse::TColumnRef column) override;
  89. /// Loads column data from input stream.
  90. bool Load(NClickHouse::TCodedInputStream* input, size_t rows) override;
  91. /// Saves column data to output stream.
  92. void Save(NClickHouse::TCodedOutputStream* output) override;
  93. /// Returns count of rows in the column.
  94. size_t Size() const override;
  95. /// Makes slice of the current column.
  96. NClickHouse::TColumnRef Slice(size_t begin, size_t len) override;
  97. private:
  98. TColumnStringBuf();
  99. TColumnStringBuf(const TVector<TStringBuf>& data);
  100. TColumnStringBuf(TVector<TStringBuf>&& data);
  101. TVector<TStringBuf> Data_;
  102. };
  103. }