arrow_util.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "arrow_util.h"
  2. #include "mkql_bit_utils.h"
  3. #include <arrow/array/array_base.h>
  4. #include <arrow/chunked_array.h>
  5. #include <yql/essentials/minikql/mkql_node_builder.h>
  6. #include <util/system/yassert.h>
  7. namespace NKikimr::NMiniKQL {
  8. std::shared_ptr<arrow::ArrayData> Unwrap(const arrow::ArrayData& data, TType* itemType) {
  9. bool nested;
  10. if (itemType->IsPg()) {
  11. nested = false;
  12. } else {
  13. bool isOptional;
  14. auto unpacked = UnpackOptional(itemType, isOptional);
  15. MKQL_ENSURE(isOptional, "Expected optional");
  16. if (unpacked->IsOptional() || unpacked->IsVariant() || unpacked->IsPg()) {
  17. nested = true;
  18. } else {
  19. nested = false;
  20. }
  21. }
  22. if (nested) {
  23. MKQL_ENSURE(data.child_data.size() == 1, "Expected struct with one element");
  24. return data.child_data[0];
  25. } else {
  26. auto buffers = data.buffers;
  27. MKQL_ENSURE(buffers.size() >= 1, "Missing nullable bitmap");
  28. buffers[0] = nullptr;
  29. return arrow::ArrayData::Make(data.type, data.length, buffers, data.child_data, data.dictionary, 0, data.offset);
  30. }
  31. }
  32. }