HuaHuaY commented on code in PR #47427:
URL: https://github.com/apache/arrow/pull/47427#discussion_r2301414271
##########
cpp/src/parquet/arrow/arrow_reader_writer_test.cc:
##########
@@ -5468,6 +5532,86 @@ TYPED_TEST(TestIntegerAnnotateDecimalTypeParquetIO,
SingleNullableDecimalColumn)
ASSERT_NO_FATAL_FAILURE(this->ReadAndCheckSingleDecimalColumnFile(*values));
}
+template <typename TestType>
+class TestIntegerAnnotateSmallestDecimalTypeParquetIO
+ : public TestIntegerAnnotateDecimalTypeParquetIO<TestType> {
+ public:
+ void ReadAndCheckSingleDecimalColumnFile(const Array& values) {
+ ArrowReaderProperties properties = default_arrow_reader_properties();
+ properties.set_smallest_decimal_enabled(true);
+
+ std::shared_ptr<Array> out;
+ std::unique_ptr<FileReader> reader;
+ this->ReaderFromSink(&reader, properties);
+ this->ReadSingleColumnFile(std::move(reader), &out);
+
+ if (values.type()->id() == out->type()->id()) {
+ AssertArraysEqual(values, *out);
+ } else {
+ auto& expected_values = values;
+ auto& read_values = *out;
+ ASSERT_EQ(expected_values.length(), read_values.length());
+ ASSERT_EQ(expected_values.null_count(), read_values.null_count());
+
+ auto format_decimal = [](const Array& values, int64_t index) {
+ switch (values.type()->id()) {
+ case ::arrow::Type::DECIMAL32:
+ return static_cast<const
::arrow::Decimal32Array&>(values).FormatValue(index);
+ case ::arrow::Type::DECIMAL64:
+ return static_cast<const
::arrow::Decimal64Array&>(values).FormatValue(index);
+ case ::arrow::Type::DECIMAL128:
+ return static_cast<const
::arrow::Decimal128Array&>(values).FormatValue(
+ index);
+ case ::arrow::Type::DECIMAL256:
+ return static_cast<const
::arrow::Decimal256Array&>(values).FormatValue(
+ index);
+ default:
+ std::string err("Unexpected decimal type: " +
values.type()->ToString());
+ ADD_FAILURE() << err;
+ return err;
+ }
+ };
+
+ for (int64_t i = 0; i < expected_values.length(); ++i) {
+ ASSERT_EQ(expected_values.IsNull(i), read_values.IsNull(i));
+ if (!expected_values.IsNull(i)) {
+ std::string expected_str = format_decimal(expected_values, i);
+ std::string read_str = format_decimal(read_values, i);
+ ASSERT_EQ(expected_str, read_str);
+ }
+ }
+ }
+ }
+};
+
+using SmallestDecimalTestTypes = ::testing::Types<
+ Decimal32WithPrecisionAndScale<1>, Decimal32WithPrecisionAndScale<5>,
+ Decimal32WithPrecisionAndScale<9>, Decimal64WithPrecisionAndScale<1>,
+ Decimal64WithPrecisionAndScale<5>, Decimal64WithPrecisionAndScale<10>,
+ Decimal64WithPrecisionAndScale<18>, Decimal128WithPrecisionAndScale<1>,
+ Decimal128WithPrecisionAndScale<5>, Decimal128WithPrecisionAndScale<10>,
+ Decimal128WithPrecisionAndScale<18>, Decimal256WithPrecisionAndScale<1>,
+ Decimal256WithPrecisionAndScale<5>, Decimal256WithPrecisionAndScale<10>,
+ Decimal256WithPrecisionAndScale<18>>;
+
+TYPED_TEST_SUITE(TestIntegerAnnotateSmallestDecimalTypeParquetIO,
+ SmallestDecimalTestTypes);
+
+TYPED_TEST(TestIntegerAnnotateSmallestDecimalTypeParquetIO,
+ SingleNonNullableDecimalColumn) {
+ std::shared_ptr<Array> values;
+ ASSERT_OK(NonNullArray<TypeParam>(SMALL_SIZE, &values));
+ ASSERT_NO_FATAL_FAILURE(this->WriteColumn(values));
Review Comment:
In this case `store_schema` is not set and
`ReadAndCheckSingleDecimalColumnFile` will compare decimal's format string
instead of comparing decimal values. This flag is set in `TEST(ArrowReadWrite,
Decimal32)` and `TEST(ArrowReadWrite, Decimal64)`.
--
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]