Skip to content

Commit 42322f8

Browse files
committed
Add coerce_types flag to parquet WriterProperties (apache#1938)
1 parent a999fb8 commit 42322f8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

parquet/src/file/properties.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ pub const DEFAULT_BLOOM_FILTER_FPP: f64 = 0.05;
5353
pub const DEFAULT_BLOOM_FILTER_NDV: u64 = 1_000_000_u64;
5454
/// Default values for [`WriterProperties::statistics_truncate_length`]
5555
pub const DEFAULT_STATISTICS_TRUNCATE_LENGTH: Option<usize> = None;
56+
/// Default values for [`WriterProperties::coerce_types`]
57+
pub const DEFAULT_COERCE_TYPES: bool = false;
5658

5759
/// Parquet writer version.
5860
///
@@ -139,6 +141,7 @@ pub struct WriterProperties {
139141
sorting_columns: Option<Vec<SortingColumn>>,
140142
column_index_truncate_length: Option<usize>,
141143
statistics_truncate_length: Option<usize>,
144+
coerce_types: bool,
142145
}
143146

144147
impl Default for WriterProperties {
@@ -251,6 +254,13 @@ impl WriterProperties {
251254
self.statistics_truncate_length
252255
}
253256

257+
/// Returns `coerce_types` boolean
258+
///
259+
/// `true` if type coercion enabled.
260+
pub fn coerce_types(&self) -> bool {
261+
self.coerce_types
262+
}
263+
254264
/// Returns encoding for a data page, when dictionary encoding is enabled.
255265
/// This is not configurable.
256266
#[inline]
@@ -345,6 +355,7 @@ pub struct WriterPropertiesBuilder {
345355
sorting_columns: Option<Vec<SortingColumn>>,
346356
column_index_truncate_length: Option<usize>,
347357
statistics_truncate_length: Option<usize>,
358+
coerce_types: bool,
348359
}
349360

350361
impl WriterPropertiesBuilder {
@@ -364,6 +375,7 @@ impl WriterPropertiesBuilder {
364375
sorting_columns: None,
365376
column_index_truncate_length: DEFAULT_COLUMN_INDEX_TRUNCATE_LENGTH,
366377
statistics_truncate_length: DEFAULT_STATISTICS_TRUNCATE_LENGTH,
378+
coerce_types: DEFAULT_COERCE_TYPES,
367379
}
368380
}
369381

@@ -383,6 +395,7 @@ impl WriterPropertiesBuilder {
383395
sorting_columns: self.sorting_columns,
384396
column_index_truncate_length: self.column_index_truncate_length,
385397
statistics_truncate_length: self.statistics_truncate_length,
398+
coerce_types: self.coerce_types,
386399
}
387400
}
388401

@@ -667,6 +680,13 @@ impl WriterPropertiesBuilder {
667680
self.statistics_truncate_length = max_length;
668681
self
669682
}
683+
684+
/// Sets flag to enable/disable type coercion.
685+
/// Takes precedence over globally defined settings.
686+
pub fn set_coerce_types(mut self, coerce_types: bool) -> Self {
687+
self.coerce_types = coerce_types;
688+
self
689+
}
670690
}
671691

672692
/// Controls the level of statistics to be computed by the writer

0 commit comments

Comments
 (0)