Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-ricciardi committed Jun 4, 2024
1 parent e87bfef commit d389373
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 186 deletions.
161 changes: 0 additions & 161 deletions lib/zawgl-front/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
pub mod planner;
pub mod tx_handler;

use std::{collections::{HashMap, hash_map::Entry}, slice::Iter};

use bson::{Bson, Document, doc};
use cypher::query_engine::{process_cypher_query, CypherError};
use zawgl_core::{model::{Property, PropertyValue, PropertyGraph, Relationship, Node}, graph::{EdgeData, NodeIndex, EdgeIndex}};
Expand Down Expand Up @@ -164,165 +162,6 @@ fn build_response(request_id: &str, qr: QueryResult, request: &Request) -> Resul
Ok(response_doc)
}

fn get_properties<'a: 'b, 'b>(graph: &'a PropertyGraph, group: &'b mut Vec::<&'a PropertyValue>, args: &Vec<ValueItem>) {
for node in graph.get_nodes() {
if let Some(var) = node.get_var() {
for arg in args {
if let ValueItem::ItemPropertyName(prop_arg) = arg {
if &prop_arg.item_name == var {
for prop in node.get_properties_ref() {
if prop.get_name() == prop_arg.property_name {
group.push(prop.get_value())
}
}
}
}
}
}
}
for rel in graph.get_relationships() {
if let Some(var) = rel.get_var() {
for arg in args {
if let ValueItem::ItemPropertyName(prop_arg) = arg {
if &prop_arg.item_name == var {
for prop in rel.get_properties_ref() {
if prop.get_name() == prop_arg.property_name {
group.push(prop.get_value())
}
}
}
}
}

}
}
}

fn compute_sum(args: &Vec<ValueItem>, graphs: &Vec<&PropertyGraph>) -> Bson {
let mut group = Vec::<&PropertyValue>::new();
for graph in graphs {
get_properties(graph, &mut group, args);
}

let mut sum_value = 0.;
for prop in group {
sum_value += get_property_sum_value(prop);
}
Bson::from(sum_value)
}

fn get_property_sum_value(prop: &PropertyValue) -> f64 {
match prop {
PropertyValue::PFloat(f) => *f,
PropertyValue::PInteger(i) => *i as f64,
PropertyValue::PUInteger(u) => *u as f64,
_ => 0.
}
}

#[derive(Debug, Clone)]
enum Item<'a> {
Node(&'a Node),
Relationship(&'a EdgeData<NodeIndex, EdgeIndex, Relationship>),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum ItemId {
NodeId(u64),
RelationshipId(u64),
}

struct Combination<'a> {
graph: &'a PropertyGraph,
items: Vec<Item<'a>>,
}

impl<'a> Combination<'a> {
fn get_item_ids(&self) -> Vec<ItemId> {
self.items.iter().map(|item| match item {
Item::Node(node) => ItemId::NodeId(node.get_id().unwrap()),
Item::Relationship(rel) => ItemId::RelationshipId(rel.relationship.get_id().unwrap())
}).collect::<Vec<ItemId>>()
}
fn get_items(&self) -> &'a Vec<Item> {
&self.items
}
}

fn get_property_in_items(alias: Option<&String>, item_name: &str, prop_name: &str, items: &Vec<Item>) -> Result<Document, CypherError> {
for item in items {
match item {
Item::Node(node) => {
if let Some(var) = node.get_var() {
if var == item_name {
let ret_name = if let Some(a) = alias {
a.to_string()
} else {
item_name.to_string()
};
for prop in node.get_properties_ref() {
if prop.get_name() == prop_name {
return Ok(build_property_value(&ret_name, prop.get_value()));
}
}
}
}
},
Item::Relationship(rel) => {
if let Some(var) = rel.relationship.get_var() {
if var == item_name {
let ret_name = if let Some(a) = alias {
a.to_string()
} else {
item_name.to_string()
};
for prop in rel.relationship.get_properties_ref() {
if prop.get_name() == prop_name {
return Ok(build_property_value(&ret_name, prop.get_value()));
}
}
}
}
}
}
}
Err(CypherError::ResponseError)
}

fn build_items_combinations<'a: 'b, 'b>(mut grouping: Iter<&String>, graph: &'a PropertyGraph, combinations: &mut Vec::<Combination<'b>>, curr_items: &mut Vec<Item<'a>>) -> Result<(), CypherError> {
if let Some(next) = grouping.next() {
let items = get_named_items(next, graph)?;
for item in items {
curr_items.push(item);
build_items_combinations(grouping.clone(), graph, combinations, curr_items)?;
}
} else {
combinations.push(Combination { graph: graph, items: curr_items.to_vec() });
curr_items.clear();
}
Ok(())
}


fn get_named_items<'a>(name: &str, graph: &'a PropertyGraph) -> Result<Vec<Item<'a>>, CypherError> {
let mut res = vec![];
for node in graph.get_nodes() {
if let Some(var) = node.get_var() {
if var == name {
res.push(Item::Node(&node));
}
}
}
for rel in graph.get_relationships_and_edges() {
if let Some(var) = rel.relationship.get_var() {
if var == name {
res.push(Item::Relationship(&rel));
}
}
}
Ok(res)
}

fn make_node_doc(node: &NodeResult) -> Result<Document, CypherError> {
let node_doc = doc!{
"name": node.name.to_string(),
Expand Down
24 changes: 0 additions & 24 deletions lib/zawgl-front/src/planner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,18 +322,6 @@ fn compute_sum(args: &Vec<ValueItem>, graphs: &Vec<&PropertyGraph>) -> f64 {
}
sum_value
}
fn get_nodes_named(ret_all: bool, alias: Option<&String>, name: &str, graph: &PropertyGraph) -> Vec<NodeResult> {
let mut nodes = vec![];
for node in graph.get_nodes() {
if let Some(var) = node.get_var() {
if var == name || ret_all {
nodes.push(make_node(alias, name, node));
}
}
}
nodes
}


fn make_node(alias: Option<&String>, name: &str, node: &Node) -> NodeResult {
let ret_name = if let Some(a) = alias {
Expand All @@ -359,18 +347,6 @@ fn make_relationship(alias: Option<&String>, name: &str, rel: &EdgeData<NodeInde
Ok(RelationshipResult::new(ret_name, ret_rel, sid, tid))
}

fn get_relationships_named(ret_all: bool, alias: Option<&String>, name: &str, graph: &PropertyGraph) -> Result<Vec<RelationshipResult>, CypherError> {
let mut rels = vec![];
for rel in graph.get_relationships_and_edges() {
if let Some(var) = rel.relationship.get_var() {
if var == name || ret_all {
rels.push(make_relationship(alias, name, rel, graph)?);
}
}
}
Ok(rels)
}

fn get_property_sum_value(prop: &PropertyValue) -> f64 {
match prop {
PropertyValue::PFloat(f) => *f,
Expand Down
1 change: 0 additions & 1 deletion lib/zawgl-front/src/tx_handler/request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use std::sync::Arc;
use std::sync::Mutex;
use std::vec;
use zawgl_core::graph_engine::GraphEngine;
use zawgl_core::model::PropertyGraph;
use zawgl_core::model::init::InitContext;
use zawgl_cypher_query_model::QueryResult;
use zawgl_cypher_query_model::QueryStep;
Expand Down

0 comments on commit d389373

Please sign in to comment.