pub struct SqlExporter {
pub batch_size: usize,
pub drop_existing: bool,
pub if_not_exists: bool,
}Expand description
Generates SQL DDL and DML statements for TSDB data.
SqlExporter is stateless: each method takes the relevant inputs and
returns a String. No database connection is required.
Fields§
§batch_size: usizeNumber of rows per batched INSERT statement (0 = all rows in one statement).
drop_existing: boolWhen true, a DROP TABLE IF EXISTS is emitted before CREATE TABLE.
if_not_exists: boolWhen true, IF NOT EXISTS is added to CREATE TABLE.
Implementations§
Source§impl SqlExporter
impl SqlExporter
Sourcepub fn with_batch_size(self, size: usize) -> Self
pub fn with_batch_size(self, size: usize) -> Self
Set batch size.
Sourcepub fn with_drop_existing(self, drop: bool) -> Self
pub fn with_drop_existing(self, drop: bool) -> Self
Include DROP TABLE IF EXISTS before CREATE TABLE.
Sourcepub fn create_table_sql(&self, schema: &MetricSchema) -> String
pub fn create_table_sql(&self, schema: &MetricSchema) -> String
Generate a CREATE TABLE statement for the given schema.
Sourcepub fn insert_sql(
&self,
schema: &MetricSchema,
points: &[SqlDataPoint],
) -> Vec<String>
pub fn insert_sql( &self, schema: &MetricSchema, points: &[SqlDataPoint], ) -> Vec<String>
Generate a batched INSERT INTO statement for a slice of points.
Points are split into chunks of batch_size (or all at once if
batch_size == 0). Returns a Vec of SQL strings, one per batch.
Sourcepub fn export_to_sql_file(
&self,
schema: &MetricSchema,
points: &[SqlDataPoint],
path: &Path,
) -> TsdbResult<()>
pub fn export_to_sql_file( &self, schema: &MetricSchema, points: &[SqlDataPoint], path: &Path, ) -> TsdbResult<()>
Generate a complete SQL script (DDL + DML) and write it to path.
The script contains:
CREATE TABLE(and optionallyDROP TABLE IF EXISTS).- All
INSERT INTObatches.
Sourcepub fn select_range_sql(
&self,
schema: &MetricSchema,
start_ms: i64,
end_ms: i64,
) -> String
pub fn select_range_sql( &self, schema: &MetricSchema, start_ms: i64, end_ms: i64, ) -> String
Generate a SELECT query for a metric within a time range.
Sourcepub fn count_sql(&self, schema: &MetricSchema) -> String
pub fn count_sql(&self, schema: &MetricSchema) -> String
Generate a SELECT COUNT(*) query.
Sourcepub fn summary_sql(&self, schema: &MetricSchema) -> String
pub fn summary_sql(&self, schema: &MetricSchema) -> String
Generate a SELECT MIN/MAX/AVG(value) summary query.
Sourcepub fn delete_before_sql(&self, schema: &MetricSchema, before_ms: i64) -> String
pub fn delete_before_sql(&self, schema: &MetricSchema, before_ms: i64) -> String
Generate a DELETE FROM statement to purge data older than before_ms.
Sourcepub fn create_index_sql(&self, schema: &MetricSchema) -> String
pub fn create_index_sql(&self, schema: &MetricSchema) -> String
Generate a CREATE INDEX for fast time-range queries.
Sourcepub fn add_tag_column_sql(&self, schema: &MetricSchema, tag_key: &str) -> String
pub fn add_tag_column_sql(&self, schema: &MetricSchema, tag_key: &str) -> String
Generate an ALTER TABLE ... ADD COLUMN for a new tag.
Sourcepub fn infer_schema(metric_name: &str, points: &[SqlDataPoint]) -> MetricSchema
pub fn infer_schema(metric_name: &str, points: &[SqlDataPoint]) -> MetricSchema
Infer a MetricSchema from a slice of SqlDataPoints and a metric name.
Trait Implementations§
Source§impl Clone for SqlExporter
impl Clone for SqlExporter
Source§fn clone(&self) -> SqlExporter
fn clone(&self) -> SqlExporter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SqlExporter
impl Debug for SqlExporter
Source§impl Default for SqlExporter
impl Default for SqlExporter
Source§fn default() -> SqlExporter
fn default() -> SqlExporter
Auto Trait Implementations§
impl Freeze for SqlExporter
impl RefUnwindSafe for SqlExporter
impl Send for SqlExporter
impl Sync for SqlExporter
impl Unpin for SqlExporter
impl UnsafeUnpin for SqlExporter
impl UnwindSafe for SqlExporter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more