tustvold commented on code in PR #4389:
URL: https://github.com/apache/arrow-rs/pull/4389#discussion_r1225792348


##########
parquet/src/column/writer/mod.rs:
##########
@@ -668,19 +669,79 @@ impl<'a, E: ColumnValueEncoder> GenericColumnWriter<'a, 
E> {
                     self.column_index_builder.to_invalid();
                 }
                 Some(stat) => {
-                    self.column_index_builder.append(
-                        null_page,
-                        stat.min_bytes(),
-                        stat.max_bytes(),
-                        self.page_metrics.num_page_nulls as i64,
-                    );
+                    // We only truncate if the data is represented as binary
+                    match self.descr.physical_type() {
+                        Type::BYTE_ARRAY | Type::FIXED_LEN_BYTE_ARRAY => {
+                            self.column_index_builder.append(
+                                null_page,
+                                self.truncate_min_value(stat.min_bytes()),
+                                self.truncate_max_value(stat.max_bytes()),
+                                self.page_metrics.num_page_nulls as i64,
+                            );
+                        }
+                        _ => {
+                            self.column_index_builder.append(
+                                null_page,
+                                stat.min_bytes().to_vec(),
+                                stat.max_bytes().to_vec(),
+                                self.page_metrics.num_page_nulls as i64,
+                            );
+                        }
+                    }
                 }
             }
+
+            // update the offset index
+            self.offset_index_builder
+                .append_row_count(self.page_metrics.num_buffered_rows as i64);
         }
+    }
+
+    fn truncate_min_value(&self, data: &[u8]) -> Vec<u8> {
+        let effective_column_index_truncate_length = self

Review Comment:
   This can be written more concisely as
   
   ```
   self.props
       .column_index_truncate_length()
       .filter(|l| data.len() > *l)
       .and_then(|l| match str::from_utf8(data) {
           Ok(str_data) => truncate_utf8(str_data, l),
           Err(_) => truncate_binary(data, l),
       })
       .unwrap_or_else(|| data.to_vec())
   ```
   
   The `unwrap_or_else` also avoids allocating a vec if not needed



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