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

Function MakeUnion

cpp/src/arrow/ipc/test_common.cc:685–735  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

683}
684
685Status MakeUnion(std::shared_ptr<RecordBatch>* out) {
686 // Define schema
687 std::vector<std::shared_ptr<Field>> union_fields(
688 {field("u0", int32()), field("u1", uint8())});
689
690 std::vector<int8_t> type_codes = {5, 10};
691 auto sparse_type = sparse_union(union_fields, type_codes);
692 auto dense_type = dense_union(union_fields, type_codes);
693
694 auto f0 = field("sparse", sparse_type);
695 auto f1 = field("dense", dense_type);
696
697 auto schema = ::arrow::schema({f0, f1});
698
699 // Create data
700 std::vector<std::shared_ptr<Array>> sparse_children(2);
701 std::vector<std::shared_ptr<Array>> dense_children(2);
702
703 const int64_t length = 7;
704
705 std::shared_ptr<Buffer> type_ids_buffer;
706 std::vector<uint8_t> type_ids = {5, 10, 5, 5, 10, 10, 5};
707 RETURN_NOT_OK(CopyBufferFromVector(type_ids, default_memory_pool(), &type_ids_buffer));
708
709 std::vector<int32_t> u0_values = {0, 1, 2, 3, 4, 5, 6};
710 ArrayFromVector<Int32Type, int32_t>(u0_values, &sparse_children[0]);
711
712 std::vector<uint8_t> u1_values = {10, 11, 12, 13, 14, 15, 16};
713 ArrayFromVector<UInt8Type, uint8_t>(u1_values, &sparse_children[1]);
714
715 // dense children
716 u0_values = {0, 2, 3, 7};
717 ArrayFromVector<Int32Type, int32_t>(u0_values, &dense_children[0]);
718
719 u1_values = {11, 14, 15};
720 ArrayFromVector<UInt8Type, uint8_t>(u1_values, &dense_children[1]);
721
722 std::shared_ptr<Buffer> offsets_buffer;
723 std::vector<int32_t> offsets = {0, 0, 1, 2, 1, 2, 3};
724 RETURN_NOT_OK(CopyBufferFromVector(offsets, default_memory_pool(), &offsets_buffer));
725
726 auto sparse = std::make_shared<SparseUnionArray>(sparse_type, length, sparse_children,
727 type_ids_buffer);
728 auto dense = std::make_shared<DenseUnionArray>(dense_type, length, dense_children,
729 type_ids_buffer, offsets_buffer);
730
731 // construct batch
732 std::vector<std::shared_ptr<Array>> arrays = {sparse, dense};
733 *out = RecordBatch::Make(schema, length, arrays);
734 return Status::OK();
735}
736
737Status MakeDictionary(std::shared_ptr<RecordBatch>* out) {
738 const int64_t length = 6;

Callers 3

TESTFunction · 0.85
TESTFunction · 0.85
BatchesFunction · 0.85

Calls 8

sparse_unionFunction · 0.85
dense_unionFunction · 0.85
CopyBufferFromVectorFunction · 0.85
default_memory_poolFunction · 0.85
schemaFunction · 0.70
fieldFunction · 0.50
MakeFunction · 0.50
OKFunction · 0.50

Tested by

no test coverage detected