sui_analytics_indexer/writers/
mod.rs

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