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

Write json to custom path #2135

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions nautilus_core/persistence/src/backend/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,17 @@ impl ParquetDataCatalog {
}

#[must_use]
pub fn write_to_json<T>(&self, data: Vec<T>) -> PathBuf
pub fn write_to_json<T>(&self, data: Vec<T>, path: Option<PathBuf>) -> PathBuf
where
T: GetTsInit + Serialize,
{
let type_name = std::any::type_name::<T>().to_snake_case();
Self::check_ascending_timestamps(&data, &type_name);

let path = self.make_path(&type_name, None);
let json_path = path.with_extension("json");
let json_path = path.unwrap_or_else(|| {
let path = self.make_path(&type_name, None);
path.with_extension("json")
});

info!(
"Writing {} records of {} data to {:?}",
Expand Down
4 changes: 2 additions & 2 deletions nautilus_core/persistence/tests/test_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ fn test_catalog_serialization_json_round_trip() {
let quote_ticks: Vec<QuoteTick> = to_variant(quote_ticks);

// Write to JSON using catalog
let json_path = catalog.write_to_json(quote_ticks.clone());
let json_path = catalog.write_to_json(quote_ticks.clone(), None);

// Read back from JSON
let json_str = std::fs::read_to_string(json_path).unwrap();
Expand Down Expand Up @@ -393,7 +393,7 @@ fn test_datafusion_parquet_round_trip() {
let mut temp_file = std::fs::File::create(&temp_file_path).unwrap();
{
let writer_props = WriterProperties::builder()
.set_compression(Compression::ZSTD(ZstdLevel::default()))
.set_compression(Compression::SNAPPY)
.set_max_row_group_size(1000)
.build();

Expand Down
Loading