-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move RecordBatchReader out of geozero code
- Loading branch information
1 parent
c164f6b
commit 5a4f730
Showing
10 changed files
with
57 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ pub mod ipc; | |
pub mod parquet; | ||
#[cfg(feature = "postgis")] | ||
pub mod postgis; | ||
pub mod stream; | ||
pub mod wkb; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::error::GeoArrowError; | ||
use crate::table::Table; | ||
use arrow_array::{RecordBatchIterator, RecordBatchReader as _RecordBatchReader}; | ||
use arrow_schema::SchemaRef; | ||
|
||
/// A wrapper around an [arrow_array::RecordBatchReader] so that we can impl the GeozeroDatasource | ||
/// trait. | ||
pub struct RecordBatchReader(Option<Box<dyn _RecordBatchReader>>); | ||
|
||
impl RecordBatchReader { | ||
pub fn new(reader: Box<dyn _RecordBatchReader>) -> Self { | ||
Self(Some(reader)) | ||
} | ||
|
||
pub fn schema(&self) -> Result<SchemaRef, GeoArrowError> { | ||
let reader = self | ||
.0 | ||
.as_ref() | ||
.ok_or(GeoArrowError::General("Closed stream".to_string()))?; | ||
Ok(reader.schema()) | ||
} | ||
|
||
pub fn take(&mut self) -> Option<Box<dyn _RecordBatchReader>> { | ||
self.0.take() | ||
} | ||
} | ||
|
||
impl From<Table> for RecordBatchReader { | ||
fn from(value: Table) -> Self { | ||
let (schema, batches) = value.into_inner(); | ||
Self(Some(Box::new(RecordBatchIterator::new( | ||
batches.into_iter().map(Ok), | ||
schema, | ||
)))) | ||
} | ||
} | ||
|
||
impl From<Box<dyn _RecordBatchReader>> for RecordBatchReader { | ||
fn from(value: Box<dyn _RecordBatchReader>) -> Self { | ||
Self(Some(value)) | ||
} | ||
} | ||
|
||
impl From<Box<dyn _RecordBatchReader + Send>> for RecordBatchReader { | ||
fn from(value: Box<dyn _RecordBatchReader + Send>) -> Self { | ||
Self(Some(value)) | ||
} | ||
} |