Skip to content

Commit

Permalink
Merge pull request #164 from cwida/issue/163-0-edge-graph-is-treated-…
Browse files Browse the repository at this point in the history
…the-same-as-no-graph

Allow path finding on edgeless graphs
  • Loading branch information
Dtenwolde authored Nov 14, 2024
2 parents 3d89b42 + fafbef9 commit 1500f5c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/functions/scalar/iterativelength.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static void IterativeLengthFunction(DataChunk &args, ExpressionState &state,
"Need to initialize CSR before doing shortest path");
}

if (!(csr_entry->second->initialized_v && csr_entry->second->initialized_e)) {
if (!csr_entry->second->initialized_v) {
throw ConstraintException(
"Need to initialize CSR before doing shortest path");
}
Expand Down
18 changes: 15 additions & 3 deletions src/core/functions/scalar/shortest_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,24 @@ static void ShortestPathFunction(DataChunk &args, ExpressionState &state,
auto duckpgq_state = GetDuckPGQState(info.context);

D_ASSERT(duckpgq_state->csr_list[info.csr_id]);
auto csr_entry = duckpgq_state->csr_list.find(info.csr_id);
if (csr_entry == duckpgq_state->csr_list.end()) {
throw ConstraintException("Invalid ID");
}
auto &csr = csr_entry->second;


if (!csr->initialized_v) {
throw ConstraintException(
"Need to initialize CSR before doing shortest path");
}

int32_t id = args.data[0].GetValue(0).GetValue<int32_t>();
int64_t v_size = args.data[1].GetValue(0).GetValue<int64_t>();

int64_t *v = (int64_t *)duckpgq_state->csr_list[id]->v;
vector<int64_t> &e = duckpgq_state->csr_list[id]->e;
vector<int64_t> &edge_ids = duckpgq_state->csr_list[id]->edge_ids;
auto *v = (int64_t *)csr->v;
vector<int64_t> &e = csr->e;
vector<int64_t> &edge_ids = csr->edge_ids;

auto &src = args.data[2];
auto &target = args.data[3];
Expand Down
32 changes: 32 additions & 0 deletions test/sql/path_finding/edgeless_graph.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

require duckpgq

statement ok
CREATE TABLE nodes (id INTEGER);

statement ok
CREATE TABLE edges (src INTEGER, dst INTEGER);

statement ok
INSERT INTO nodes VALUES (1), (2), (3);

statement ok
-CREATE PROPERTY GRAPH testgraph
VERTEX TABLES (
nodes LABEL N
)
EDGE TABLES (
edges SOURCE KEY (src) REFERENCES nodes (id)
DESTINATION KEY (dst) REFERENCES nodes (id)
LABEL E
);

query IIIII
-FROM GRAPH_TABLE(testgraph
MATCH p = ANY SHORTEST (n1:N)-[e:E]-> * (n2:N)
COLUMNS (n1.id, n2.id, element_id(p), edges(p) AS path_edges, path_length(p))
);
----
1 1 [0] [] 0
2 2 [1] [] 0
3 3 [2] [] 0

0 comments on commit 1500f5c

Please sign in to comment.