-
Notifications
You must be signed in to change notification settings - Fork 3
Keep writer state across batches #107
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,6 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use core::time; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| collections::HashMap, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fs::File, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| io::{Read, Seek, Write}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path::{Path, PathBuf}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -7,8 +9,8 @@ use std::{ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use arrow::{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| array::{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Array, ArrayRef, ArrowPrimitiveType, AsArray, PrimitiveArray, RecordBatch, StringArray, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StringBuilder, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Array, ArrayRef, ArrowPrimitiveType, AsArray, PrimitiveArray, RecordBatch, Scalar, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StringArray, StringBuilder, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| datatypes::{DataType, Field, Schema, SchemaRef}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -302,6 +304,93 @@ pub struct AsyncOdvWriter<W: AsyncWrite + Unpin + Send> { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| trajectory_file: OdvFile<Trajectories, File>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| zip_file_writer: ZipFileWriter<W>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Key entry cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| trajectory_profile_key_entry_state: Option<FileWriterState>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| trajectory_time_series_key_entry_state: Option<FileWriterState>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct FileWriterState { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| entry_key: Scalar<ArrayRef>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key_state: KeyEntryState, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| impl FileWriterState { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn is_equal_entry_key(&self, other_key: &Scalar<ArrayRef>) -> bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let eq_array = arrow::compute::kernels::cmp::eq(&self.entry_key, other_key).unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| eq_array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .as_any() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .downcast_ref::<arrow::array::BooleanArray>() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .unwrap() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .value(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn is_equal_key_state(&self, other_state: &KeyEntryState) -> bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.key_state == *other_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[derive(Default, Clone)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct KeyEntryState { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| key: Vec<Scalar<ArrayRef>>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| count: usize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| impl KeyEntryState { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn new(key: Vec<Scalar<ArrayRef>>) -> Self { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Self { key, count: 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| impl PartialEq for KeyEntryState { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn eq(&self, other: &Self) -> bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if self.key.len() != other.key.len() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (a, b) in self.key.iter().zip(other.key.iter()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let eq_array = arrow::compute::kernels::cmp::eq(a, b).unwrap(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if eq_array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .as_any() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .downcast_ref::<arrow::array::BooleanArray>() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .unwrap() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .value(0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| == false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+353
to
+358
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if eq_array | |
| .as_any() | |
| .downcast_ref::<arrow::array::BooleanArray>() | |
| .unwrap() | |
| .value(0) | |
| == false | |
| if !eq_array | |
| .as_any() | |
| .downcast_ref::<arrow::array::BooleanArray>() | |
| .unwrap() | |
| .value(0) |
Copilot
AI
Oct 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern of checking is_none() followed by a match on as_mut() creates redundant logic. Since you initialize the state if it's None on line 779, the None => 0 case on line 802 is unreachable. Consider removing the None arm or restructuring to use get_or_insert_with.
| let count = match profile_file_state.as_mut() { | |
| Some(state) => { | |
| if state.is_equal_entry_key(&entry_key_scalar) { | |
| if state.is_equal_key_state(¤t_entry_key_state) { | |
| state.key_state.count | |
| } else { | |
| state.key_state.count += 1; | |
| state.key_state.count | |
| } | |
| } else { | |
| state.entry_key = entry_key_scalar; | |
| state.key_state = | |
| KeyEntryState::new(vec![timestamp_scalar.clone()]); | |
| state.key_state.count | |
| } | |
| } | |
| None => 0, | |
| let state = profile_file_state.as_mut().unwrap(); | |
| let count = if state.is_equal_entry_key(&entry_key_scalar) { | |
| if state.is_equal_key_state(¤t_entry_key_state) { | |
| state.key_state.count | |
| } else { | |
| state.key_state.count += 1; | |
| state.key_state.count | |
| } | |
| } else { | |
| state.entry_key = entry_key_scalar; | |
| state.key_state = | |
| KeyEntryState::new(vec![timestamp_scalar.clone()]); | |
| state.key_state.count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
use core::time;import appears to be unused. Consider removing this import unless it's required elsewhere in the file.