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

Function MakeDictionary

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

Source from the content-addressed store, hash-verified

735}
736
737Status MakeDictionary(std::shared_ptr<RecordBatch>* out) {
738 const int64_t length = 6;
739
740 std::vector<bool> is_valid = {true, true, false, true, true, true};
741
742 auto dict_ty = utf8();
743
744 auto dict1 = ArrayFromJSON(dict_ty, "[\"foo\", \"bar\", \"baz\"]");
745 auto dict2 = ArrayFromJSON(dict_ty, "[\"fo\", \"bap\", \"bop\", \"qup\"]");
746
747 auto f0_type = arrow::dictionary(arrow::int32(), dict_ty);
748 auto f1_type = arrow::dictionary(arrow::int8(), dict_ty, true);
749 auto f2_type = arrow::dictionary(arrow::int32(), dict_ty);
750
751 std::shared_ptr<Array> indices0, indices1, indices2;
752 std::vector<int32_t> indices0_values = {1, 2, -1, 0, 2, 0};
753 std::vector<int8_t> indices1_values = {0, 0, 2, 2, 1, 1};
754 std::vector<int32_t> indices2_values = {3, 0, 2, 1, 0, 2};
755
756 ArrayFromVector<Int32Type, int32_t>(is_valid, indices0_values, &indices0);
757 ArrayFromVector<Int8Type, int8_t>(is_valid, indices1_values, &indices1);
758 ArrayFromVector<Int32Type, int32_t>(is_valid, indices2_values, &indices2);
759
760 auto a0 = std::make_shared<DictionaryArray>(f0_type, indices0, dict1);
761 auto a1 = std::make_shared<DictionaryArray>(f1_type, indices1, dict1);
762 auto a2 = std::make_shared<DictionaryArray>(f2_type, indices2, dict2);
763
764 // Lists of dictionary-encoded strings
765 auto f3_type = list(f1_type);
766
767 auto indices3 = ArrayFromJSON(int8(), "[0, 1, 2, 0, 1, 1, 2, 1, 0]");
768 auto offsets3 = ArrayFromJSON(int32(), "[0, 0, 2, 2, 5, 6, 9]");
769
770 std::shared_ptr<Buffer> null_bitmap;
771 RETURN_NOT_OK(GetBitmapFromVector(is_valid, &null_bitmap));
772
773 std::shared_ptr<Array> a3 = std::make_shared<ListArray>(
774 f3_type, length, std::static_pointer_cast<PrimitiveArray>(offsets3)->values(),
775 std::make_shared<DictionaryArray>(f1_type, indices3, dict1), null_bitmap, 1);
776
777 // Dictionary-encoded lists of integers
778 auto dict4_ty = list(int8());
779 auto f4_type = dictionary(int8(), dict4_ty);
780
781 auto indices4 = ArrayFromJSON(int8(), "[0, 1, 2, 0, 2, 2]");
782 auto dict4 = ArrayFromJSON(dict4_ty, "[[44, 55], [], [66]]");
783 auto a4 = std::make_shared<DictionaryArray>(f4_type, indices4, dict4);
784
785 std::vector<std::shared_ptr<Field>> fields = {
786 field("dict1", f0_type), field("dict2", f1_type), field("dict3", f2_type),
787 field("list<encoded utf8>", f3_type), field("encoded list<int8>", f4_type)};
788 std::vector<std::shared_ptr<Array>> arrays = {a0, a1, a2, a3, a4};
789
790 // Ensure all dictionary index types are represented
791 int field_index = 5;
792 for (auto index_ty : all_dictionary_index_types()) {
793 std::stringstream ss;
794 ss << "dict" << field_index++;

Callers 5

TEST_FFunction · 0.85
ExampleDictSchemaFunction · 0.85
ExampleDictBatchesFunction · 0.85
BatchesFunction · 0.85

Calls 11

ArrayFromJSONFunction · 0.85
listFunction · 0.85
GetBitmapFromVectorFunction · 0.85
push_backMethod · 0.80
strMethod · 0.80
schemaFunction · 0.70
dictionaryFunction · 0.50
fieldFunction · 0.50
MakeFunction · 0.50
OKFunction · 0.50
valuesMethod · 0.45

Tested by

no test coverage detected