HuaHuaY commented on code in PR #50807:
URL: https://github.com/apache/arrow/pull/50807#discussion_r3893487769


##########
cpp/src/parquet/encoding_test.cc:
##########
@@ -466,6 +469,70 @@ TEST(TestDictionaryEncoding, CannotDictDecodeBoolean) {
   ASSERT_THROW(MakeDictDecoder<BooleanType>(nullptr), ParquetException);
 }
 
+template <typename DType, typename UInt, size_t NumValues>
+void TestFloatingDictionaryBits(const std::array<UInt, NumValues>& bits,
+                                int num_entries) {
+  using T = typename DType::c_type;
+  std::array<T, NumValues> values;
+  std::transform(bits.begin(), bits.end(), values.begin(),
+                 [](UInt value) { return ::arrow::util::SafeCopy<T>(value); });
+
+  auto encoder = MakeTypedEncoder<DType>(Encoding::PLAIN, true);
+  auto dictionary = dynamic_cast<DictEncoder<DType>*>(encoder.get());
+  ASSERT_NE(nullptr, dictionary);
+  encoder->Put(values.data(), values.size());
+  ASSERT_EQ(num_entries, dictionary->num_entries());
+
+  auto buffer = AllocateBuffer(default_memory_pool(), 
dictionary->dict_encoded_size());
+  dictionary->WriteDict(buffer->mutable_data());
+  const UInt* encoded = reinterpret_cast<const UInt*>(buffer->data());
+  for (int value_index = 0; value_index < num_entries; ++value_index) {
+    EXPECT_EQ(bits[value_index], encoded[value_index]);
+  }
+
+  using ArrowType = std::conditional_t<std::is_same_v<DType, FloatType>,
+                                       ::arrow::FloatType, 
::arrow::DoubleType>;
+  typename ::arrow::TypeTraits<ArrowType>::BuilderType builder;
+  ASSERT_OK(
+      builder.AppendValues(std::vector<T>(values.begin(), values.begin() + 
num_entries)));
+  std::shared_ptr<::arrow::Array> values_array;
+  ASSERT_OK(builder.Finish(&values_array));
+  auto direct_encoder = MakeTypedEncoder<DType>(Encoding::PLAIN, true);
+  auto direct_dictionary = 
dynamic_cast<DictEncoder<DType>*>(direct_encoder.get());
+  ASSERT_NE(nullptr, direct_dictionary);
+  direct_dictionary->PutDictionary(*values_array);
+  ASSERT_EQ(num_entries, direct_dictionary->num_entries());
+  auto direct_buffer =
+      AllocateBuffer(default_memory_pool(), 
direct_dictionary->dict_encoded_size());
+  direct_dictionary->WriteDict(direct_buffer->mutable_data());
+  const UInt* direct_encoded = reinterpret_cast<const 
UInt*>(direct_buffer->data());
+  for (int value_index = 0; value_index < num_entries; ++value_index) {
+    EXPECT_EQ(bits[value_index], direct_encoded[value_index]);
+  }
+}
+
+TEST(TestDictionaryEncoding, FloatingPointBits) {

Review Comment:
   I think we don't need to test that because float16 doesn't use 
`DictEncoderImpl<DType>::Put` but `DictEncoderImpl<FLBAType>::Put`, and 
`TestFloatingDictionaryBits` is not suitable for float16.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to