| 839 | } |
| 840 | |
| 841 | Status MakeNestedDictionary(std::shared_ptr<RecordBatch>* out) { |
| 842 | const int64_t length = 7; |
| 843 | |
| 844 | auto values0 = ArrayFromJSON(utf8(), "[\"foo\", \"bar\", \"baz\"]"); |
| 845 | auto values1 = ArrayFromJSON(int64(), "[1234567890, 987654321]"); |
| 846 | |
| 847 | // NOTE: it is important to test several levels of nesting, with non-trivial |
| 848 | // numbers of child fields, to exercise structural mapping of fields to dict ids. |
| 849 | |
| 850 | // Field 0: dict(int32, list(dict(int8, utf8))) |
| 851 | ARROW_ASSIGN_OR_RAISE(auto inner0, |
| 852 | DictionaryArray::FromArrays( |
| 853 | dictionary(int8(), values0->type()), |
| 854 | /*indices=*/ArrayFromJSON(int8(), "[0, 1, 2, null, 2, 1, 0]"), |
| 855 | /*dictionary=*/values0)); |
| 856 | |
| 857 | ARROW_ASSIGN_OR_RAISE(auto nested_values0, |
| 858 | ListArray::FromArrays( |
| 859 | /*offsets=*/*ArrayFromJSON(int32(), "[0, 3, 3, 6, 7]"), |
| 860 | /*values=*/*inner0)); |
| 861 | ARROW_ASSIGN_OR_RAISE( |
| 862 | auto outer0, DictionaryArray::FromArrays( |
| 863 | dictionary(int32(), nested_values0->type()), |
| 864 | /*indices=*/ArrayFromJSON(int32(), "[0, 1, 3, 3, null, 3, 2]"), |
| 865 | /*dictionary=*/nested_values0)); |
| 866 | DCHECK_EQ(outer0->length(), length); |
| 867 | |
| 868 | // Field 1: struct(a: dict(int8, int64), b: dict(int16, utf8)) |
| 869 | ARROW_ASSIGN_OR_RAISE( |
| 870 | auto inner1, DictionaryArray::FromArrays( |
| 871 | dictionary(int8(), values1->type()), |
| 872 | /*indices=*/ArrayFromJSON(int8(), "[0, 1, 1, null, null, 1, 0]"), |
| 873 | /*dictionary=*/values1)); |
| 874 | ARROW_ASSIGN_OR_RAISE( |
| 875 | auto inner2, DictionaryArray::FromArrays( |
| 876 | dictionary(int16(), values0->type()), |
| 877 | /*indices=*/ArrayFromJSON(int16(), "[2, 1, null, null, 2, 1, 0]"), |
| 878 | /*dictionary=*/values0)); |
| 879 | ARROW_ASSIGN_OR_RAISE( |
| 880 | auto outer1, StructArray::Make({inner1, inner2}, {field("a", inner1->type()), |
| 881 | field("b", inner2->type())})); |
| 882 | DCHECK_EQ(outer1->length(), length); |
| 883 | |
| 884 | // Field 2: dict(int8, struct(c: dict(int8, int64), d: dict(int16, list(dict(int8, |
| 885 | // utf8))))) |
| 886 | ARROW_ASSIGN_OR_RAISE(auto nested_values2, |
| 887 | ListArray::FromArrays( |
| 888 | /*offsets=*/*ArrayFromJSON(int32(), "[0, 1, 5, 5, 7]"), |
| 889 | /*values=*/*inner0)); |
| 890 | ARROW_ASSIGN_OR_RAISE( |
| 891 | auto inner3, DictionaryArray::FromArrays( |
| 892 | dictionary(int16(), nested_values2->type()), |
| 893 | /*indices=*/ArrayFromJSON(int16(), "[0, 1, 3, null, 3, 2, 1]"), |
| 894 | /*dictionary=*/nested_values2)); |
| 895 | ARROW_ASSIGN_OR_RAISE( |
| 896 | auto inner4, StructArray::Make({inner1, inner3}, {field("c", inner1->type()), |
| 897 | field("d", inner3->type())})); |
| 898 | ARROW_ASSIGN_OR_RAISE(auto outer2, |
nothing calls this directly
no test coverage detected