Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions crates/ourios-parquet/src/audit_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,32 @@ impl AuditReader {
path: path.to_path_buf(),
source,
})?;
Self::from_chunk_reader(file, path.to_path_buf())
}

/// Open an audit file from in-memory bytes — the RFC 0019 `Store` read path
/// (`Store::get_blocking` → bytes → here), so the audit scan reads through
/// the object-storage seam (local or S3) rather than `std::fs`. Skips
/// row-vs-path validation like [`Self::open_file`]; there is no filesystem
/// access, so no [`AuditReaderError::Io`] is produced.
///
/// # Errors
///
/// [`AuditReaderError::Parquet`] / [`AuditReaderError::MissingRequiredColumn`]
/// as [`Self::open_file`].
pub fn open_bytes(bytes: bytes::Bytes) -> Result<Self, AuditReaderError> {
Self::from_chunk_reader(bytes, PathBuf::from("<object-store>"))
}

/// Build the reader from any Parquet [`ChunkReader`] (a `File` or in-memory
/// `Bytes`), enforcing the §3.7 baseline-REQUIRED-column check. Shared by
/// [`Self::open_file`] and [`Self::open_bytes`].
fn from_chunk_reader<R: parquet::file::reader::ChunkReader + 'static>(
reader: R,
file_path: PathBuf,
) -> Result<Self, AuditReaderError> {
let builder =
ParquetRecordBatchReaderBuilder::try_new(file).map_err(AuditReaderError::Parquet)?;
ParquetRecordBatchReaderBuilder::try_new(reader).map_err(AuditReaderError::Parquet)?;

let file_schema = builder.schema();
for expected_field in crate::audit_schema().fields() {
Expand All @@ -110,7 +133,7 @@ impl AuditReader {
Ok(Self {
inner,
partition: None,
file_path: path.to_path_buf(),
file_path,
})
}

Expand Down
25 changes: 25 additions & 0 deletions crates/ourios-parquet/tests/audit_round_trip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,31 @@ fn rfc0005_7_audit_round_trip_one_of_each_variant() {
}
}

/// `AuditReader::open_bytes` reads an audit file from in-memory bytes — the
/// RFC 0019 `Store` read path the querier's audit scan moves onto (so the scan
/// reads through the object-storage seam, local or S3, rather than `std::fs`).
/// The events round-trip identically to the on-disk `open_file` path.
#[test]
fn audit_reader_open_bytes_round_trips() {
let bucket = TempDir::new().unwrap();
let events = three_variants("acme");
let partition = audit_partition_for(&events[0]);

let mut writer = AuditWriter::open(bucket.path(), partition).expect("open");
writer.append_events(&events).expect("append");
let written = writer.close().expect("close");

// Read the written object's raw bytes and parse them through `open_bytes`
// (the bytes a `Store::get_blocking` returns on the migrated scan path).
let bytes = std::fs::read(&written.path).expect("read file bytes");
let round_tripped = AuditReader::open_bytes(bytes::Bytes::from(bytes))
.expect("open_bytes")
.read_all()
.expect("read_all");

assert_eq!(round_tripped, events, "open_bytes round-trips every event");
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

/// Scenario RFC0017.1 (storage round-trip) — the `template_created` variant
/// round-trips through the audit file series. Full `AuditEvent` equality
/// confirms `new_template` survives and the reader reconstructs `Created`
Expand Down
Loading