use dr_strange_core::AggFunc;
use dr_strange_core::Metric;
use dr_strange_core::PropValue;
use dr_strange_core::compute::expr::{ArithOp, CmpOp, LogicOp, StrOp};
use dr_strange_core::types::Dir;
#[derive(Debug, Clone, PartialEq)]
pub struct Query {
pub source: QuerySource,
pub beams: Vec<BeamClause>,
pub where_clause: Option<PExpr>,
pub ret: Return,
pub order_by: Vec<OrderKey>,
pub skip: Option<u64>,
pub limit: Option<u64>,
pub as_of: Option<AsOfSpec>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AsOfSpec {
Seq(u64),
Time(i64),
}
#[derive(Debug, Clone, PartialEq)]
pub struct BeamClause {
pub node: NodePat,
pub dir: Dir,
pub edge_type: Option<String>,
pub property: Option<String>,
pub query: VecArg,
pub metric: Metric,
pub width: u32,
pub depth: u32,
}
#[derive(Debug, Clone, PartialEq)]
pub struct QuerySource {
pub kind: SourceKind,
pub first: NodePat,
pub rest: Vec<(RelPat, NodePat)>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum SourceKind {
Match,
Search {
property: Option<String>,
query: VecArg,
metric: Metric,
k: u64,
},
Keyword {
property: Option<String>,
query: String,
k: u64,
},
Hybrid(HybridClause),
Call(CallClause),
}
#[derive(Debug, Clone, PartialEq)]
pub struct HybridClause {
pub vector: Option<HybridVector>,
pub keyword: Option<HybridKeyword>,
pub graph: Option<HybridGraph>,
pub candidates: Option<u64>,
pub k: Option<u64>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct HybridVector {
pub property: Option<String>,
pub query: VecArg,
pub metric: Metric,
pub weight: Option<f32>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct HybridKeyword {
pub property: Option<String>,
pub query: String,
pub weight: Option<f32>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct HybridGraph {
pub hops: u32,
pub decay: Option<f32>,
pub seeds: Option<u64>,
pub weight: Option<f32>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CallClause {
pub name: String,
pub args: Vec<(String, Val)>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum VecArg {
Vector(Vec<f32>),
Text(String),
}
#[derive(Debug, Clone, PartialEq)]
pub struct Pattern {
pub first: NodePat,
pub rest: Vec<(RelPat, NodePat)>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct NodePat {
pub var: Option<String>,
pub label: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct RelPat {
pub dir: Dir,
pub ty: Option<String>,
pub var_len: Option<VarLen>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct VarLen {
pub min: u32,
pub max: Option<u32>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Return {
pub distinct: bool,
pub items: Vec<ReturnItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ReturnItem {
Star,
Var(String),
Value { expr: PExpr, name: String },
Agg {
func: AggFunc,
arg: Option<PExpr>,
distinct: bool,
name: String,
},
}
#[derive(Debug, Clone, PartialEq)]
pub struct OrderKey {
pub target: SortTarget,
pub text: String,
pub descending: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum SortTarget {
Expr(PExpr),
Name(String),
Agg {
func: AggFunc,
arg: Option<PExpr>,
distinct: bool,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum PExpr {
Lit(PropValue),
Param(String),
Prop {
var: String,
key: String,
},
HasLabel {
var: String,
label: String,
},
ExternalKey {
var: String,
},
In {
lhs: Box<PExpr>,
list: Vec<PExpr>,
},
InValue {
lhs: Box<PExpr>,
haystack: Box<PExpr>,
},
StringMatch {
op: StrOp,
lhs: Box<PExpr>,
rhs: Box<PExpr>,
},
IsNull(Box<PExpr>),
Not(Box<PExpr>),
Neg(Box<PExpr>),
Compare {
op: CmpOp,
lhs: Box<PExpr>,
rhs: Box<PExpr>,
},
Logic {
op: LogicOp,
lhs: Box<PExpr>,
rhs: Box<PExpr>,
},
Arith {
op: ArithOp,
lhs: Box<PExpr>,
rhs: Box<PExpr>,
},
Score,
Hops,
Similarity {
var: String,
property: String,
query: VecArg,
metric: Metric,
},
Distance {
var: String,
property: String,
query: VecArg,
metric: Metric,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum StmtAst {
Read(Box<Query>),
Write(WriteAst),
}
#[derive(Debug, Clone, PartialEq)]
pub struct WriteAst {
pub match_clause: Option<MatchClause>,
pub ops: Vec<WriteOp>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct MatchClause {
pub pattern: Pattern,
pub where_clause: Option<PExpr>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum WriteOp {
Create(Vec<CreatePath>),
Merge(MergeClause),
Set(Vec<SetItem>),
Remove(Vec<RemoveItem>),
Delete { detach: bool, vars: Vec<String> },
}
#[derive(Debug, Clone, PartialEq)]
pub struct MergeClause {
pub path: CreatePath,
pub on_create: Vec<SetItem>,
pub on_match: Vec<SetItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Val {
Lit(PropValue),
Param(String),
}
#[derive(Debug, Clone, PartialEq)]
pub enum SetItem {
Prop {
var: String,
key: String,
value: Val,
},
Label { var: String, label: String },
Merge {
var: String,
props: Vec<(String, Val)>,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum RemoveItem {
Prop { var: String, key: String },
Label { var: String, label: String },
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreatePath {
pub first: CreateNode,
pub rest: Vec<(CreateRel, CreateNode)>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateNode {
pub var: Option<String>,
pub label: Option<String>,
pub key: Option<Val>,
pub props: Vec<(String, Val)>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateRel {
pub dir: Dir,
pub ty: String,
pub props: Vec<(String, Val)>,
}