use super::*;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GraphMatchProgram {
pub imports: Vec<GraphBindingImport>,
pub introduced: Vec<String>,
pub projected_nodes: BTreeMap<String, BTreeSet<String>>,
pub projected_relationships: BTreeMap<String, BTreeSet<String>>,
pub steps: Vec<GraphMatchStep>,
pub predicate: Option<Predicate>,
pub predicate_steps: Vec<usize>,
pub edge_predicates: Vec<usize>,
pub optional: bool,
}
impl GraphMatchProgram {
pub fn predicate_conjuncts(&self) -> &[Predicate] {
match &self.predicate {
None => &[],
Some(Predicate::And(conjuncts)) => conjuncts,
Some(predicate) => std::slice::from_ref(predicate),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GraphBindingImport {
pub variable: String,
pub column: String,
pub kind: GraphEntityKind,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GraphEntityKind {
Node,
Relationship,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GraphMatchNode {
pub variable: String,
pub label: String,
pub properties: BTreeMap<String, Value>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GraphMatchStep {
Node(GraphMatchNode),
Expand {
source: String,
relationship: Option<String>,
rel_type: String,
properties: BTreeMap<String, Value>,
direction: RelationshipDirection,
min_hops: usize,
max_hops: usize,
target: GraphMatchNode,
},
ShortestPath(Box<GraphMatchShortestPath>),
}
pub const MAX_SHORTEST_PATH_HOPS: usize = 256;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ShortestPathSelection {
Any,
All,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GraphMatchShortestPath {
pub path: String,
pub source: String,
pub target: String,
pub rel_type: String,
pub direction: RelationshipDirection,
pub min_hops: usize,
pub max_hops: usize,
pub bounded: bool,
pub selection: ShortestPathSelection,
}
hawdb_core::impl_retained_heap_for_struct!(GraphMatchProgram {
imports,
introduced,
projected_nodes,
projected_relationships,
steps,
predicate,
predicate_steps,
edge_predicates,
optional
});
hawdb_core::impl_retained_heap_for_struct!(GraphMatchNode {
variable,
label,
properties
});
hawdb_core::impl_retained_heap_for_struct!(GraphBindingImport {
variable,
column,
kind
});
hawdb_core::impl_retained_heap_for_copy!(GraphEntityKind);
impl hawdb_core::RetainedHeapBytes for GraphMatchStep {
fn retained_heap_bytes(&self) -> Option<usize> {
match self {
Self::Node(value0) => hawdb_core::checked_retained_heap_sum([
hawdb_core::RetainedHeapBytes::retained_heap_bytes(value0),
]),
Self::ShortestPath(path) => hawdb_core::RetainedHeapBytes::retained_heap_bytes(path),
Self::Expand {
source,
relationship,
rel_type,
properties,
direction,
min_hops,
max_hops,
target,
} => hawdb_core::checked_retained_heap_sum([
hawdb_core::RetainedHeapBytes::retained_heap_bytes(source),
hawdb_core::RetainedHeapBytes::retained_heap_bytes(relationship),
hawdb_core::RetainedHeapBytes::retained_heap_bytes(rel_type),
hawdb_core::RetainedHeapBytes::retained_heap_bytes(properties),
hawdb_core::RetainedHeapBytes::retained_heap_bytes(direction),
hawdb_core::RetainedHeapBytes::retained_heap_bytes(min_hops),
hawdb_core::RetainedHeapBytes::retained_heap_bytes(max_hops),
hawdb_core::RetainedHeapBytes::retained_heap_bytes(target),
]),
}
}
}
hawdb_core::impl_retained_heap_for_struct!(GraphMatchShortestPath {
path,
source,
target,
rel_type,
direction,
min_hops,
max_hops,
bounded,
selection
});
hawdb_core::impl_retained_heap_for_copy!(ShortestPathSelection);