Skip to content

Commit

Permalink
fix(interactive): Fix some edge_expand queries (#4503)
Browse files Browse the repository at this point in the history
As titled.

Fix #4500
  • Loading branch information
zhanglei1949 authored Feb 20, 2025
1 parent b5735cd commit 4111956
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,57 @@ class EdgeExpand {
ctx.set_with_reshuffle(params.alias, builder.finish(), shuffle_offset);
return ctx;
} else {
LOG(FATAL) << "expand edge both";
auto& input_vertex_list = *input_vertex_list_ptr;
auto& props = graph.schema().get_edge_properties(
params.labels[0].src_label, params.labels[0].dst_label,
params.labels[0].edge_label);
auto src_label = params.labels[0].src_label;
auto dst_label = params.labels[0].dst_label;
auto edge_label = params.labels[0].edge_label;
PropertyType pt = PropertyType::kEmpty;
if (!props.empty()) {
pt = props[0];
}
if (props.size() > 1) {
pt = PropertyType::kRecordView;
}
BDSLEdgeColumnBuilder builder(params.labels[0], pt);

foreach_vertex(
input_vertex_list, [&](size_t index, label_t label, vid_t v) {
if (label == src_label) {
auto oe_iter =
graph.GetOutEdgeIterator(label, v, dst_label, edge_label);
while (oe_iter.IsValid()) {
auto nbr = oe_iter.GetNeighbor();
if (pred(params.labels[0], v, nbr, oe_iter.GetData(),
Direction::kOut, index)) {
assert(oe_iter.GetData().type == pt);
builder.push_back_opt(v, nbr, oe_iter.GetData(),
Direction::kOut);
shuffle_offset.push_back(index);
}
oe_iter.Next();
}
}
if (label == dst_label) {
auto ie_iter =
graph.GetInEdgeIterator(label, v, src_label, edge_label);
while (ie_iter.IsValid()) {
auto nbr = ie_iter.GetNeighbor();
if (pred(params.labels[0], nbr, v, ie_iter.GetData(),
Direction::kIn, index)) {
assert(ie_iter.GetData().type == pt);
builder.push_back_opt(nbr, v, ie_iter.GetData(),
Direction::kIn);
shuffle_offset.push_back(index);
}
ie_iter.Next();
}
}
});
ctx.set_with_reshuffle(params.alias, builder.finish(), shuffle_offset);
return ctx;
}
} else {
LOG(INFO) << "not hit, fallback";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ expand_edge_ep_se(const GraphReadInterface& graph, const SLVertexColumn& input,
}
++idx;
}
} else {
} else if (dir == Direction::kOut) {
CHECK(dir == Direction::kOut);
GraphReadInterface::graph_view_t<EDATA_T> view =
graph.GetOutgoingGraphView<EDATA_T>(input_label, nbr_label, edge_label);
Expand All @@ -1399,6 +1399,10 @@ expand_edge_ep_se(const GraphReadInterface& graph, const SLVertexColumn& input,
}
++idx;
}
} else {
// We will handle edge_expand with both direction outside this function, in
// EdgeExpand::expand_edge.
return std::make_pair(nullptr, std::vector<size_t>());
}

return std::make_pair(builder.finish(), std::move(offsets));
Expand All @@ -1416,10 +1420,11 @@ expand_edge_impl(const GraphReadInterface& graph, const SLVertexColumn& input,
if (dir == Direction::kOut) {
CHECK(triplet.src_label == input_label);
std::get<0>(label_dir) = triplet.dst_label;
} else {
CHECK(dir == Direction::kIn);
} else if (dir == Direction::kIn) {
CHECK(triplet.dst_label == input_label);
std::get<0>(label_dir) = triplet.src_label;
} else {
return std::make_pair(nullptr, std::vector<size_t>());
}
std::get<1>(label_dir) = triplet.edge_label;
std::get<2>(label_dir) = dir;
Expand Down
6 changes: 6 additions & 0 deletions flex/engines/graph_db/runtime/common/rt_any.cc
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,14 @@ bool RTAny::operator==(const RTAny& other) const {

if (type_ == RTAnyType::kI64Value) {
return value_.i64_val == other.value_.i64_val;
} else if (type_ == RTAnyType::kU64Value) {
return value_.u64_val == other.value_.u64_val;
} else if (type_ == RTAnyType::kI32Value) {
return value_.i32_val == other.value_.i32_val;
} else if (type_ == RTAnyType::kF64Value) {
return value_.f64_val == other.value_.f64_val;
} else if (type_ == RTAnyType::kBoolValue) {
return value_.b_val == other.value_.b_val;
} else if (type_ == RTAnyType::kStringValue) {
return value_.str_val == other.value_.str_val;
} else if (type_ == RTAnyType::kVertex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"MATCH(a)-[b]->(c) return b",
"MATCH(a)-[b]->(c) return c.id",
"MATCH(a)-[b]->(c) return count(c), c, c.id;",
"MATCH(a)-[e: knows { weight: 0.5 }]-(c) return e,a,c;",
"MATCH(a)<-[e: knows { weight: 0.5 }]-(c) return e,a,c;",
"MATCH(a)-[e: knows { weight: 0.5 }]->(c) return e,a,c;",
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,15 @@ public static QueryContext get_simple_match_query_19_test() {
+ " url=http://dbpedia.org/resource/Azerbaijan}]");
return new QueryContext(query, expected);
}

public static QueryContext get_simple_match_query_20_test() {
String query =
"MATCH(a)-[b: LIKES {creationDate: 1294619734295}]-(c) WITH a.id as aId, c.id as"
+ " cId return aId, cId ORDER BY aId ASC, cId ASC limit 5;";
List<String> expected =
Arrays.asList(
"Record<{aId: 933, cId: 412317087328}>",
"Record<{aId: 412317087328, cId: 933}>");
return new QueryContext(query, expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ record -> {
Assert.assertEquals(testQuery.getExpectedResult().toString(), properties.toString());
}

@Test
public void run_simple_match_20_test() {
assumeTrue("hiactor".equals(System.getenv("ENGINE_TYPE")));
QueryContext testQuery = SimpleMatchQueries.get_simple_match_query_20_test();
Result result = session.run(testQuery.getQuery());
Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString());
}

private static String fetchAllProperties(Record record) {
List<String> properties = new ArrayList<>();
record.keys()
Expand Down

0 comments on commit 4111956

Please sign in to comment.