Skip to content

Commit 6fa4ff4

Browse files
committed
inline hashmap
Signed-off-by: Andrew Duffy <[email protected]>
1 parent 5c676c9 commit 6fa4ff4

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

vortex-file/src/strategy.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const ONE_MEG: u64 = 1 << 20;
3131
pub struct WriteStrategyBuilder {
3232
compressor: Option<Arc<dyn CompressorPlugin>>,
3333
row_block_size: usize,
34-
field_writers: Option<HashMap<FieldPath, Arc<dyn LayoutStrategy>>>,
34+
field_writers: HashMap<FieldPath, Arc<dyn LayoutStrategy>>,
3535
}
3636

3737
impl Default for WriteStrategyBuilder {
@@ -43,11 +43,11 @@ impl Default for WriteStrategyBuilder {
4343
impl WriteStrategyBuilder {
4444
/// Create a new empty builder. It can be further configured, and then finally built
4545
/// yielding the [`LayoutStrategy`].
46-
pub const fn new() -> Self {
46+
pub fn new() -> Self {
4747
Self {
4848
compressor: None,
4949
row_block_size: 8192,
50-
field_writers: None,
50+
field_writers: HashMap::new(),
5151
}
5252
}
5353

@@ -73,9 +73,7 @@ impl WriteStrategyBuilder {
7373
field: impl Into<FieldPath>,
7474
writer: Arc<dyn LayoutStrategy>,
7575
) -> Self {
76-
let mut writers = self.field_writers.unwrap_or_default();
77-
writers.insert(field.into(), writer);
78-
self.field_writers = Some(writers);
76+
self.field_writers.insert(field.into(), writer);
7977
self
8078
}
8179

@@ -143,14 +141,9 @@ impl WriteStrategyBuilder {
143141
// 0. start with splitting columns
144142
let validity_strategy = CollectStrategy::new(compress_then_flat);
145143

146-
let table_strategy = PathStrategy::new(Arc::new(validity_strategy), Arc::new(repartition));
147-
148144
// Take any field overrides from the builder and apply them to the final strategy.
149-
let table_strategy = if let Some(overrides) = self.field_writers {
150-
table_strategy.set_field_writers(overrides)
151-
} else {
152-
table_strategy
153-
};
145+
let table_strategy = PathStrategy::new(Arc::new(validity_strategy), Arc::new(repartition))
146+
.with_field_writers(self.field_writers);
154147

155148
Arc::new(table_strategy)
156149
}

vortex-file/tests/test_write_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async fn test_file_roundtrip() {
7474

7575
let writer = Arc::new(
7676
PathStrategy::new(Arc::new(FlatLayoutStrategy::default()), default_strategy)
77-
.set_field_writer(field_path!(a.raw), Arc::new(FlatLayoutStrategy::default())),
77+
.with_field_writer(field_path!(a.raw), Arc::new(FlatLayoutStrategy::default())),
7878
);
7979

8080
let mut bytes = Vec::new();

vortex-layout/src/layouts/path.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ impl PathStrategy {
103103
/// Arc::new(FlatLayoutStrategy::default()),
104104
/// Arc::new(compress_btrblocks),
105105
/// )
106-
/// .set_field_writer(
106+
/// .with_field_writer(
107107
/// field_path!(request.body.bytes),
108108
/// Arc::new(compress_compact),
109109
/// );
110110
/// ```
111-
pub fn set_field_writer(
111+
pub fn with_field_writer(
112112
mut self,
113113
field_path: impl Into<FieldPath>,
114114
writer: Arc<dyn LayoutStrategy>,
@@ -120,7 +120,7 @@ impl PathStrategy {
120120
/// Set writers for several fields at once.
121121
///
122122
/// See also: [`set_field_writer`][Self::set_field_writer].
123-
pub fn set_field_writers(
123+
pub fn with_field_writers(
124124
mut self,
125125
writers: impl IntoIterator<Item = (FieldPath, Arc<dyn LayoutStrategy>)>,
126126
) -> Self {

0 commit comments

Comments
 (0)