nullable.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "nullable.h"
  2. #include <util/generic/yexception.h>
  3. #include <util/system/yassert.h>
  4. namespace NClickHouse {
  5. TColumnNullable::TColumnNullable(TColumnRef nested, TColumnRef nulls)
  6. : TColumn(TType::CreateNullable(nested->Type()))
  7. , Nested_(nested)
  8. , Nulls_(nulls->As<TColumnUInt8>())
  9. {
  10. if (Nested_->Size() != nulls->Size()) {
  11. ythrow yexception() << "count of elements in nested and nulls should be the same";
  12. }
  13. }
  14. TIntrusivePtr<TColumnNullable> TColumnNullable::Create(TColumnRef nested) {
  15. return new TColumnNullable(nested, TColumnUInt8::Create());
  16. }
  17. TIntrusivePtr<TColumnNullable> TColumnNullable::Create(TColumnRef nested, TColumnRef nulls) {
  18. return new TColumnNullable(nested, nulls);
  19. }
  20. bool TColumnNullable::IsNull(size_t n) const {
  21. return Nulls_->At(n) != 0;
  22. }
  23. TColumnRef TColumnNullable::Nested() const {
  24. return Nested_;
  25. }
  26. void TColumnNullable::Append(TColumnRef column) {
  27. if (auto col = column->As<TColumnNullable>()) {
  28. if (!col->Nested_->Type()->IsEqual(Nested_->Type())) {
  29. return;
  30. }
  31. Nested_->Append(col->Nested_);
  32. Nulls_->Append(col->Nulls_);
  33. }
  34. }
  35. bool TColumnNullable::Load(TCodedInputStream* input, size_t rows) {
  36. if (!Nulls_->Load(input, rows)) {
  37. return false;
  38. }
  39. if (!Nested_->Load(input, rows)) {
  40. return false;
  41. }
  42. return true;
  43. }
  44. void TColumnNullable::Save(TCodedOutputStream* output) {
  45. Nulls_->Save(output);
  46. Nested_->Save(output);
  47. }
  48. size_t TColumnNullable::Size() const {
  49. Y_ASSERT(Nested_->Size() == Nulls_->Size());
  50. return Nulls_->Size();
  51. }
  52. TColumnRef TColumnNullable::Slice(size_t begin, size_t len) {
  53. (void)begin;
  54. (void)len;
  55. return TColumnRef();
  56. }
  57. }