use enum_as_inner::EnumAsInner;
use prqlc_ast::Ty;
use serde::{Deserialize, Serialize};
use crate::ir::generic::WindowKind;
use crate::ir::pl::{Expr, ExprKind, Func, FuncCall, Range};
impl FuncCall {
pub fn new_simple(name: Expr, args: Vec<Expr>) -> Self {
FuncCall {
name: Box::new(name),
args,
named_args: Default::default(),
}
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, EnumAsInner)]
pub enum TyOrExpr {
Ty(Ty),
Expr(Box<Expr>),
}
impl Func {
pub(crate) fn as_debug_name(&self) -> &str {
let ident = self.name_hint.as_ref();
ident.map(|n| n.name.as_str()).unwrap_or("<anonymous>")
}
}
pub type WindowFrame = crate::ir::generic::WindowFrame<Box<Expr>>;
pub type ColumnSort = crate::ir::generic::ColumnSort<Box<Expr>>;
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct TransformCall {
pub input: Box<Expr>,
pub kind: Box<TransformKind>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub partition: Option<Box<Expr>>,
#[serde(default, skip_serializing_if = "WindowFrame::is_default")]
pub frame: WindowFrame,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub sort: Vec<ColumnSort>,
}
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, strum::AsRefStr, EnumAsInner)]
pub enum TransformKind {
Derive {
assigns: Box<Expr>,
},
Select {
assigns: Box<Expr>,
},
Filter {
filter: Box<Expr>,
},
Aggregate {
assigns: Box<Expr>,
},
Sort {
by: Vec<ColumnSort>,
},
Take {
range: Range,
},
Join {
side: JoinSide,
with: Box<Expr>,
filter: Box<Expr>,
},
Group {
by: Box<Expr>,
pipeline: Box<Expr>,
},
Window {
kind: WindowKind,
range: Range,
pipeline: Box<Expr>,
},
Append(Box<Expr>),
Loop(Box<Expr>),
}
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum TableExternRef {
LocalTable(String),
Param(String),
}
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub enum JoinSide {
Inner,
Left,
Right,
Full,
}
impl Expr {
pub fn new(kind: impl Into<ExprKind>) -> Self {
Expr {
id: None,
kind: kind.into(),
span: None,
target_id: None,
ty: None,
lineage: None,
needs_window: false,
alias: None,
flatten: false,
}
}
}