use relate_names::SmallName;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum PreambleMode {
#[default]
Execute,
Explain,
Profile,
}
#[derive(Debug, Clone, Default)]
pub struct Statement {
pub clauses: Vec<Clause>,
pub union: Option<Box<UnionPart>>,
pub preamble: PreambleMode,
pub next: Option<Box<Statement>>,
pub brace_wrapped: bool,
pub definitions: Vec<LocalDefinition>,
}
impl PartialEq for Statement {
fn eq(&self, other: &Self) -> bool {
self.clauses == other.clauses
&& self.union == other.union
&& self.preamble == other.preamble
&& self.next == other.next
&& self.definitions == other.definitions
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct LocalDefinition {
pub kind: LocalCallableKind,
pub name: SmallName,
pub params: Vec<LocalParam>,
pub output: Option<LocalOutput>,
pub body: LocalDefinitionBody,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LocalCallableKind {
Procedure,
Function,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LocalParam {
pub name: SmallName,
pub type_expr: Option<TypeExpr>,
pub default: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum LocalOutput {
Fields(Vec<LocalOutputField>),
Type(TypeExpr),
}
#[derive(Debug, Clone, PartialEq)]
pub struct LocalOutputField {
pub name: SmallName,
pub type_expr: Option<TypeExpr>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum LocalDefinitionBody {
Expression(Expr),
Query(Statement),
}
#[derive(Debug, Clone, PartialEq)]
pub struct UnionPart {
pub all: bool,
pub statement: Statement,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Clause {
Match(MatchClause),
Create(CreateClause),
Merge(MergeClause),
Delete(DeleteClause),
Set(SetClause),
Remove(RemoveClause),
Return(ReturnClause),
With(WithClause),
Unwind(UnwindClause),
CreateIndex(CreateIndexClause),
DropIndex(DropIndexClause),
CreateConstraint(CreateConstraintClause),
DropConstraint(DropConstraintClause),
Foreach(ForeachClause),
LoadCSV(LoadCSVClause),
CallSubquery(CallSubqueryClause),
CallProcedure(CallProcedureClause),
ShowFunctions(ShowFunctionsClause),
ShowConstraints(ShowConstraintsClause),
ShowIndexes(ShowIndexesClause),
ShowDatabases(ShowDatabasesClause),
ShowRoles(ShowRolesClause),
ShowServers(ShowServersClause),
ShowUsers(ShowUsersClause),
ShowProcedures(ShowProceduresClause),
ShowSettings(ShowSettingsClause),
ShowTransactions(ShowTransactionsClause),
TerminateTransactions(TerminateTransactionsClause),
Use(UseClause),
Finish,
StandaloneOrderBy(StandaloneOrderByClause),
Conditional(ConditionalClause),
AlterCurrentGraphType(AlterCurrentGraphTypeClause),
CreateGraphType(CreateGraphTypeClause),
ShowGraphType(ShowGraphTypeClause),
ShowCurrentGraphType(ShowCurrentGraphTypeClause),
AlterDatabase(AlterDatabaseClause),
}
impl Clause {
pub fn keyword(&self) -> &'static str {
match self {
Clause::Match(_) => "MATCH",
Clause::Create(_) => "CREATE",
Clause::Merge(_) => "MERGE",
Clause::Delete(_) => "DELETE",
Clause::Set(_) => "SET",
Clause::Remove(_) => "REMOVE",
Clause::Return(_) => "RETURN",
Clause::With(_) => "WITH",
Clause::Unwind(_) => "UNWIND",
Clause::CreateIndex(_) => "CREATE INDEX",
Clause::DropIndex(_) => "DROP INDEX",
Clause::CreateConstraint(_) => "CREATE CONSTRAINT",
Clause::DropConstraint(_) => "DROP CONSTRAINT",
Clause::Foreach(_) => "FOREACH",
Clause::LoadCSV(_) => "LOAD CSV",
Clause::CallSubquery(_) | Clause::CallProcedure(_) => "CALL",
Clause::ShowFunctions(_) => "SHOW FUNCTIONS",
Clause::ShowConstraints(_) => "SHOW CONSTRAINTS",
Clause::ShowIndexes(_) => "SHOW INDEXES",
Clause::ShowDatabases(_) => "SHOW DATABASES",
Clause::ShowRoles(_) => "SHOW ROLES",
Clause::ShowServers(_) => "SHOW SERVERS",
Clause::ShowUsers(_) => "SHOW USERS",
Clause::ShowProcedures(_) => "SHOW PROCEDURES",
Clause::ShowSettings(_) => "SHOW SETTINGS",
Clause::ShowTransactions(_) => "SHOW TRANSACTIONS",
Clause::TerminateTransactions(_) => "TERMINATE TRANSACTIONS",
Clause::Use(_) => "USE",
Clause::Finish => "FINISH",
Clause::StandaloneOrderBy(_) => "ORDER BY",
Clause::Conditional(_) => "WHEN",
Clause::AlterCurrentGraphType(_) => "ALTER CURRENT GRAPH TYPE",
Clause::CreateGraphType(_) => "CREATE GRAPH TYPE",
Clause::ShowGraphType(_) => "SHOW GRAPH TYPE",
Clause::ShowCurrentGraphType(_) => "SHOW CURRENT GRAPH TYPE",
Clause::AlterDatabase(_) => "ALTER DATABASE",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct AlterDatabaseClause {
pub name: SchemaName,
pub if_exists: bool,
pub default_language: u32,
}
#[derive(Debug, Clone, PartialEq)]
pub struct AlterCurrentGraphTypeClause {
pub verb: AlterGraphTypeVerb,
pub target: AlterCurrentGraphTypeTarget,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AlterCurrentGraphTypeTarget {
Body(GraphTypeBody),
Named(SmallName),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct YieldItem {
pub name: SmallName,
pub alias: Option<SmallName>,
}
impl YieldItem {
pub fn effective_name(&self) -> SmallName {
self.alias.clone().unwrap_or_else(|| self.name.clone())
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct YieldList {
pub items: Vec<YieldItem>,
pub all: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum YieldMode {
Star,
Default,
Named,
}
impl YieldList {
pub fn mode(&self) -> YieldMode {
if self.all {
YieldMode::Star
} else if self.items.is_empty() {
YieldMode::Default
} else {
YieldMode::Named
}
}
pub fn present(&self) -> bool {
!matches!(self.mode(), YieldMode::Default)
}
pub fn names(&self) -> impl Iterator<Item = &SmallName> {
self.items.iter().map(|item| &item.name)
}
pub fn pairs(&self) -> impl Iterator<Item = (&SmallName, Option<&SmallName>, SmallName)> {
self.items
.iter()
.map(|item| (&item.name, item.alias.as_ref(), item.effective_name()))
}
pub fn effective_names(&self) -> impl Iterator<Item = SmallName> + '_ {
self.items.iter().map(YieldItem::effective_name)
}
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct ShowCurrentGraphTypeClause {
pub yields: YieldList,
pub stages: Vec<PageStage>,
pub where_expr: Option<Expr>,
pub as_graph: Option<AnyNodeMode>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum AnyNodeMode {
#[default]
Separate,
Single,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AlterGraphTypeVerb {
Set,
Add,
Alter,
Drop,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateGraphTypeClause {
pub name: SmallName,
pub body: GraphTypeBody,
pub via_as: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShowGraphTypeClause {
pub name: SmallName,
pub yields: YieldList,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct GraphTypeBody {
pub node_types: Vec<GraphTypeNodeTypeSpec>,
pub edge_types: Vec<GraphTypeEdgeTypeSpec>,
pub constraints: Vec<GraphTypeConstraintSpec>,
pub drop_constraint_names: Vec<SmallName>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct GraphTypeNodeTypeSpec {
pub alias: Option<SmallName>,
pub identifying_label: SmallName,
pub implied_labels: Vec<SmallName>,
pub properties: Vec<GraphTypePropertyType>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct GraphTypeEdgeTypeSpec {
pub alias: Option<SmallName>,
pub identifying_label: SmallName,
pub properties: Vec<GraphTypePropertyType>,
pub source: GraphTypeElementRef,
pub target: GraphTypeElementRef,
}
#[derive(Debug, Clone, PartialEq)]
pub struct GraphTypePropertyType {
pub name: SmallName,
pub value_type: TypeExpr,
pub default_value: Option<Expr>,
pub inline_constraint: Option<GraphTypeInlineConstraint>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct GraphTypeInlineConstraint {
pub verb: GraphTypeInlineVerb,
pub qualifier: Option<GraphTypeEntityQualifier>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GraphTypeInlineVerb {
Key,
Unique,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GraphTypeEntityQualifier {
Node,
Rel,
}
#[derive(Debug, Clone, PartialEq)]
pub enum GraphTypeElementRef {
Any,
AliasRef(SmallName),
InSitu {
alias: Option<SmallName>,
label: SmallName,
implies: bool,
},
}
#[derive(Debug, Clone, PartialEq)]
pub struct GraphTypeConstraintSpec {
pub name: Option<SmallName>,
pub target: GraphTypeElementRef,
pub is_edge: bool,
pub properties: Vec<SmallName>,
pub kind: GraphTypeConstraintVerb,
pub property_type: Option<TypeExpr>,
pub options: OptionsForm,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GraphTypeConstraintVerb {
Key,
Unique,
Exists,
PropertyType,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ConditionalClause {
pub branches: Vec<WhenBranch>,
pub else_body: Option<Statement>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WhenBranch {
pub predicate: Expr,
pub body: Statement,
}
#[derive(Debug, Clone, PartialEq)]
pub struct MatchClause {
pub optional: bool,
pub match_mode: MatchMode,
pub pattern: Vec<PatternPath>,
pub using_scan: Vec<ScanHint>,
pub using_index: Vec<IndexHint>,
pub using_join: Vec<JoinHint>,
pub where_expr: Option<Expr>,
pub search: Option<SearchClause>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ScanHint {
pub variable: SmallName,
pub label: SmallName,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IndexHint {
pub variable: SmallName,
pub label: SmallName,
pub properties: Vec<SmallName>,
}
impl IndexHint {
pub fn properties_text(&self) -> String {
self.properties
.iter()
.map(|property| property.to_string())
.collect::<Vec<_>>()
.join(", ")
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct JoinHint {
pub variables: Vec<SmallName>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SearchClause {
pub binding_var: SmallName,
pub spec: SearchSpec,
pub score_var: Option<SmallName>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum SearchSpec {
Index(SearchIndexSpec),
Combine(SearchCombineSpec),
}
#[derive(Debug, Clone, PartialEq)]
pub struct SearchIndexSpec {
pub kind: SearchKind,
pub index_name: SmallName,
pub for_expr: Expr,
pub analyzer: Option<Expr>,
pub inner_where: Option<Expr>,
pub offset_expr: Option<Expr>,
pub limit_expr: Expr,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SearchKind {
Vector,
Fulltext,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SearchCombineSpec {
pub sources: Vec<SearchWeightedSource>,
pub constant_expr: Option<Expr>,
pub limit_expr: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SearchWeightedSource {
pub spec: SearchSpec,
pub weight_expr: Option<Expr>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum MatchMode {
#[default]
DifferentRelationships,
RepeatableElements,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PathMode {
Walk,
Trail,
Acyclic,
Simple,
}
#[derive(Debug, Clone, PartialEq)]
pub enum PathCount {
Literal(u32),
Parameter(String),
}
#[derive(Debug, Clone, PartialEq)]
pub enum PathSelector {
All,
Any(Option<PathCount>),
AnyShortest,
AllShortest,
Shortest {
count: Option<PathCount>,
group: bool,
},
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateClause {
pub pattern: Vec<PatternPath>,
pub is_insert: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct MergeClause {
pub pattern: PatternPath,
pub on_create: Vec<SetItem>,
pub on_match: Vec<SetItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DeleteClause {
pub detach: bool,
pub expressions: Vec<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SetClause {
pub items: Vec<SetItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SetItem {
pub property: Option<PropertyAccess>,
pub variable: Option<SmallName>,
pub labels: Vec<LabelExpr>,
pub value: Option<Expr>,
pub merge: bool,
pub is_keyword: bool,
pub labels_function: Option<(Expr, LabelsFunctionOp)>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LabelsFunctionOp {
Overwrite,
Extend,
Remove,
}
#[derive(Debug, Clone, PartialEq)]
pub struct RemoveClause {
pub items: Vec<RemoveItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct RemoveItem {
pub property: Option<PropertyAccess>,
pub variable: Option<SmallName>,
pub labels: Vec<LabelExpr>,
pub is_keyword: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ReturnClause {
pub group_by: Option<GroupBySpec>,
pub distinct: bool,
pub items: Vec<ReturnItem>,
pub order_by: Vec<OrderByItem>,
pub skip: Option<Expr>,
pub limit: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ReturnItem {
pub expr: Expr,
pub alias: Option<SmallName>,
pub all: bool,
pub source_text: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct OrderByItem {
pub expr: Expr,
pub descending: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum WithOrigin {
#[default]
Explicit,
Let,
Filter,
}
#[derive(Debug, Clone, PartialEq)]
pub enum GroupBySpec {
Keys(Vec<Expr>),
Empty,
All,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WithClause {
pub group_by: Option<GroupBySpec>,
pub distinct: bool,
pub items: Vec<ReturnItem>,
pub order_by: Vec<OrderByItem>,
pub skip: Option<Expr>,
pub limit: Option<Expr>,
pub where_expr: Option<Expr>,
pub origin: WithOrigin,
}
#[derive(Debug, Clone, PartialEq)]
pub enum PageStage {
OrderBy(Vec<OrderByItem>),
Skip(Expr),
Limit(Expr),
}
#[derive(Debug, Clone, PartialEq)]
pub struct StandaloneOrderByClause {
pub stages: Vec<PageStage>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct UnwindClause {
pub expr: Expr,
pub alias: SmallName,
pub for_syntax: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IndexKind {
Range,
Point,
Text,
Fulltext,
Lookup,
Vector,
}
impl IndexKind {
pub fn storage_tag(&self) -> &'static str {
match self {
IndexKind::Range => "range",
IndexKind::Point => "point",
IndexKind::Text => "text",
IndexKind::Fulltext => "fulltext",
IndexKind::Lookup => "lookup",
IndexKind::Vector => "vector",
}
}
pub fn display_name(&self) -> &'static str {
match self {
IndexKind::Range => "RANGE",
IndexKind::Point => "POINT",
IndexKind::Text => "TEXT",
IndexKind::Fulltext => "FULLTEXT",
IndexKind::Lookup => "LOOKUP",
IndexKind::Vector => "VECTOR",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SchemaEntityType {
Node,
Relationship,
}
impl SchemaEntityType {
pub fn as_str(&self) -> &'static str {
match self {
SchemaEntityType::Node => "NODE",
SchemaEntityType::Relationship => "RELATIONSHIP",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum SchemaName {
Literal(String),
Parameter(String),
}
#[derive(Debug, Clone, PartialEq)]
pub enum OptionsForm {
Absent,
Literal(Vec<(String, Expr)>),
Parameter(String),
}
impl OptionsForm {
pub fn literal(&self) -> Option<&[(String, Expr)]> {
match self {
Self::Literal(entries) => Some(entries),
Self::Absent | Self::Parameter(_) => None,
}
}
pub fn parameter(&self) -> Option<&str> {
match self {
Self::Parameter(name) => Some(name),
Self::Absent | Self::Literal(_) => None,
}
}
pub fn literal_mut(&mut self) -> Option<&mut [(String, Expr)]> {
match self {
Self::Literal(entries) => Some(entries),
Self::Absent | Self::Parameter(_) => None,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateIndexClause {
pub name: Option<SchemaName>,
pub entity_type: SchemaEntityType,
pub labels: Vec<SmallName>,
pub properties: Vec<SmallName>,
pub if_not_exists: bool,
pub kind: IndexKind,
pub on_each: bool,
pub with_properties: Vec<SmallName>,
pub options: OptionsForm,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DropIndexClause {
pub name: SchemaName,
pub if_exists: bool,
pub legacy_target: Option<(SmallName, SmallName)>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShowIndexesClause {
pub kind_filter: Option<IndexKind>,
pub yields: YieldList,
pub where_expr: Option<Expr>,
pub stages: Vec<PageStage>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CreateConstraintClause {
pub name: Option<SchemaName>,
pub entity_type: SchemaEntityType,
pub label: SmallName,
pub variable: SmallName,
pub properties: Vec<SmallName>,
pub constraint_type: String, pub if_not_exists: bool,
pub property_type: Option<TypeExpr>,
pub options: OptionsForm,
pub enforced_label: Option<SmallName>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DropConstraintClause {
pub name: SchemaName,
pub if_exists: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ForeachClause {
pub variable: SmallName,
pub list_expr: Expr,
pub clauses: Vec<Clause>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct LoadCSVClause {
pub with_headers: bool,
pub source: Expr,
pub alias: SmallName,
pub field_terminator: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CallSubqueryClause {
pub statement: Statement,
pub scope: CallScope,
pub optional: bool,
pub in_transactions: Option<InTransactionsClause>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct InTransactionsClause {
pub concurrency: Concurrency,
pub batch_size: Option<Expr>,
pub on_error: OnErrorMode,
pub report_status: Option<SmallName>,
pub disjoint: Option<DisjointBy>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DisjointBy {
Expressions(Vec<Expr>),
Auto,
None,
}
impl InTransactionsClause {
pub fn exprs(&self) -> Vec<&Expr> {
let mut out = Vec::new();
match &self.concurrency {
Concurrency::Value(expr) => out.push(expr),
Concurrency::Sequential | Concurrency::DefaultUnspecified => {}
}
out.extend(self.batch_size.as_ref());
match &self.on_error {
OnErrorMode::Retry { duration, .. } => out.extend(duration.as_ref()),
OnErrorMode::Fail | OnErrorMode::Continue | OnErrorMode::Break => {}
}
match &self.disjoint {
Some(DisjointBy::Expressions(keys)) => out.extend(keys),
Some(DisjointBy::Auto | DisjointBy::None) | None => {}
}
out
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum Concurrency {
Sequential,
DefaultUnspecified,
Value(Expr),
}
#[derive(Debug, Clone, PartialEq)]
pub enum OnErrorMode {
Fail,
Continue,
Break,
Retry {
duration: Option<Expr>,
fallback: RetryFallback,
},
}
#[derive(Debug, Clone, PartialEq)]
pub enum RetryFallback {
Fail,
Continue,
Break,
}
#[derive(Debug, Clone, PartialEq)]
pub enum CallScope {
None,
Wildcard,
Vars(Vec<SmallName>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct UseClause {
pub graph_expr: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShowFunctionsClause {
pub yields: YieldList,
pub where_expr: Option<Expr>,
pub stages: Vec<PageStage>,
pub scope: FunctionScope,
pub executable: Option<ExecutableBy>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ExecutableBy {
User(String),
Current,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum FunctionScope {
#[default]
All,
BuiltIn,
UserDefined,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShowConstraintsClause {
pub yields: YieldList,
pub where_expr: Option<Expr>,
pub type_filter: ConstraintTypeFilter,
pub stages: Vec<PageStage>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConstraintEntityFilter {
Any,
Node,
Relationship,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConstraintKindFilter {
Unique,
Key,
PropertyType,
Existence,
PropertyExistence,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ConstraintTypeFilter {
pub entity: ConstraintEntityFilter,
pub kind: Option<ConstraintKindFilter>,
}
impl ConstraintTypeFilter {
pub fn all() -> Self {
ConstraintTypeFilter {
entity: ConstraintEntityFilter::Any,
kind: None,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShowDatabasesClause {
pub filter: DatabaseFilter,
pub yields: YieldList,
pub where_expr: Option<Expr>,
pub stages: Vec<PageStage>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DatabaseFilter {
All,
Default,
Home,
Named(SchemaName),
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShowRolesClause {
pub modifier: RoleModifier,
pub with_users: bool,
pub yields: YieldList,
pub where_expr: Option<Expr>,
pub stages: Vec<PageStage>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RoleModifier {
Any,
All,
Populated,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShowServersClause {
pub yields: YieldList,
pub where_expr: Option<Expr>,
pub stages: Vec<PageStage>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShowUsersClause {
pub current_only: bool,
pub yields: YieldList,
pub where_expr: Option<Expr>,
pub stages: Vec<PageStage>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShowProceduresClause {
pub yields: YieldList,
pub where_expr: Option<Expr>,
pub stages: Vec<PageStage>,
pub executable: Option<ExecutableBy>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShowSettingsClause {
pub names: Option<Expr>,
pub yields: YieldList,
pub where_expr: Option<Expr>,
pub stages: Vec<PageStage>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShowTransactionsClause {
pub ids: Vec<Expr>,
pub yields: YieldList,
pub where_expr: Option<Expr>,
pub stages: Vec<PageStage>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TerminateTransactionsClause {
pub ids: Vec<Expr>,
pub yields: YieldList,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CallProcedureClause {
pub procedure: SmallName,
pub args: Vec<Expr>,
pub explicit_args: bool,
pub yields: YieldList,
pub optional: bool,
pub where_expr: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PatternPath {
pub variable: Option<SmallName>,
pub subpath_variable: Option<SmallName>,
pub elements: Vec<PatternElement>,
pub where_expr: Option<Expr>,
pub mode: Option<PathMode>,
pub selector: Option<PathSelector>,
pub is_shortest_path_function: bool,
}
impl PatternPath {
pub fn path_names(&self) -> impl Iterator<Item = &SmallName> {
[self.variable.as_ref(), self.subpath_variable.as_ref()]
.into_iter()
.flatten()
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum PatternElement {
Node(NodePattern),
Relationship(RelPattern),
Quantified(QuantifiedPathPattern),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PathQuantifier {
pub min: u32,
pub max: Option<u32>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct QuantifiedPathPattern {
pub subpath_variable: Option<SmallName>,
pub elements: Vec<PatternElement>,
pub where_expr: Option<Expr>,
pub quantifier: PathQuantifier,
}
#[derive(Debug, Clone, PartialEq)]
pub struct NodePattern {
pub variable: Option<SmallName>,
pub label_expr: Option<LabelExpr>,
pub properties: Vec<(SmallName, Expr)>,
pub has_properties: bool,
pub properties_param: Option<Expr>,
pub where_expr: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct RelPattern {
pub variable: Option<SmallName>,
pub type_expr: Option<LabelExpr>,
pub properties: Vec<(SmallName, Expr)>,
pub has_properties: bool,
pub properties_param: Option<Expr>,
pub direction: Direction,
pub min_hops: Option<u32>,
pub max_hops: Option<u32>,
pub where_expr: Option<Expr>,
pub quantified: bool,
}
impl RelPattern {
pub fn is_variable_length(&self) -> bool {
self.min_hops.is_some() || self.max_hops.is_some()
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum LabelExpr {
Label(SmallName),
Wildcard,
Dynamic(DynamicLabelExpr),
Not(Box<LabelExpr>),
And(Vec<LabelExpr>),
Or(Vec<LabelExpr>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DynamicLabelQuantifier {
Default,
All,
Any,
}
#[derive(Debug, Clone, PartialEq)]
pub struct DynamicLabelExpr {
pub expr: Box<Expr>,
pub quantifier: DynamicLabelQuantifier,
}
impl LabelExpr {
pub fn as_label_list(&self) -> Option<Vec<SmallName>> {
match self {
LabelExpr::Label(name) => Some(vec![name.clone()]),
LabelExpr::And(items) => {
let mut out = Vec::with_capacity(items.len());
for item in items {
match item {
LabelExpr::Label(name) => out.push(name.clone()),
_ => return None,
}
}
Some(out)
}
_ => None,
}
}
pub fn contains_not_or_wildcard(&self) -> bool {
match self {
LabelExpr::Label(_) | LabelExpr::Dynamic(_) => false,
LabelExpr::Wildcard | LabelExpr::Not(_) => true,
LabelExpr::And(items) | LabelExpr::Or(items) => {
items.iter().any(LabelExpr::contains_not_or_wildcard)
}
}
}
pub fn as_ddl_list(&self) -> Option<Vec<SmallName>> {
match self {
LabelExpr::Label(name) => Some(vec![name.clone()]),
LabelExpr::Or(items) => {
let mut out = Vec::with_capacity(items.len());
for item in items {
match item {
LabelExpr::Label(name) => out.push(name.clone()),
_ => return None,
}
}
Some(out)
}
_ => None,
}
}
pub fn contains_dynamic(&self) -> bool {
match self {
LabelExpr::Label(_) | LabelExpr::Wildcard => false,
LabelExpr::Dynamic(_) => true,
LabelExpr::Not(inner) => inner.contains_dynamic(),
LabelExpr::And(items) | LabelExpr::Or(items) => {
items.iter().any(LabelExpr::contains_dynamic)
}
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Direction {
Right, Left, Both, }
mod expr_children;
pub use expr_children::{ExprEdge, ExprEdgeMut};
#[derive(Debug, Clone, PartialEq)]
pub enum InterpPart {
Text(String),
Interp(Box<Expr>),
}
#[derive(Debug, Clone, PartialEq)]
pub enum Expr {
Literal(LiteralValue),
List(Vec<Expr>),
Map(Vec<MapPair>),
StringInterp(Vec<InterpPart>),
Variable(SmallName),
Parameter(String),
Property(Box<PropertyAccess>),
FunctionCall(FunctionCallExpr),
Binary(Box<BinaryExpr>),
Unary(Box<UnaryExpr>),
Comparison(Box<ComparisonExpr>),
In(Box<InExpr>),
IsNull(Box<IsNullExpr>),
IsType(Box<IsTypeExpr>),
IsNormalized(Box<IsNormalizedExpr>),
ChronologicalCompare(Box<ChronologicalCompareExpr>),
StringMatch(Box<StringMatchExpr>),
CountStar,
Star,
Case(Box<CaseExpr>),
ExistsSubquery(Box<ExistsSubqueryExpr>),
CountSubquery(Box<CountSubqueryExpr>),
CollectSubquery(Box<CollectSubqueryExpr>),
ListComprehension(Box<ListComprehensionExpr>),
MapComprehension(Box<MapComprehensionExpr>),
PatternComprehension(Box<PatternComprehensionExpr>),
Reduce(Box<ReduceExpr>),
AllReduce(Box<AllReduceExpr>),
ShortestPath(Box<ShortestPathExpr>),
Subscript(Box<SubscriptExpr>),
Quantifier(Box<QuantifierExpr>),
HasLabel(Box<HasLabelExpr>),
Paren(Box<Expr>),
PatternPredicate(Box<PatternPredicateExpr>),
MapProjection(Box<MapProjectionExpr>),
OptionValuePlaceholder,
}
#[derive(Debug, Clone, PartialEq)]
pub enum LiteralValue {
Null,
Bool(bool),
Integer(i64),
Float(f64),
String(String),
}
#[derive(Debug, Clone, PartialEq)]
pub struct MapPair {
pub key: SmallName,
pub value: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct MapProjectionExpr {
pub expr: Expr,
pub items: Vec<MapProjectionItem>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum MapProjectionItem {
AllProperties,
Property(SmallName),
Variable(SmallName),
KeyValue(SmallName, Expr),
}
#[derive(Debug, Clone, PartialEq)]
pub struct PropertyAccess {
pub expr: Expr,
pub property: SmallName,
pub key_expr: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FunctionCallExpr {
pub name: SmallName,
pub args: Vec<Expr>,
pub distinct: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct BinaryExpr {
pub left: Expr,
pub op: &'static str,
pub right: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct UnaryExpr {
pub op: &'static str,
pub expr: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ComparisonExpr {
pub left: Expr,
pub op: &'static str,
pub right: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct InExpr {
pub expr: Expr,
pub list: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct IsNullExpr {
pub expr: Expr,
pub negated: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct IsTypeExpr {
pub expr: Expr,
pub type_expr: TypeExpr,
pub negated: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum TypeExpr {
Predefined {
kind: PredefinedKind,
not_null: bool,
},
List {
element: Box<TypeExpr>,
not_null: bool,
},
PropertyValue { not_null: bool },
Union(Vec<TypeExpr>),
Vector {
coord: Option<VectorCoordKind>,
dimension: Option<i64>,
not_null: bool,
},
}
impl TypeExpr {
pub fn direct_not_null(&self) -> bool {
match self {
TypeExpr::Predefined { not_null, .. } => *not_null,
TypeExpr::List { not_null, .. } => *not_null,
TypeExpr::PropertyValue { not_null } => *not_null,
TypeExpr::Vector { not_null, .. } => *not_null,
TypeExpr::Union(_) => false,
}
}
}
pub use relate_model::VectorCoordKind;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PredefinedKind {
Nothing,
Null,
Any,
Boolean,
String,
Integer,
Float,
Date,
Duration,
Point,
LocalTime,
ZonedTime,
LocalDateTime,
ZonedDateTime,
Node,
Relationship,
Path,
Map,
Uuid,
}
#[derive(Debug, Clone, PartialEq)]
pub struct IsNormalizedExpr {
pub expr: Expr,
pub form: Option<String>,
pub negated: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChronologicalOp {
Before,
After,
SameInstant,
SameRepresentation,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ChronologicalCompareExpr {
pub left: Expr,
pub op: ChronologicalOp,
pub right: Expr,
pub negated: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StringMatchExpr {
pub left: Expr,
pub op: &'static str,
pub right: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CaseExpr {
pub whens: Vec<WhenClause>,
pub else_expr: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct WhenClause {
pub condition: Expr,
pub result: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ExistsSubqueryExpr {
pub statement: Statement,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CountSubqueryExpr {
pub statement: Statement,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CollectSubqueryExpr {
pub statement: Statement,
}
#[derive(Debug, Clone, PartialEq)]
pub struct MapComprehensionExpr {
pub key_var: Option<SmallName>,
pub value_var: SmallName,
pub source_expr: Expr,
pub where_expr: Option<Expr>,
pub key_expr: Expr,
pub value_expr: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ListComprehensionExpr {
pub variable: SmallName,
pub list_expr: Expr,
pub where_expr: Option<Expr>,
pub map_expr: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PatternComprehensionExpr {
pub path_variable: Option<SmallName>,
pub pattern: PatternPath,
pub where_expr: Option<Expr>,
pub map_expr: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ReduceExpr {
pub accumulator: SmallName,
pub init_expr: Expr,
pub variable: SmallName,
pub list_expr: Expr,
pub expression: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct AllReduceExpr {
pub accumulator: SmallName,
pub init_expr: Expr,
pub variable: SmallName,
pub list_expr: Expr,
pub expression: Expr,
pub predicate: Expr,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShortestPathExpr {
pub pattern: PatternPath,
pub all: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SubscriptExpr {
pub expr: Expr,
pub index: Option<Expr>,
pub from: Option<Expr>,
pub to: Option<Expr>,
pub slice: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct QuantifierExpr {
pub quantifier: String,
pub variable: SmallName,
pub list: Expr,
pub predicate: Option<Expr>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct HasLabelExpr {
pub expr: Expr,
pub label_expr: LabelExpr,
pub negated: bool,
pub strict: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct PatternPredicateExpr {
pub pattern: PatternPath,
}