Skip to content

Commit

Permalink
Add ArrowWriter doctest (apache#1927)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Jun 23, 2022
1 parent 9cd591d commit a503cfd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions parquet/src/arrow/arrow_writer/mod.rs
Expand Up @@ -48,6 +48,27 @@ mod levels;
/// to produce row groups with `max_row_group_size` rows. Any remaining rows will be
/// flushed on close, leading the final row group in the output file to potentially
/// contain fewer than `max_row_group_size` rows
///
/// ```
/// # use std::sync::Arc;
/// # use bytes::Bytes;
/// # use arrow::array::{ArrayRef, Int64Array};
/// # use arrow::record_batch::RecordBatch;
/// # use parquet::arrow::{ArrowReader, ArrowWriter, ParquetFileArrowReader};
/// let col = Arc::new(Int64Array::from_iter_values([1, 2, 3])) as ArrayRef;
/// let to_write = RecordBatch::try_from_iter([("col", col)]).unwrap();
///
/// let mut buffer = Vec::new();
/// let mut writer = ArrowWriter::try_new(&mut buffer, to_write.schema(), None).unwrap();
/// writer.write(&to_write).unwrap();
/// writer.close().unwrap();
///
/// let mut reader = ParquetFileArrowReader::try_new(Bytes::from(buffer)).unwrap();
/// let mut reader = reader.get_record_reader(1024).unwrap();
/// let read = reader.next().unwrap().unwrap();
///
/// assert_eq!(to_write, read);
/// ```
pub struct ArrowWriter<W: Write> {
/// Underlying Parquet writer
writer: SerializedFileWriter<W>,
Expand Down
2 changes: 2 additions & 0 deletions parquet/src/util/cursor.rs
Expand Up @@ -206,6 +206,8 @@ impl Seek for InMemoryWriteableCursor {

#[cfg(test)]
mod tests {
use arrow::record_batch::RecordBatch;
use crate::arrow::ArrowWriter;
use super::*;

/// Create a SliceableCursor of all u8 values in ascending order
Expand Down

0 comments on commit a503cfd

Please sign in to comment.