1use crate::value::LoraValue;
2use lora_compiler::physical::PhysicalNodeId;
3use lora_store::{NodeId, RelationshipId};
4use thiserror::Error;
5
6#[derive(Debug, Error)]
7pub enum ExecutorError {
8 #[error("this query modifies the graph, but it was executed in read-only mode (CREATE at plan node {node_id:?})")]
9 ReadOnlyCreate { node_id: PhysicalNodeId },
10
11 #[error("this query modifies the graph, but it was executed in read-only mode (MERGE at plan node {node_id:?})")]
12 ReadOnlyMerge { node_id: PhysicalNodeId },
13
14 #[error("this query modifies the graph, but it was executed in read-only mode (DELETE at plan node {node_id:?})")]
15 ReadOnlyDelete { node_id: PhysicalNodeId },
16
17 #[error("this query modifies the graph, but it was executed in read-only mode (SET at plan node {node_id:?})")]
18 ReadOnlySet { node_id: PhysicalNodeId },
19
20 #[error("this query modifies the graph, but it was executed in read-only mode (REMOVE at plan node {node_id:?})")]
21 ReadOnlyRemove { node_id: PhysicalNodeId },
22
23 #[error("this query modifies the graph, but it was executed in read-only mode (FOREACH at plan node {node_id:?})")]
24 ReadOnlyForeach { node_id: PhysicalNodeId },
25
26 #[error("expected variable {var} to contain a node before expanding a relationship, but found {found}")]
27 ExpectedNodeForExpand { var: String, found: String },
28
29 #[error("expected a map value for properties, but found {found}")]
30 ExpectedPropertyMap { found: String },
31
32 #[error("grouping could not be executed because the group-by expression was not lowered to a variable")]
33 GroupByNotLowered,
34
35 #[error("aggregation could not be executed because the aggregate expression was not lowered to a variable")]
36 AggregateNotLowered,
37
38 #[error("variable-length relationships are not supported in CREATE")]
39 UnsupportedCreateRelationshipRange,
40
41 #[error("a CREATE relationship is missing its relationship type")]
42 MissingRelationshipType,
43
44 #[error("failed to create relationship `{rel_type}` from node {src} to node {dst}")]
45 RelationshipCreateFailed {
46 src: u64,
47 dst: u64,
48 rel_type: String,
49 },
50
51 #[error("cannot delete node {node_id} because it still has relationships; use DETACH DELETE to remove the node and its relationships")]
52 DeleteNodeWithRelationships { node_id: NodeId },
53
54 #[error("failed to delete relationship {rel_id}")]
55 DeleteRelationshipFailed { rel_id: RelationshipId },
56
57 #[error(
58 "DELETE can only be used with nodes, relationships, or lists of them, but found {found}"
59 )]
60 InvalidDeleteTarget { found: String },
61
62 #[error("REMOVE label can only be applied to a node, but found {found}")]
63 ExpectedNodeForRemoveLabels { found: String },
64
65 #[error("REMOVE referenced variable {var}, but that variable is not bound in the current row")]
66 UnboundVariableForRemove { var: String },
67
68 #[error("SET label can only be applied to a node, but found {found}")]
69 ExpectedNodeForSetLabels { found: String },
70
71 #[error("SET referenced variable {var}, but that variable is not bound in the current row")]
72 UnboundVariableForSet { var: String },
73
74 #[error("SET target must be a node or relationship, but found {found}")]
75 InvalidSetTarget { found: String },
76
77 #[error("REMOVE property currently only supports direct property expressions like n.name or r.weight")]
78 UnsupportedRemoveTarget,
79
80 #[error("REMOVE target must be a node or relationship property, but found {found}")]
81 InvalidRemoveTarget { found: String },
82
83 #[error(
84 "SET property currently only supports direct property expressions like n.name or r.weight"
85 )]
86 UnsupportedSetTarget,
87
88 #[error("expected variable {var} to contain a relationship during EXPAND, but found {found}")]
89 ExpectedRelationshipForExpand { var: String, found: String },
90
91 #[error("query deadline exceeded")]
92 QueryTimeout,
93
94 #[error("{0}")]
98 ConstraintViolation(String),
99
100 #[error("{0}")]
101 RuntimeError(String),
102}
103
104pub type ExecResult<T> = Result<T, ExecutorError>;
105
106pub fn value_kind(value: &LoraValue) -> String {
107 match value {
108 LoraValue::Null => "null".into(),
109 LoraValue::Bool(_) => "bool".into(),
110 LoraValue::Int(_) => "int".into(),
111 LoraValue::Float(_) => "float".into(),
112 LoraValue::String(_) => "string".into(),
113 LoraValue::Binary(_) => "binary".into(),
114 LoraValue::List(_) => "list".into(),
115 LoraValue::Map(_) => "map".into(),
116 LoraValue::Node(_) => "node".into(),
117 LoraValue::Relationship(_) => "relationship".into(),
118 LoraValue::Path(_) => "path".into(),
119 LoraValue::Date(_) => "date".into(),
120 LoraValue::DateTime(_) => "datetime".into(),
121 LoraValue::LocalDateTime(_) => "localdatetime".into(),
122 LoraValue::Time(_) => "time".into(),
123 LoraValue::LocalTime(_) => "localtime".into(),
124 LoraValue::Duration(_) => "duration".into(),
125 LoraValue::Point(_) => "point".into(),
126 LoraValue::Vector(_) => "vector".into(),
127 }
128}