#[derive(Debug, Clone, PartialEq)]
pub enum Expr {
Ident(String),
StringLit(String),
IntLit(i64),
FloatLit(f64),
BoolLit(bool),
BinOp {
lhs: Box<Expr>,
op: BinOpKind,
rhs: Box<Expr>,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum BinOpKind {
Eq,
NotEq,
Lt,
Gt,
LtEq,
GtEq,
Add,
Sub,
Mul,
Div,
}
#[derive(Debug, Clone, PartialEq)]
pub enum FillNullValue {
Int(i64),
Float(f64),
Str(String),
}
#[derive(Debug, Clone, PartialEq)]
pub enum JoinHow {
Inner,
Left,
Outer,
Cross,
}
impl Default for JoinHow {
fn default() -> Self {
JoinHow::Inner
}
}
impl JoinHow {
pub fn from_str(s: &str) -> Option<Self> {
match s {
"inner" => Some(JoinHow::Inner),
"left" => Some(JoinHow::Left),
"outer" => Some(JoinHow::Outer),
"cross" => Some(JoinHow::Cross),
_ => None,
}
}
pub fn as_polars_str(&self) -> &'static str {
match self {
JoinHow::Inner => "JoinType::Inner",
JoinHow::Left => "JoinType::Left",
JoinHow::Outer => "JoinType::Full",
JoinHow::Cross => "JoinType::Cross",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum ChartType {
Bar,
Line,
Pie,
Scatter,
}
impl ChartType {
pub fn from_str(s: &str) -> Option<Self> {
match s {
"bar" => Some(ChartType::Bar),
"line" => Some(ChartType::Line),
"pie" => Some(ChartType::Pie),
"scatter" => Some(ChartType::Scatter),
_ => None,
}
}
pub fn as_str(&self) -> &'static str {
match self {
ChartType::Bar => "bar",
ChartType::Line => "line",
ChartType::Pie => "pie",
ChartType::Scatter => "scatter",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ChartConfig {
pub chart_type: ChartType,
pub title: Option<String>,
pub x: Option<String>,
pub y: Option<String>,
pub label: Option<String>,
pub value: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum PipelineOp {
Filter(Expr),
Select(Vec<String>),
Count(Option<String>),
GroupBy(String),
Sum(String),
Mean(String),
Min(String),
Max(String),
OrderBy { col: String, desc: bool },
Take(i64),
DropNull(String),
FillNull { col: String, value: FillNullValue },
Join {
other: String,
left_on: Vec<String>,
right_on: Vec<String>,
how: JoinHow,
},
WithColumn { name: String, expr: Expr },
Chart(ChartConfig),
Cast { col: String, to_type: String },
Rename { old_name: String, new_name: String },
Replace {
col: String,
from: String,
to: String,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum PipelineSource {
Load {
file_path: String,
schema_name: String,
},
VarRef(String),
}
#[derive(Debug, Clone, PartialEq)]
pub struct StructField {
pub name: String,
pub field_type: String,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Stmt {
TypeDecl {
name: String,
fields: Vec<StructField>,
},
VarDecl {
var_name: String,
is_mut: bool,
source: PipelineSource,
ops: Vec<PipelineOp>,
},
ExprStmt {
source: PipelineSource,
ops: Vec<PipelineOp>,
},
}
#[derive(Debug, Clone, PartialEq)]
pub struct Program {
pub stmts: Vec<Stmt>,
}
impl Program {
pub fn new() -> Self {
Program { stmts: Vec::new() }
}
}
impl Default for Program {
fn default() -> Self {
Program::new()
}
}