Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IPC row count info in IPC reader #1796

Merged
merged 3 commits into from
Jun 6, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 25 additions & 3 deletions arrow/src/ipc/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::compute::cast;
use crate::datatypes::{DataType, Field, IntervalUnit, Schema, SchemaRef, UnionMode};
use crate::error::{ArrowError, Result};
use crate::ipc;
use crate::record_batch::{RecordBatch, RecordBatchReader};
use crate::record_batch::{RecordBatch, RecordBatchOptions, RecordBatchReader};

use ipc::CONTINUATION_MARKER;
use DataType::*;
Expand Down Expand Up @@ -608,6 +608,11 @@ pub fn read_record_batch(
let mut node_index = 0;
let mut arrays = vec![];

let options = RecordBatchOptions {
match_field_names: true,
row_count: Some(batch.length() as usize),
};
viirya marked this conversation as resolved.
Show resolved Hide resolved

if let Some(projection) = projection {
// project fields
for (idx, field) in schema.fields().iter().enumerate() {
Expand Down Expand Up @@ -643,7 +648,11 @@ pub fn read_record_batch(
}
}

RecordBatch::try_new(Arc::new(schema.project(projection)?), arrays)
RecordBatch::try_new_with_options(
Arc::new(schema.project(projection)?),
arrays,
&options,
)
} else {
// keep track of index as lists require more than one node
for field in schema.fields() {
Expand All @@ -661,7 +670,7 @@ pub fn read_record_batch(
buffer_index = triple.2;
arrays.push(triple.0);
}
RecordBatch::try_new(schema, arrays)
RecordBatch::try_new_with_options(schema, arrays, &options)
}
}

Expand Down Expand Up @@ -1933,4 +1942,17 @@ mod tests {
let output_batch = roundtrip_ipc_stream(&input_batch);
assert_eq!(input_batch, output_batch);
}

#[test]
fn test_no_columns_batch() {
let schema = Arc::new(Schema::new(vec![]));
let options = RecordBatchOptions {
match_field_names: true,
row_count: Some(10),
};
let input_batch =
RecordBatch::try_new_with_options(schema, vec![], &options).unwrap();
let output_batch = roundtrip_ipc_stream(&input_batch);
assert_eq!(input_batch, output_batch);
}
}