block.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #include "columns/column.h"
  3. namespace NClickHouse {
  4. struct TBlockInfo {
  5. ui8 IsOverflows = 0;
  6. i32 BucketNum = -1;
  7. };
  8. class TBlock {
  9. public:
  10. /// Allow to iterate over block's columns.
  11. class TIterator {
  12. public:
  13. TIterator(const TBlock& block);
  14. /// Name of column.
  15. const TString& Name() const;
  16. /// Type of column.
  17. TTypeRef Type() const;
  18. /// Reference to column object.
  19. TColumnRef Column() const;
  20. /// Move to next column.
  21. void Next();
  22. /// Is the iterator still valid.
  23. bool IsValid() const;
  24. private:
  25. TIterator() = delete;
  26. const TBlock& Block_;
  27. size_t Idx_;
  28. };
  29. public:
  30. TBlock();
  31. TBlock(size_t cols, size_t rows);
  32. ~TBlock();
  33. /// Append named column to the block.
  34. void AppendColumn(const TString& name, const TColumnRef& col);
  35. /// Count of columns in the block.
  36. size_t GetColumnCount() const;
  37. const TBlockInfo& Info() const;
  38. /// Count of rows in the block.
  39. size_t GetRowCount() const;
  40. /// Append block to the current (vertical scale)
  41. void AppendBlock(const TBlock& block);
  42. /// Reference to column by index in the block.
  43. TColumnRef operator[](size_t idx) const;
  44. private:
  45. struct TColumnItem {
  46. TString Name;
  47. TColumnRef Column;
  48. };
  49. TBlockInfo Info_;
  50. TVector<TColumnItem> Columns_;
  51. /// Count of rows in the block.
  52. size_t Rows_;
  53. };
  54. }