hawdb-optimizer-graph 0.13.0

An embedded Rust graph database for local data-plane workloads
Documentation
// Copyright 2026 Nowledge
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::super::PhysicalPlan;
use hawdb_plan_cypher::LogicalPlan;

pub(super) fn lower(logical: &LogicalPlan) -> Option<PhysicalPlan> {
    match logical {
        LogicalPlan::CreateNode { label, properties } => Some(PhysicalPlan::CreateNode {
            label: label.clone(),
            properties: properties.clone(),
        }),
        LogicalPlan::UnwindMutation {
            rows,
            variable,
            operation,
        } => Some(PhysicalPlan::UnwindMutation {
            rows: rows.clone(),
            variable: variable.clone(),
            operation: operation.clone(),
        }),
        LogicalPlan::MergeNode {
            label,
            match_properties,
            on_create_properties,
            on_match_assignments,
            post_merge_assignments,
        } => Some(PhysicalPlan::MergeNode {
            label: label.clone(),
            match_properties: match_properties.clone(),
            on_create_properties: on_create_properties.clone(),
            on_match_assignments: on_match_assignments.clone(),
            post_merge_assignments: post_merge_assignments.clone(),
        }),
        LogicalPlan::MergeRelationship {
            source_label,
            source_properties,
            rel_type,
            rel_properties,
            target_label,
            target_properties,
        } => Some(PhysicalPlan::MergeRelationship {
            source_label: source_label.clone(),
            source_properties: source_properties.clone(),
            rel_type: rel_type.clone(),
            rel_properties: rel_properties.clone(),
            target_label: target_label.clone(),
            target_properties: target_properties.clone(),
        }),
        LogicalPlan::MergeMatchedRelationship {
            source_label,
            source_properties,
            target_label,
            target_properties,
            rel_type,
            rel_match_properties,
            on_create_properties,
        } => Some(PhysicalPlan::MergeMatchedRelationship {
            source_label: source_label.clone(),
            source_properties: source_properties.clone(),
            target_label: target_label.clone(),
            target_properties: target_properties.clone(),
            rel_type: rel_type.clone(),
            rel_match_properties: rel_match_properties.clone(),
            on_create_properties: on_create_properties.clone(),
        }),
        LogicalPlan::MergeRelationshipFromMatchedRelationship {
            source_label,
            source_properties,
            old_rel_variable: _,
            old_rel_type,
            old_rel_properties,
            target_label,
            target_properties,
            new_rel_type,
            new_rel_match_properties,
            on_create_properties,
        } => Some(PhysicalPlan::MergeRelationshipFromMatchedRelationship {
            source_label: source_label.clone(),
            source_properties: source_properties.clone(),
            old_rel_type: old_rel_type.clone(),
            old_rel_properties: old_rel_properties.clone(),
            target_label: target_label.clone(),
            target_properties: target_properties.clone(),
            new_rel_type: new_rel_type.clone(),
            new_rel_match_properties: new_rel_match_properties.clone(),
            on_create_properties: on_create_properties.clone(),
        }),
        LogicalPlan::MergeRelationshipToMatchedTarget {
            source_label,
            source_properties,
            old_rel_type,
            old_rel_properties,
            old_target_label,
            old_target_properties,
            new_target_label,
            new_target_properties,
            new_rel_type,
            new_rel_match_properties,
            on_create_properties,
        } => Some(PhysicalPlan::MergeRelationshipToMatchedTarget {
            source_label: source_label.clone(),
            source_properties: source_properties.clone(),
            old_rel_type: old_rel_type.clone(),
            old_rel_properties: old_rel_properties.clone(),
            old_target_label: old_target_label.clone(),
            old_target_properties: old_target_properties.clone(),
            new_target_label: new_target_label.clone(),
            new_target_properties: new_target_properties.clone(),
            new_rel_type: new_rel_type.clone(),
            new_rel_match_properties: new_rel_match_properties.clone(),
            on_create_properties: on_create_properties.clone(),
        }),
        LogicalPlan::MergeRelationshipFromMatchedTarget {
            old_source_label,
            old_source_properties,
            old_rel_type,
            old_rel_properties,
            old_target_label,
            old_target_properties,
            new_source_label,
            new_source_properties,
            new_rel_type,
            new_rel_match_properties,
            on_create_properties,
        } => Some(PhysicalPlan::MergeRelationshipFromMatchedTarget {
            old_source_label: old_source_label.clone(),
            old_source_properties: old_source_properties.clone(),
            old_rel_type: old_rel_type.clone(),
            old_rel_properties: old_rel_properties.clone(),
            old_target_label: old_target_label.clone(),
            old_target_properties: old_target_properties.clone(),
            new_source_label: new_source_label.clone(),
            new_source_properties: new_source_properties.clone(),
            new_rel_type: new_rel_type.clone(),
            new_rel_match_properties: new_rel_match_properties.clone(),
            on_create_properties: on_create_properties.clone(),
        }),
        LogicalPlan::CreateMatchedRelationship {
            source_label,
            source_properties,
            target_label,
            target_properties,
            rel_type,
            rel_properties,
        } => Some(PhysicalPlan::CreateMatchedRelationship {
            source_label: source_label.clone(),
            source_properties: source_properties.clone(),
            target_label: target_label.clone(),
            target_properties: target_properties.clone(),
            rel_type: rel_type.clone(),
            rel_properties: rel_properties.clone(),
        }),
        LogicalPlan::SetNodeProperty {
            variable,
            label,
            predicate,
            property,
            value,
        } => Some(PhysicalPlan::SetNodeProperty {
            variable: variable.clone(),
            label: label.clone(),
            predicate: predicate.clone(),
            property: property.clone(),
            value: value.clone(),
        }),
        LogicalPlan::SetNodeProperties {
            variable,
            label,
            predicate,
            assignments,
        } => Some(PhysicalPlan::SetNodeProperties {
            variable: variable.clone(),
            label: label.clone(),
            predicate: predicate.clone(),
            assignments: assignments.clone(),
        }),
        LogicalPlan::SetNodePropertiesReturn {
            variable,
            label,
            predicate,
            assignments,
            returns,
        } => Some(PhysicalPlan::SetNodePropertiesReturn {
            variable: variable.clone(),
            label: label.clone(),
            predicate: predicate.clone(),
            assignments: assignments.clone(),
            returns: returns.clone(),
        }),
        LogicalPlan::SetRelationshipProperty {
            source_variable,
            source_label,
            predicate,
            rel_variable,
            rel_type,
            rel_properties,
            rel_predicate,
            target_variable,
            target_label,
            target_properties,
            property,
            value,
        } => Some(PhysicalPlan::SetRelationshipProperty {
            source_variable: source_variable.clone(),
            source_label: source_label.clone(),
            predicate: predicate.clone(),
            rel_variable: rel_variable.clone(),
            rel_type: rel_type.clone(),
            rel_properties: rel_properties.clone(),
            rel_predicate: rel_predicate.clone(),
            target_variable: target_variable.clone(),
            target_label: target_label.clone(),
            target_properties: target_properties.clone(),
            property: property.clone(),
            value: value.clone(),
        }),
        LogicalPlan::SetRelationshipProperties {
            source_variable,
            source_label,
            predicate,
            rel_variable,
            rel_type,
            rel_properties,
            rel_predicate,
            target_variable,
            target_label,
            target_properties,
            assignments,
        } => Some(PhysicalPlan::SetRelationshipProperties {
            source_variable: source_variable.clone(),
            source_label: source_label.clone(),
            predicate: predicate.clone(),
            rel_variable: rel_variable.clone(),
            rel_type: rel_type.clone(),
            rel_properties: rel_properties.clone(),
            rel_predicate: rel_predicate.clone(),
            target_variable: target_variable.clone(),
            target_label: target_label.clone(),
            target_properties: target_properties.clone(),
            assignments: assignments.clone(),
        }),
        LogicalPlan::DeleteNode {
            variable,
            label,
            predicate,
            detach,
        } => Some(PhysicalPlan::DeleteNode {
            variable: variable.clone(),
            label: label.clone(),
            predicate: predicate.clone(),
            detach: *detach,
        }),
        LogicalPlan::DeleteRelationship {
            source_variable,
            source_label,
            predicate,
            rel_variable,
            rel_type,
            rel_properties,
            rel_predicate,
            target_variable,
            target_label,
            target_properties,
        } => Some(PhysicalPlan::DeleteRelationship {
            source_variable: source_variable.clone(),
            source_label: source_label.clone(),
            predicate: predicate.clone(),
            rel_variable: rel_variable.clone(),
            rel_type: rel_type.clone(),
            rel_properties: rel_properties.clone(),
            rel_predicate: rel_predicate.clone(),
            target_variable: target_variable.clone(),
            target_label: target_label.clone(),
            target_properties: target_properties.clone(),
        }),
        LogicalPlan::DeleteRelationshipTargetNodes {
            source_variable,
            source_label,
            source_predicate,
            rel_type,
            rel_properties,
            target_variable,
            target_label,
            target_properties,
            detach,
        } => Some(PhysicalPlan::DeleteRelationshipTargetNodes {
            source_variable: source_variable.clone(),
            source_label: source_label.clone(),
            source_predicate: source_predicate.clone(),
            rel_type: rel_type.clone(),
            rel_properties: rel_properties.clone(),
            target_variable: target_variable.clone(),
            target_label: target_label.clone(),
            target_properties: target_properties.clone(),
            detach: *detach,
        }),
        LogicalPlan::CreateRelationship {
            source_label,
            source_properties,
            rel_type,
            rel_properties,
            target_label,
            target_properties,
        } => Some(PhysicalPlan::CreateRelationship {
            source_label: source_label.clone(),
            source_properties: source_properties.clone(),
            rel_type: rel_type.clone(),
            rel_properties: rel_properties.clone(),
            target_label: target_label.clone(),
            target_properties: target_properties.clone(),
        }),
        _ => None,
    }
}