pub(crate) mod raw;
use super::raw::*;
use super::*;
use crate::impl_expr2;
use raw::*;
pub const WINDOW_CONST_ID: usize = 0;
pub const GROUP_CONST_ID: usize = 1;
pub const ARGS_CONST_ID: usize = 2;
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct Query<'script> {
pub stmts: Stmts<'script>,
pub node_meta: NodeMetas<'script>,
}
#[derive(Clone, Debug, PartialEq, Serialize)]
pub enum Stmt<'script> {
WindowDecl(WindowDecl<'script>),
Stream(StreamStmt),
OperatorDecl(OperatorDecl<'script>),
ScriptDecl(ScriptDecl<'script>),
Operator(OperatorStmt<'script>),
Script(ScriptStmt<'script>),
Select(SelectStmt<'script>),
}
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct SelectStmt<'script> {
pub stmt: Box<Select<'script>>,
pub aggregates: Vec<InvokeAggrFn<'script>>,
pub consts: Vec<Value<'script>>,
pub locals: usize,
pub node_meta: NodeMetas<'script>,
}
pub enum SelectType {
Passthrough,
Simple,
Normal,
}
impl SelectStmt<'_> {
pub fn complexity(&self) -> SelectType {
if self.stmt.target.0
== ImutExprInt::Path(Path::Event(EventPath {
mid: 0,
segments: vec![],
}))
&& self.stmt.maybe_group_by.is_none()
&& self.stmt.windows.is_empty()
{
if self.stmt.maybe_having.is_none() && self.stmt.maybe_where.is_none() {
SelectType::Passthrough
} else {
SelectType::Simple
}
} else {
SelectType::Normal
}
}
}
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct OperatorKind {
pub(crate) mid: usize,
pub module: String,
pub operation: String,
}
impl BaseExpr for OperatorKind {
fn mid(&self) -> usize {
self.mid
}
}
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct OperatorDecl<'script> {
pub(crate) mid: usize,
pub kind: OperatorKind,
pub id: String,
pub params: Option<HashMap<String, Value<'script>>>,
}
impl_expr2!(OperatorDecl);
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct OperatorStmt<'script> {
pub(crate) mid: usize,
pub id: String,
pub target: String,
pub(crate) params: Option<HashMap<String, Value<'script>>>,
}
impl_expr2!(OperatorStmt);
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct ScriptDecl<'script> {
pub(crate) mid: usize,
pub id: String,
pub params: Option<HashMap<String, Value<'script>>>,
pub script: Script<'script>,
}
impl_expr2!(ScriptDecl);
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct ScriptStmt<'script> {
pub(crate) mid: usize,
pub id: String,
pub target: String,
pub params: Option<HashMap<String, Value<'script>>>,
}
impl_expr2!(ScriptStmt);
#[derive(Clone, Debug, PartialEq, Serialize)]
pub enum WindowKind {
Sliding,
Tumbling,
}
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct WindowDecl<'script> {
pub(crate) mid: usize,
pub id: String,
pub kind: WindowKind,
pub params: HashMap<String, Value<'script>>,
pub script: Option<Script<'script>>,
}
impl_expr2!(WindowDecl);
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct Select<'script> {
pub mid: usize,
pub from: (Ident<'script>, Ident<'script>),
pub into: (Ident<'script>, Ident<'script>),
pub target: ImutExpr<'script>,
pub maybe_where: Option<ImutExpr<'script>>,
pub maybe_having: Option<ImutExpr<'script>>,
pub maybe_group_by: Option<GroupBy<'script>>,
pub windows: Vec<WindowDefnRaw>,
}
impl_expr2!(Select);
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct GroupBy<'script>(pub(crate) GroupByInt<'script>);
#[derive(Clone, Debug, PartialEq, Serialize)]
pub(crate) enum GroupByInt<'script> {
Expr {
mid: usize,
expr: ImutExprInt<'script>,
},
Set {
mid: usize,
items: Vec<GroupBy<'script>>,
},
Each {
mid: usize,
expr: ImutExprInt<'script>,
},
}
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct StreamStmt {
pub(crate) mid: usize,
pub id: String,
}
impl BaseExpr for StreamStmt {
fn mid(&self) -> usize {
self.mid
}
}