iota_analytics_indexer/writers/
mod.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use anyhow::Result;
6use iota_types::base_types::EpochId;
7use serde::Serialize;
8
9use crate::{FileFormat, ParquetSchema};
10
11pub mod csv_writer;
12pub mod parquet_writer;
13
14pub trait AnalyticsWriter<S: Serialize + ParquetSchema>: Send + Sync + 'static {
15    /// File format i.e. csv, parquet, etc
16    fn file_format(&self) -> Result<FileFormat>;
17    /// Persist given rows into a file
18    fn write(&mut self, rows: &[S]) -> Result<()>;
19    /// Flush the current file
20    fn flush(&mut self, end_checkpoint_seq_num: u64) -> Result<bool>;
21    /// Reset internal state with given epoch and checkpoint sequence number
22    fn reset(&mut self, epoch_num: EpochId, start_checkpoint_seq_num: u64) -> Result<()>;
23    /// Approx size in bytes of the current staging file if available
24    fn file_size(&self) -> Result<Option<u64>>;
25}