1use hawdb_sql_syntax::{
16 BinaryOperatorSyntax, GraphEdgeDirection, GraphPatternQuantifier, Span, UnaryOperatorSyntax,
17};
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
20pub struct PgqSlotId(pub u32);
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum PgqElementKind {
24 Vertex,
25 Edge,
26}
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29pub enum PgqDataType {
30 Unknown,
31 Null,
32 Boolean,
33 Int64,
34 Float64,
35 String,
36 Binary,
37 Uuid,
38 GraphElement(PgqElementKind),
39}
40
41#[derive(Debug, Clone, PartialEq)]
42pub enum BoundPgqLiteral {
43 Null,
44 Boolean(bool),
45 Int64(i64),
46 Float64(f64),
47 String(String),
48 TypedString { data_type: String, value: String },
49}
50
51#[derive(Debug, Clone, PartialEq)]
52pub struct BoundPgqExpression {
53 pub kind: BoundPgqExpressionKind,
54 pub data_type: PgqDataType,
55 pub span: Span,
56}
57
58#[derive(Debug, Clone, PartialEq)]
59pub enum BoundPgqExpressionKind {
60 Variable(PgqSlotId),
61 Property {
62 slot: PgqSlotId,
63 property: String,
64 },
65 OuterColumn(Vec<String>),
66 Parameter(u32),
67 Literal(BoundPgqLiteral),
68 Unary {
69 operator: UnaryOperatorSyntax,
70 expression: Box<BoundPgqExpression>,
71 },
72 Binary {
73 left: Box<BoundPgqExpression>,
74 operator: BinaryOperatorSyntax,
75 right: Box<BoundPgqExpression>,
76 },
77 IsNull {
78 expression: Box<BoundPgqExpression>,
79 negated: bool,
80 },
81 InList {
82 expression: Box<BoundPgqExpression>,
83 values: Vec<BoundPgqExpression>,
84 negated: bool,
85 },
86 Between {
87 expression: Box<BoundPgqExpression>,
88 low: Box<BoundPgqExpression>,
89 high: Box<BoundPgqExpression>,
90 negated: bool,
91 },
92 Function {
93 name: Vec<String>,
94 arguments: Vec<BoundPgqExpression>,
95 distinct: bool,
96 },
97 Cast {
98 expression: Box<BoundPgqExpression>,
99 data_type: Vec<String>,
100 },
101 Collate {
102 expression: Box<BoundPgqExpression>,
103 collation: Vec<String>,
104 },
105}
106
107#[derive(Debug, Clone, PartialEq, Eq)]
108pub struct BoundPgqVariable {
109 pub slot: PgqSlotId,
110 pub name: Option<String>,
111 pub kind: PgqElementKind,
112 pub labels: Vec<String>,
113 pub span: Span,
114}
115
116#[derive(Debug, Clone, PartialEq)]
117pub struct BoundPgqGraphTable {
118 pub graph_name: Vec<String>,
119 pub variables: Vec<BoundPgqVariable>,
120 pub pattern: BoundPgqGraphPattern,
121 pub columns: Vec<BoundPgqColumn>,
122 pub alias: Option<String>,
123 pub span: Span,
124}
125
126#[derive(Debug, Clone, PartialEq)]
127pub struct BoundPgqGraphPattern {
128 pub paths: Vec<BoundPgqPath>,
129 pub predicate: Option<BoundPgqExpression>,
130}
131
132#[derive(Debug, Clone, PartialEq)]
133pub struct BoundPgqPath {
134 pub factors: Vec<BoundPgqPathFactor>,
135}
136
137#[derive(Debug, Clone, PartialEq)]
138pub struct BoundPgqPathFactor {
139 pub primary: BoundPgqPathPrimary,
140 pub quantifier: Option<GraphPatternQuantifier>,
141}
142
143#[derive(Debug, Clone, PartialEq)]
144pub enum BoundPgqPathPrimary {
145 Vertex {
146 slot: PgqSlotId,
147 predicate: Option<BoundPgqExpression>,
148 },
149 Edge {
150 slot: PgqSlotId,
151 direction: GraphEdgeDirection,
152 predicate: Option<BoundPgqExpression>,
153 },
154 Parenthesized {
155 path: Box<BoundPgqPath>,
156 predicate: Option<BoundPgqExpression>,
157 },
158}
159
160#[derive(Debug, Clone, PartialEq)]
161pub struct BoundPgqColumn {
162 pub name: String,
163 pub expression: BoundPgqExpression,
164 pub data_type: PgqDataType,
165}