Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path finding operator #135

Open
wants to merge 254 commits into
base: main
Choose a base branch
from
Open

Path finding operator #135

wants to merge 254 commits into from

Conversation

Dtenwolde
Copy link
Contributor

@Dtenwolde Dtenwolde commented Aug 15, 2024

This PR introduces the path-finding operator developed by Pingan Ren during his MSc thesis.

It doesn't work with the PGQ syntax yet but will be added in future commits.

The operator needs to be enabled with a SET command:
set experimental_path_finding_operator=true;
Getting the current setting's value:
SELECT current_setting('experimental_path_finding_operator');

This PR is limited to unquantified shortest path and path length queries with a * in PGQ.

An example that will trigger the operator:

CREATE TABLE pair(src BIGINT, dst BIGINT); INSERT INTO pair(src, dst) VALUES (0, 1), (1, 2), (2,0);
CREATE TABLE student(id INT); INSERT INTO student(id) VALUES (10), (20), (30), (40);
CREATE TABLE know(src INT, dst INT); INSERT INTO know(src, dst) VALUES (40, 20), (10,30), (10,10), (20,10), (30,10);

WITH shortestpath_cte as (
SELECT src, dst, shortestpathoperator(src, dst, 'pair') as path
FROM pair p
WHERE p.src between (SELECT CSR_OPERATOR(
                             (SELECT count(a.id) as v_size FROM Student a),
                             (SELECT count(k.src) as e_size from know k),
                               a.rowid,
                               c.rowid,
                               k.rowid,
                               t.cnt) FROM Know k
                                           JOIN student a on a.id = k.src
                                           JOIN student c on c.id = k.dst
                                           JOIN (SELECT count(k.src) cnt, a.rowid as a_rowid
                                                   FROM student a
                                                  LEFT JOIN know k ON k.src = a.id
                                                  GROUP BY a.rowid) t
                                              ON t.a_rowid = a.rowid) and p.dst)
 SELECT * FROM shortestpath_cte;

This PR also supports the PGQ syntax:

FROM GRAPH_TABLE (pg
	MATCH p = ANY SHORTEST (a:Person)-[k:Knows]-> *(b:Person) COLUMNS (element_id(p)));

This PR will only support ANY SHORTEST with * (shortest unbounded path patterns). A future PR will add support for shortest path with quantified path patterns and +.

# Conflicts:
#	src/core/functions/function_data/CMakeLists.txt
#	src/core/functions/scalar/CMakeLists.txt
#	src/core/functions/scalar/csr_creation.cpp
#	src/core/utils/compressed_sparse_row.cpp
#	src/include/duckpgq/core/functions/scalar.hpp
#	src/include/duckpgq/core/utils/compressed_sparse_row.hpp
#	src/include/duckpgq/core/utils/duckpgq_utils.hpp
@Dtenwolde Dtenwolde marked this pull request as ready for review September 6, 2024 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement PathFindingOperator
2 participants