etseidl commented on code in PR #9700:
URL: https://github.com/apache/arrow-rs/pull/9700#discussion_r3080951829


##########
parquet/src/arrow/arrow_writer/mod.rs:
##########
@@ -4827,6 +4895,48 @@ mod tests {
         assert_eq!(get_dict_page_size(col1_meta), 1024 * 1024 * 4);
     }
 
+    #[test]
+    fn test_dict_page_size_decided_by_compression_fallback() {

Review Comment:
   As a test, I saved the output from this and examined the sizing. Without the 
heuristic, the encoded size for col0 is 8658384 bytes (the default fallback 
mechanism kicked in after 7 pages). With the heuristic, col1 is 8391126 bytes, 
a savings of 3%. 
   
   I also modified the test to mod the index with 32767. In that instance, col1 
was still 8391126 bytes, but col0 was only 2231581, nearly 4X smaller.
   
   I know this is not entirely representative, but it does again point out the 
pitfalls of too simplistic an approach.
   



##########
parquet/src/column/writer/encoder.rs:
##########
@@ -109,6 +109,12 @@ pub trait ColumnValueEncoder {
     /// <already_written_encoded_byte_size> + 
<estimated_encoded_size_of_unflushed_bytes>
     fn estimated_data_page_size(&self) -> usize;
 
+    /// Returns the estimated size of plainly encoded data, in bytes,
+    /// that would be written without a dictionary.
+    /// If there is no dictionary, or the data size statistic is not available,
+    /// returns `None`.
+    fn uncompressed_data_size(&self) -> Option<usize>;

Review Comment:
   To avoid confusion I'd prefer this be named `plain_encoded_data_size` or 
some such. To me, compression is performed on the page after encoding.



##########
parquet/src/encodings/encoding/plain_counter.rs:
##########
@@ -0,0 +1,75 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::basic::Type;
+use crate::data_type::private::ParquetValueType;
+use crate::schema::types::ColumnDescriptor;
+
+/// A helper to estimate the size of plain encoding of the values
+/// that were written to the dictionary encoder.
+///
+/// This is used to enhance the dictionary fallback heuristic with the logic
+/// that the writer should fall back to the plain encoding when at a certain 
point,
+/// e.g. after encoding the first batch, the total size of unencoded data
+/// is calculated as smaller than `(encodedSize + dictionarySize)`.
+pub struct PlainDataSizeCounter {

Review Comment:
   To my comment about sample size, perhaps this can be adapted to keep track 
of both the plain and dictionary encoded sizes, and then only make a decision 
after some critical number of rows or bytes have been processed.



##########
parquet/src/data_type.rs:
##########
@@ -1071,9 +1081,8 @@ pub(crate) mod private {
             Ok(num_values)
         }
 
-        #[inline]
-        fn dict_encoding_size(&self) -> (usize, usize) {
-            (std::mem::size_of::<u32>(), self.len())
+        fn dict_encoding_size(&self) -> usize {
+            4 + self.len()
         }

Review Comment:
   To be fair, there's magic all over this module. But I agree with @EmilyMatt 
there's no need to add more.



-- 
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