MCPcopy Create free account
hub / github.com/apache/arrow / MakeDataView

Method MakeDataView

cpp/src/arrow/array/data.cc:822–927  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

820 }
821
822 Status MakeDataView(const std::shared_ptr<Field>& out_field,
823 std::shared_ptr<ArrayData>* out) {
824 const auto& out_type = out_field->type();
825 const auto out_layout = out_type->layout();
826
827 AdjustInputPointer();
828 int64_t out_length = in_data_length;
829 int64_t out_offset = 0;
830 int64_t out_null_count;
831
832 std::shared_ptr<ArrayData> dictionary;
833 if (out_type->id() == Type::DICTIONARY) {
834 ARROW_ASSIGN_OR_RAISE(dictionary, GetDictionaryView(*out_type));
835 }
836
837 // No type has a purely empty layout
838 DCHECK_GT(out_layout.buffers.size(), 0);
839
840 std::vector<std::shared_ptr<Buffer>> out_buffers;
841
842 // Process null bitmap
843 if (in_buffer_idx == 0 && out_layout.buffers[0].kind == DataTypeLayout::BITMAP) {
844 // Copy input null bitmap
845 RETURN_NOT_OK(CheckInputAvailable());
846 const auto& in_data_item = in_data[in_layout_idx];
847 if (!out_field->nullable() && in_data_item->GetNullCount() != 0) {
848 return InvalidView("nulls in input cannot be viewed as non-nullable");
849 }
850 DCHECK_GT(in_data_item->buffers.size(), in_buffer_idx);
851 out_buffers.push_back(in_data_item->buffers[in_buffer_idx]);
852 out_length = in_data_item->length;
853 out_offset = in_data_item->offset;
854 out_null_count = in_data_item->null_count;
855 ++in_buffer_idx;
856 AdjustInputPointer();
857 } else {
858 // No null bitmap in input, append no-nulls bitmap
859 out_buffers.push_back(nullptr);
860 if (out_type->id() == Type::NA) {
861 out_null_count = out_length;
862 } else {
863 out_null_count = 0;
864 }
865 }
866
867 // Process other buffers in output layout
868 for (size_t out_buffer_idx = 1; out_buffer_idx < out_layout.buffers.size();
869 ++out_buffer_idx) {
870 const auto& out_spec = out_layout.buffers[out_buffer_idx];
871 // If always-null buffer is expected, just construct it
872 if (out_spec.kind == DataTypeLayout::ALWAYS_NULL) {
873 out_buffers.push_back(nullptr);
874 continue;
875 }
876
877 // If input buffer is null bitmap, try to ignore it
878 while (in_buffer_idx == 0) {
879 RETURN_NOT_OK(CheckInputAvailable());

Callers 1

GetArrayViewFunction · 0.80

Calls 11

nullableMethod · 0.80
GetNullCountMethod · 0.80
push_backMethod · 0.80
MakeFunction · 0.70
ARROW_ASSIGN_OR_RAISEFunction · 0.50
OKFunction · 0.50
typeMethod · 0.45
layoutMethod · 0.45
idMethod · 0.45
sizeMethod · 0.45
fieldsMethod · 0.45

Tested by

no test coverage detected