date.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #include "numeric.h"
  3. #include <util/datetime/base.h>
  4. namespace NClickHouse {
  5. /** */
  6. class TColumnDate: public TColumn {
  7. public:
  8. static TIntrusivePtr<TColumnDate> Create();
  9. static TIntrusivePtr<TColumnDate> Create(const TVector<TInstant>& data);
  10. /// Appends one element to the end of column.
  11. void Append(const TInstant& value);
  12. /// Returns element at given row number.
  13. std::time_t At(size_t n) const;
  14. /// Set element at given row number.
  15. void SetAt(size_t n, const TInstant& value);
  16. public:
  17. /// Appends content of given column to the end of current one.
  18. void Append(TColumnRef column) override;
  19. /// Loads column data from input stream.
  20. bool Load(TCodedInputStream* input, size_t rows) override;
  21. /// Saves column data to output stream.
  22. void Save(TCodedOutputStream* output) override;
  23. /// Returns count of rows in the column.
  24. size_t Size() const override;
  25. /// Makes slice of the current column.
  26. TColumnRef Slice(size_t begin, size_t len) override;
  27. private:
  28. TColumnDate();
  29. TColumnDate(const TVector<TInstant>& data);
  30. TIntrusivePtr<TColumnUInt16> Data_;
  31. };
  32. /** */
  33. class TColumnDateTime: public TColumn {
  34. public:
  35. static TIntrusivePtr<TColumnDateTime> Create();
  36. static TIntrusivePtr<TColumnDateTime> Create(const TVector<TInstant>& data);
  37. /// Appends one element to the end of column.
  38. void Append(const TInstant& value);
  39. /// Returns element at given row number.
  40. std::time_t At(size_t n) const;
  41. /// Set element at given row number.
  42. void SetAt(size_t n, const TInstant& value);
  43. public:
  44. /// Appends content of given column to the end of current one.
  45. void Append(TColumnRef column) override;
  46. /// Loads column data from input stream.
  47. bool Load(TCodedInputStream* input, size_t rows) override;
  48. /// Saves column data to output stream.
  49. void Save(TCodedOutputStream* output) override;
  50. /// Returns count of rows in the column.
  51. size_t Size() const override;
  52. /// Makes slice of the current column.
  53. TColumnRef Slice(size_t begin, size_t len) override;
  54. private:
  55. TColumnDateTime();
  56. TColumnDateTime(const TVector<TInstant>& data);
  57. TIntrusivePtr<TColumnUInt32> Data_;
  58. };
  59. }