use nodedb_physical::physical_plan::{ColumnarOp, TimeseriesOp};
use nodedb_wal::record::RecordType;
use crate::control::server::wal_dispatch::{
encode_columnar_batch_payload, encode_columnar_dml_payload, encode_timeseries_batch_payload,
};
use crate::wal::RedoSubRecord;
pub(super) fn serialize_columnar_op(
op: &ColumnarOp,
ops: &mut Vec<RedoSubRecord>,
) -> crate::Result<()> {
match op {
ColumnarOp::Insert {
collection,
payload,
format: _,
intent: _,
on_conflict_updates: _,
surrogates,
schema_bytes: _,
provenance,
wal_lsn: _,
} => {
let sub_payload = encode_columnar_batch_payload(
collection,
payload,
provenance.as_ref(),
surrogates,
)?;
ops.push(RedoSubRecord {
record_type: RecordType::TimeseriesBatch as u32,
payload: sub_payload,
});
Ok(())
}
ColumnarOp::Scan { .. } | ColumnarOp::MaterializeScan { .. } => Ok(()),
ColumnarOp::Update {
collection,
filters,
updates,
} => {
let sub_payload = encode_columnar_dml_payload(collection, true, filters, updates)?;
ops.push(RedoSubRecord {
record_type: RecordType::TimeseriesBatch as u32,
payload: sub_payload,
});
Ok(())
}
ColumnarOp::Delete {
collection,
filters,
} => {
let sub_payload = encode_columnar_dml_payload(collection, false, filters, &[])?;
ops.push(RedoSubRecord {
record_type: RecordType::TimeseriesBatch as u32,
payload: sub_payload,
});
Ok(())
}
}
}
pub(super) fn serialize_timeseries_op(
op: &TimeseriesOp,
ops: &mut Vec<RedoSubRecord>,
) -> crate::Result<()> {
match op {
TimeseriesOp::Ingest {
collection,
payload,
format: _,
wal_lsn: _,
surrogates: _,
provenance,
} => {
let sub_payload =
encode_timeseries_batch_payload(collection, payload, provenance.as_ref())?;
ops.push(RedoSubRecord {
record_type: RecordType::TimeseriesBatch as u32,
payload: sub_payload,
});
Ok(())
}
TimeseriesOp::Scan { .. } => Ok(()),
}
}