You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "westonpace (via GitHub)" <gi...@apache.org> on 2023/03/24 16:44:17 UTC

[GitHub] [arrow] westonpace commented on a diff in pull request #34720: GH-34633: [C++][Parquet] Fix StreamReader to read decimals

westonpace commented on code in PR #34720:
URL: https://github.com/apache/arrow/pull/34720#discussion_r1147827525


##########
cpp/src/parquet/stream_reader.cc:
##########
@@ -173,6 +174,60 @@ StreamReader& StreamReader::operator>>(std::string& v) {
   return *this;
 }
 
+StreamReader& StreamReader::operator>>(::arrow::Decimal128& v) {

Review Comment:
   Is there anyway to avoid repeating the implementation here?  For example, would something like this work?
   
   ```
   StreamReader& StreamReader::operator>>(::arrow::Decimal128& v) {
     std::optional<::arrow::Decimal128> maybe_v;
     this >> maybe_v;
     if (!maybe_v) {
       // I'm not sure what happens here, maybe throw an exception?
     }
     v = *maybe_v;
     return this;
   }
   ```



##########
cpp/src/parquet/stream_reader_test.cc:
##########
@@ -912,5 +913,39 @@ TEST_F(TestReadingDataFiles, Int64Decimal) {
   EXPECT_EQ(i, 25);
 }
 
+TEST_F(TestReadingDataFiles, FLBADecimal) {
+  PARQUET_ASSIGN_OR_THROW(auto infile, ::arrow::io::ReadableFile::Open(
+                                           GetDataFile("fixed_length_decimal.parquet")));
+
+  auto file_reader = ParquetFileReader::Open(infile);
+  auto reader = StreamReader{std::move(file_reader)};
+
+  ::arrow::Decimal128 x;
+  int i = 0;
+
+  for (i = 1; !reader.eof(); ++i) {
+    reader >> x >> EndRow;
+    EXPECT_EQ(x.ToString(2), ::arrow::Decimal128(i * 100).ToString(2));

Review Comment:
   Why `ToString`.  Can't we compare the decimals directly?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org