use crate::error::Result;
#[derive(Clone, Debug)]
pub struct TableRef {
pub schema: Option<String>,
pub name: String,
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum LogicalType {
Int,
Decimal { scale: u8 },
Timestamp { precision: u8 },
String,
Boolean,
Binary,
}
#[derive(Clone, Debug)]
pub struct ColumnSchema {
pub name: String,
pub ty: LogicalType,
pub nullable: bool,
pub default_value: Option<String>,
pub primary_key: bool,
}
#[derive(Debug)]
pub struct TableSchema {
pub columns: Vec<ColumnSchema>,
}
#[derive(Clone, Debug)]
pub struct ComparePlan {
pub key: ColumnSchema,
pub columns: Vec<ColumnSchema>,
}
#[derive(Debug)]
pub enum KeyValue {
Int(i128),
Bytes(Vec<u8>),
}
#[allow(dead_code)]
pub struct Segment {
lo: KeyValue,
hi: KeyValue,
}
#[allow(dead_code)]
pub struct Checksum {
half1: u64,
half2: u64,
count: u64,
}
#[derive(Debug)]
pub enum DiffOp {
Left,
Right,
Differ,
}
#[allow(dead_code)]
pub struct DiffRow {
op: DiffOp,
key: KeyValue,
columns: Vec<Option<String>>,
}
#[derive(Debug)]
pub struct JoinDiffQuery {
pub left_only: String,
pub right_only: String,
pub differing: String,
}
pub trait Engine {
fn name(&self) -> &str;
fn introspect(&self, table: &TableRef) -> Result<TableSchema>;
fn dialect(&self) -> &dyn Dialect;
fn execute(&self, sql: &str) -> Result<Vec<Vec<String>>>;
}
pub trait Dialect {
fn whole_table_checksum_sql(&self, table: &TableRef, plan: &ComparePlan) -> Result<String>;
fn joindiff_sql(&self, a: &TableRef, b: &TableRef, plan: &ComparePlan) -> Result<JoinDiffQuery>;
fn materialize_sql(
&self,
a: &TableRef,
b: &TableRef,
plan: &ComparePlan,
target: &TableRef,
) -> Result<String>;
fn normalize_column(&self, col: &ColumnSchema) -> Result<String>;
fn digest_expr(&self, canon_cols: &[String]) -> Result<String>;
fn keyspace_bounds_sql(&self, table: &TableRef, key: &ColumnSchema) -> Result<String>;
fn segment_checksum_sql(
&self,
table: &TableRef,
plan: &ComparePlan,
segment: &Segment,
) -> Result<String>;
fn segment_rows_sql(&self, table: &TableRef, plan: &ComparePlan) -> Result<String>;
}