Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Use actual schema when writing, check rust fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
brad-richardson committed Jul 15, 2024
1 parent c2a5fa7 commit 7310917
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ jobs:
run: cargo bench
- name: Run clippy
run: cargo clippy --all-targets --all-features
- name: Run cargo fmt
run: cargo fmt --all -- --check
20 changes: 11 additions & 9 deletions src/osm_arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn osm_arrow_schema() -> Schema {

pub struct OSMArrowBuilder {
builders: Vec<Box<dyn ArrayBuilder>>,
schema: Schema,
schema: Arc<Schema>,
}

impl Default for OSMArrowBuilder {
Expand Down Expand Up @@ -138,7 +138,10 @@ impl OSMArrowBuilder {
}
}

OSMArrowBuilder { builders, schema }
OSMArrowBuilder {
builders,
schema: Arc::new(schema),
}
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -286,13 +289,12 @@ impl OSMArrowBuilder {
}

pub fn finish(&mut self) -> Result<RecordBatch, ArrowError> {
let field_arrays_iter = self
.schema
.fields()
.iter()
.zip(self.builders.iter_mut())
.map(|(field, builder)| (field.name(), builder.finish()));
let array_refs = self
.builders
.iter_mut()
.map(|builder| builder.finish())
.collect();

RecordBatch::try_from_iter(field_arrays_iter)
RecordBatch::try_new(self.schema.clone(), array_refs)
}
}

0 comments on commit 7310917

Please sign in to comment.