summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLV-426 <lv-426@taproot.org.il>2014-10-06 18:49:14 +0300
committerLV-426 <lv-426@taproot.org.il>2014-10-06 18:50:14 +0300
commite4fbde3cea8a5febda828b12927a3759d430606d (patch)
treeef08079b73cebd000463534ae03c4164414c0cde
parenteef0c89ed89293ca89ba8b5f42b7100c46682fd7 (diff)
handle empty filter maps
-rw-r--r--src-py/db_controller.py42
-rw-r--r--src-py/neo4j_util.py5
2 files changed, 27 insertions, 20 deletions
diff --git a/src-py/db_controller.py b/src-py/db_controller.py
index b4ce0fc5..dcc22f7c 100644
--- a/src-py/db_controller.py
+++ b/src-py/db_controller.py
@@ -112,7 +112,7 @@ class DBO_add_node_set(DB_op):
class DBO_load_node_id_set(DB_op):
def __init__(self, filter_type, filter_prop=None):
- # TODO: mv type filter to DBO_load_node_set_by_attribute
+ # TODO: mv type filter to DBO_load_node_set
"""
load node DB id set, filter by type / properties
"""
@@ -161,35 +161,23 @@ class DBO_load_node_set_by_DB_id(DB_op):
log.debug('loaded node set: ' + str(data))
return self.extract_single_query_response_data(self.statement_set[0], data)
-class DBO_load_node_set_by_attribute(DB_op):
+class DBO_load_node_set(DB_op):
- def __init__(self, filter_attr_map):
+ def __init__(self, filter_type=None, filter_attr_map=None):
"""
load a set of nodes according to filter_attr_map
@param filter_attr_map: is a filter_key to filter_value_set map of
attributes to match against, eg.:
{ 'id':[0,1], 'color: ['red','blue'] }
+ @param filter_type: node type filter
@return: loaded node set or an empty set if no match was found
"""
- # type sanity checks
- assert isinstance(filter_attr_map, dict)
- assert len(filter_attr_map) > 0
- for k, v in filter_attr_map.items():
- assert isinstance(k, basestring)
- assert isinstance(v, list)
-
- filter_arr = []
- for k, v in filter_attr_map.items():
- # create a cypher query parameter place holder for each attr set
- # eg. n.foo in {foo}, where foo is passed as a query parameter
- f_attr = "n.{0} in {{{0}}}".format(k, v)
- filter_arr.append(f_attr)
+ self.__type_check_filter_attr_map(filter_attr_map)
+ filter_str = dbu.where_clause_from_filter_attr_map()
- filter_str = "where {0}".format(' and '.join(filter_arr))
-
- super(DBO_load_node_set_by_attribute, self).__init__()
+ super(DBO_load_node_set, self).__init__()
q = "match (n) {0} return n".format(filter_str)
self.add_statement(q, params=filter_attr_map)
@@ -197,7 +185,7 @@ class DBO_load_node_set_by_attribute(DB_op):
log.debug('loaded node set: ' + str(data))
return self.extract_single_query_response_data(self.statement_set[0], data)
-class DBO_load_node_set_by_id_attribute(DBO_load_node_set_by_attribute):
+class DBO_load_node_set_by_id_attribute(DBO_load_node_set):
def __init__(self, id_set):
"""
convenience op: load a set of nodes by their 'id' attribute != DB node id
@@ -206,6 +194,20 @@ class DBO_load_node_set_by_id_attribute(DBO_load_node_set_by_attribute):
super(DBO_load_node_set_by_id_attribute, self).__init__({'id': id_set})
+class DBO_load_link_id_set(DB_op):
+ def __init__(self, filter_type=None, filter_attr_map=None):
+ """
+ load a set of link ids
+
+ @param filter_type: link type filter
+ @param filter_attr_map: is a filter_key to filter_value_set map of
+ attributes to match link properties against
+ @return: a set of loaded link ids
+ """
+ self.__type_check_filter_attr_map(filter_attr_map)
+ filter_str = dbu.where_clause_from_filter_attr_map()
+
+
class DB_Driver_Base():
pass
diff --git a/src-py/neo4j_util.py b/src-py/neo4j_util.py
index 929324fb..c340e15a 100644
--- a/src-py/neo4j_util.py
+++ b/src-py/neo4j_util.py
@@ -54,7 +54,12 @@ def where_clause_from_filter_attr_map(filter_attr_map, node_param_name="n"):
convert a filter attribute map to a parameterized Cypher where clause, eg.
in: { 'att_foo': [ 'a', 'b' ], 'att_goo': [1,2] }
out: where n.att_foo in {att_foo} and n.att_goo in {att_goo} ...
+
+ @param filter_attr_map: may be None or empty
"""
+ if not filter_attr_map:
+ return ""
+
filter_arr = []
for k in filter_attr_map.keys():
# create a cypher query parameter place holder for each attr set