Skip to content
Snippets Groups Projects
Unverified Commit 5c34b76b authored by jimingquan's avatar jimingquan Committed by GitHub
Browse files

list change to set (#283)


* list change to set

* check_subgraph_result

* add line

* address comment

* fix error

* address comment

Co-authored-by: default avatarYee <2520865+yixinglu@users.noreply.github.com>
parent 75cfdb7c
No related branches found
No related tags found
No related merge requests found
......@@ -143,7 +143,7 @@ Expression* GetSubgraphValidator::buildFilterCondition(int64_t step) {
} else {
left = new RelationalExpression(Expression::Kind::kRelIn,
new EdgeDstIdExpression(new std::string("*")),
new ListExpression(startVidList_.release()));
new SetExpression(startVidList_.release()));
}
auto* lastestVidsDataSet = new VersionedVariableExpression(new std::string(collectVar_),
new ConstantExpression(0));
......@@ -198,7 +198,7 @@ Status GetSubgraphValidator::zeroStep(PlanNode* depend, const std::string& input
Aggregate::make(qctx_,
getVertex,
{},
{Aggregate::GroupItem(column->expr(), AggFun::nameIdMap_[fun], true)});
{Aggregate::GroupItem(column->expr(), AggFun::nameIdMap_[fun], false)});
collectVertex->setInputVar(getVertex->outputVar());
collectVertex->setColNames({"_vertices"});
......@@ -227,7 +227,7 @@ Status GetSubgraphValidator::toPlan() {
new VariablePropertyExpression(new std::string(var), new std::string(kVid)),
new std::string(kVid));
qctx_->objPool()->add(column);
column->setAggFunction(new std::string("COLLECT"));
column->setAggFunction(new std::string("COLLECT_SET"));
auto fun = column->getAggFunName();
collectRunTimeStartVids =
Aggregate::make(qctx_,
......@@ -261,7 +261,7 @@ Status GetSubgraphValidator::toPlan() {
new VariablePropertyExpression(new std::string(var), new std::string(kVid)),
new std::string(kVid));
qctx_->objPool()->add(column);
column->setAggFunction(new std::string("COLLECT"));
column->setAggFunction(new std::string("COLLECT_SET"));
auto fun = column->getAggFunName();
auto* collect =
Aggregate::make(qctx_,
......
......@@ -16,6 +16,7 @@ from nebula2.common import ttypes as CommonTtypes
from nebula2.ConnectionPool import ConnectionPool
from nebula2.graph import ttypes
from tests.common.configs import get_delay_time
import functools
import re
......@@ -485,6 +486,103 @@ class NebulaTestSuite(object):
empty = True
assert empty, msg
def compare_vertex(self, vertex1, vertex2):
assert isinstance(vertex1, CommonTtypes.Vertex) and isinstance(vertex2, CommonTtypes.Vertex)
if vertex1.vid != vertex2.vid:
if vertex1.vid < vertex2.vid:
return -1
return 1
if len(vertex1.tags) != len(vertex2.tags):
return len(vertex1.tags) - len(vertex2.tags)
return 0
def compare_edge(self, edge1, edge2):
assert isinstance(edge1, CommonTtypes.Edge) and isinstance(edge2, CommonTtypes.Edge)
if edge1.src != edge2.src:
if edge1.src < edge2.src:
return -1
return 1
if edge1.dst != edge2.dst:
if edge1.dst < edge2.dst:
return -1
return 1
if edge1.type != edge2.type:
return edge1.type - edge2.type
if edge1.ranking != edge2.ranking:
return edge1.ranking - edge2.ranking
if len(edge1.props) != len(edge2.props):
return len(edge1.props) - len(edge2.props)
return 0
def sort_vertex_list(self, rows):
assert len(rows) == 1
if isinstance(rows[0], CommonTtypes.Row):
vertex_list = list(map(lambda v : v.get_vVal(), rows[0].values[0].get_lVal().values))
sort_vertex_list = sorted(vertex_list, key = functools.cmp_to_key(self.compare_vertex))
elif isinstance(rows[0], list):
vertex_list = list(map(lambda v : v.get_vVal(), rows[0][0]))
sort_vertex_list = sorted(vertex_list, key = functools.cmp_to_key(self.compare_vertex))
else:
assert False
return sort_vertex_list
def sort_vertex_edge_list(self, rows):
new_rows = list()
for row in rows:
new_row = list()
if isinstance(row, CommonTtypes.Row):
vertex_list = row.values[0].get_lVal().values
new_vertex_list = list(map(lambda v : v.get_vVal(), vertex_list))
new_row.extend(sorted(new_vertex_list, key = functools.cmp_to_key(self.compare_vertex)))
edge_list = row.values[1].get_lVal().values
new_edge_list = list(map(lambda e : e.get_eVal(), edge_list))
new_row.extend(sorted(new_edge_list, key = functools.cmp_to_key(self.compare_edge)))
elif isinstance(row, list):
vertex_list = list(map(lambda v : v.get_vVal(), row[0]))
sort_vertex_list = sorted(vertex_list, key = functools.cmp_to_key(self.compare_vertex))
new_row.extend(sort_vertex_list)
edge_list = list(map(lambda e: e.get_eVal(), row[1]))
sort_edge_list = sorted(edge_list, key = functools.cmp_to_key(self.compare_edge))
new_row.extend(sort_edge_list)
else:
assert False, "Unsupport type : {}".format(type(row))
new_rows.append(new_row)
return new_rows
def check_subgraph_result(self, resp, expect):
if resp.data is None and len(expect) == 0:
return True
if resp.data is None:
return False, 'resp.data is None'
rows = resp.data.rows
msg = 'len(rows)[%d] != len(expect)[%d]' % (len(rows), len(expect))
assert len(rows) == len(expect), msg
if len(resp.data.column_names) == 1:
new_rows = self.sort_vertex_list(rows)
new_expect = self.sort_vertex_list(expect)
else:
new_rows = self.sort_vertex_edge_list(rows)
new_expect = self.sort_vertex_edge_list(expect)
for exp in new_expect:
find = False
for row in new_rows:
if row == exp:
find = True
new_rows.remove(row)
break
assert find, 'Can not find {}'.format(exp)
assert len(new_rows) == 0
@classmethod
def check_path_result_without_prop(self, rows, expect):
msg = 'len(rows)[%d] != len(expect)[%d]' % (len(rows), len(expect))
......
......@@ -11,9 +11,9 @@ import pytest
class TestSubGraph(NebulaTestSuite):
@classmethod
def prepare(self):
self.use_nba()
self.load_vertex_edge()
def prepare(cls):
cls.use_nba()
cls.load_vertex_edge()
def cleanup():
pass
......@@ -65,14 +65,14 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = 'GET SUBGRAPH 0 STEPS FROM "Tim Duncan", "Spurs"'
resp = self.execute_query(stmt)
self.check_resp_succeeded(resp)
vertices = [
VERTEXS['Tim Duncan'],
VERTEXS['Spurs'],
VERTEXS['Tim Duncan']
]
expected_data = {
"column_names" : ['_vertices'],
......@@ -81,15 +81,15 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = 'GET SUBGRAPH 0 STEPS FROM "Tim Duncan", "Tony Parker", "Spurs"'
resp = self.execute_query(stmt)
self.check_resp_succeeded(resp)
vertices = [
VERTEXS['Tony Parker'],
VERTEXS['Spurs'],
VERTEXS['Tim Duncan'],
VERTEXS['Tony Parker'],
]
expected_data = {
"column_names" : ['_vertices'],
......@@ -98,7 +98,7 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = "GO FROM 'Tim Duncan' over serve YIELD serve._dst AS id | GET SUBGRAPH 0 STEPS FROM $-.id"
resp = self.execute_query(stmt)
......@@ -114,7 +114,7 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = "GO FROM 'Tim Duncan' over like YIELD like._dst AS id | GET SUBGRAPH 0 STEPS FROM $-.id"
resp = self.execute_query(stmt)
......@@ -131,7 +131,7 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = '''$a = GO FROM 'Tim Duncan' over serve YIELD serve._dst AS id;
GET SUBGRAPH 0 STEPS FROM $a.id'''
......@@ -148,7 +148,7 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = '''$a = GO FROM 'Tim Duncan' over like YIELD like._dst AS id;
GET SUBGRAPH 0 STEPS FROM $a.id'''
......@@ -166,7 +166,7 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
def test_subgraph(self):
VERTEXS = self.VERTEXS
......@@ -215,10 +215,6 @@ class TestSubGraph(NebulaTestSuite):
]
edge2 = [
EDGES['Dejounte Murray'+'Danny Green'+'like'+'0'],
EDGES['Marco Belinelli'+'Danny Green'+'like'+'0'],
EDGES['Danny Green'+'Marco Belinelli'+'like'+'0'],
EDGES['Danny Green'+'Spurs'+'serve'+'0'],
EDGES['Tony Parker'+'Manu Ginobili'+'teammate'+'0'],
EDGES['Dejounte Murray'+'Manu Ginobili'+'like'+'0'],
EDGES['Tiago Splitter'+'Manu Ginobili'+'like'+'0'],
......@@ -239,7 +235,11 @@ class TestSubGraph(NebulaTestSuite):
EDGES['Marco Belinelli'+'Spurs'+'serve'+'0'],
EDGES['Tiago Splitter'+'Spurs'+'serve'+'0'],
EDGES['Marco Belinelli'+'Spurs'+'serve'+'1'],
EDGES['Dejounte Murray'+'Marco Belinelli'+'like'+'0']
EDGES['Dejounte Murray'+'Marco Belinelli'+'like'+'0'],
EDGES['Dejounte Murray'+'Danny Green'+'like'+'0'],
EDGES['Marco Belinelli'+'Danny Green'+'like'+'0'],
EDGES['Danny Green'+'Marco Belinelli'+'like'+'0'],
EDGES['Danny Green'+'Spurs'+'serve'+'0'],
]
expected_data = {
......@@ -250,7 +250,7 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = "GET SUBGRAPH 2 STEPS FROM 'Tim Duncan'"
resp = self.execute_query(stmt)
......@@ -453,7 +453,7 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = "GET SUBGRAPH 2 STEPS FROM 'Tim Duncan' IN like, serve"
resp = self.execute_query(stmt)
......@@ -533,7 +533,7 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = "GET SUBGRAPH 2 STEPS FROM 'Tim Duncan' IN like OUT serve"
resp = self.execute_query(stmt)
......@@ -686,7 +686,7 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = "GET SUBGRAPH 2 STEPS FROM 'Tim Duncan', 'James Harden' IN teammate OUT serve"
resp = self.execute_query(stmt)
......@@ -741,7 +741,7 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = "GET SUBGRAPH 3 STEPS FROM 'Paul George' OUT serve BOTH like"
resp = self.execute_query(stmt)
......@@ -846,7 +846,7 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = "GET SUBGRAPH FROM 'Tony Parker' BOTH like"
resp = self.execute_query(stmt)
......@@ -902,7 +902,7 @@ class TestSubGraph(NebulaTestSuite):
]
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = "GO FROM 'Tim Duncan' over serve YIELD serve._src AS id | GET SUBGRAPH FROM $-.id"
resp = self.execute_query(stmt)
......@@ -983,7 +983,7 @@ class TestSubGraph(NebulaTestSuite):
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
self.check_subgraph_result(resp, expected_data["rows"])
stmt = '''$a = GO FROM 'Tim Duncan' over serve YIELD serve._src AS id;
GET SUBGRAPH FROM $a.id'''
......@@ -1065,4 +1065,4 @@ class TestSubGraph(NebulaTestSuite):
}
self.check_column_names(resp, expected_data["column_names"])
self.check_out_of_order_result(resp, expected_data["rows"])
\ No newline at end of file
self.check_subgraph_result(resp, expected_data["rows"])
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment