| 1077 | } |
| 1078 | |
| 1079 | void DictPutIndices() { |
| 1080 | if (std::is_same<ParquetType, BooleanType>::value) { |
| 1081 | return; |
| 1082 | } |
| 1083 | |
| 1084 | auto dict_values = ::arrow::ArrayFromJSON( |
| 1085 | arrow_type(), std::is_same<ParquetType, FLBAType>::value |
| 1086 | ? R"(["abcdefgh", "ijklmnop", "qrstuvwx"])" |
| 1087 | : "[120, -37, 47]"); |
| 1088 | auto indices = ::arrow::ArrayFromJSON(::arrow::int32(), "[0, 1, 2]"); |
| 1089 | auto indices_nulls = |
| 1090 | ::arrow::ArrayFromJSON(::arrow::int32(), "[null, 0, 1, null, 2]"); |
| 1091 | |
| 1092 | auto expected = ::arrow::ArrayFromJSON( |
| 1093 | arrow_type(), std::is_same<ParquetType, FLBAType>::value |
| 1094 | ? R"(["abcdefgh", "ijklmnop", "qrstuvwx", null, |
| 1095 | "abcdefgh", "ijklmnop", null, "qrstuvwx"])" |
| 1096 | : "[120, -37, 47, null, " |
| 1097 | "120, -37, null, 47]"); |
| 1098 | |
| 1099 | auto owned_encoder = |
| 1100 | MakeTypedEncoder<ParquetType>(Encoding::PLAIN, |
| 1101 | /*use_dictionary=*/true, column_descr()); |
| 1102 | auto owned_decoder = MakeDictDecoder<ParquetType>(column_descr()); |
| 1103 | |
| 1104 | auto encoder = dynamic_cast<DictEncoder<ParquetType>*>(owned_encoder.get()); |
| 1105 | |
| 1106 | ASSERT_NO_THROW(encoder->PutDictionary(*dict_values)); |
| 1107 | |
| 1108 | // Trying to call PutDictionary again throws |
| 1109 | ASSERT_THROW(encoder->PutDictionary(*dict_values), ParquetException); |
| 1110 | |
| 1111 | ASSERT_NO_THROW(encoder->PutIndices(*indices)); |
| 1112 | ASSERT_NO_THROW(encoder->PutIndices(*indices_nulls)); |
| 1113 | |
| 1114 | std::shared_ptr<Buffer> buf, dict_buf; |
| 1115 | int num_values = static_cast<int>(expected->length() - expected->null_count()); |
| 1116 | |
| 1117 | std::unique_ptr<TypedDecoder<ParquetType>> decoder; |
| 1118 | GetDictDecoder(encoder, num_values, &buf, &dict_buf, column_descr(), &decoder); |
| 1119 | |
| 1120 | BuilderType acc(arrow_type(), ::arrow::default_memory_pool()); |
| 1121 | ASSERT_EQ(num_values, decoder->DecodeArrow(static_cast<int>(expected->length()), |
| 1122 | static_cast<int>(expected->null_count()), |
| 1123 | expected->null_bitmap_data(), |
| 1124 | expected->offset(), &acc)); |
| 1125 | |
| 1126 | std::shared_ptr<::arrow::Array> result; |
| 1127 | ASSERT_OK(acc.Finish(&result)); |
| 1128 | ASSERT_OK(result->ValidateFull()); |
| 1129 | ::arrow::AssertArraysEqual(*expected, *result); |
| 1130 | } |
| 1131 | |
| 1132 | protected: |
| 1133 | const int64_t size_ = 50; |
no test coverage detected