use lora_compiler::physical::{PhysicalOp, PhysicalPlan};
use lora_compiler::CompiledQuery;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StreamShape {
ReadOnly,
Mutating,
}
impl StreamShape {
pub fn is_mutating(self) -> bool {
matches!(self, StreamShape::Mutating)
}
}
fn plan_is_mutating(plan: &PhysicalPlan) -> bool {
plan.nodes.iter().any(|op| {
matches!(
op,
PhysicalOp::Create(_)
| PhysicalOp::Merge(_)
| PhysicalOp::Delete(_)
| PhysicalOp::Set(_)
| PhysicalOp::Remove(_)
)
})
}
pub fn classify_stream(compiled: &CompiledQuery) -> StreamShape {
if plan_is_mutating(&compiled.physical)
|| compiled
.unions
.iter()
.any(|b| plan_is_mutating(&b.physical))
{
StreamShape::Mutating
} else {
StreamShape::ReadOnly
}
}