column.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <library/cpp/clickhouse/client/base/coded.h>
  3. #include <library/cpp/clickhouse/client/types/types.h>
  4. #include <util/generic/ptr.h>
  5. namespace NClickHouse {
  6. using TColumnRef = TIntrusivePtr<class TColumn>;
  7. /**
  8. * An abstract base of all columns classes.
  9. */
  10. class TColumn: public TAtomicRefCount<TColumn> {
  11. public:
  12. virtual ~TColumn() {
  13. }
  14. /// Downcast pointer to the specific culumn's subtype.
  15. template <typename T>
  16. inline TIntrusivePtr<T> As() {
  17. return TIntrusivePtr<T>(dynamic_cast<T*>(this));
  18. }
  19. /// Downcast pointer to the specific culumn's subtype.
  20. template <typename T>
  21. inline TIntrusivePtr<const T> As() const {
  22. return TIntrusivePtr<const T>(dynamic_cast<const T*>(this));
  23. }
  24. /// Get type object of the column.
  25. inline TTypeRef Type() const {
  26. return Type_;
  27. }
  28. /// Appends content of given column to the end of current one.
  29. virtual void Append(TColumnRef column) = 0;
  30. /// Loads column data from input stream.
  31. virtual bool Load(TCodedInputStream* input, size_t rows) = 0;
  32. /// Saves column data to output stream.
  33. virtual void Save(TCodedOutputStream* output) = 0;
  34. /// Returns count of rows in the column.
  35. virtual size_t Size() const = 0;
  36. /// Makes slice of the current column.
  37. virtual TColumnRef Slice(size_t begin, size_t len) = 0;
  38. protected:
  39. explicit inline TColumn(TTypeRef type)
  40. : Type_(type)
  41. {
  42. }
  43. TTypeRef Type_;
  44. };
  45. }