Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into pathfindingoperator
Browse files Browse the repository at this point in the history
  • Loading branch information
Dtenwolde committed Mar 20, 2024
2 parents 737db39 + 4212f63 commit d6c801b
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 28 deletions.
2 changes: 1 addition & 1 deletion duckdb-pgq
Submodule duckdb-pgq updated 1256 files
4 changes: 2 additions & 2 deletions duckpgq/src/duckpgq/functions/scalar/cheapest_path_length.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool UpdateLanes(vector<vector<T>> &dists, T v, T n, T weight) {
template <typename T, int16_t lane_limit>
int16_t
TemplatedBatchBellmanFord(CSR *csr, DataChunk &args, int64_t input_size,
UnifiedVectorFormat vdata_src, int64_t *src_data,
UnifiedVectorFormat &vdata_src, int64_t *src_data,
const UnifiedVectorFormat &vdata_target,
int64_t *target_data, std::vector<T> weight_array,
int16_t result_size, T *result_data,
Expand Down Expand Up @@ -94,7 +94,7 @@ TemplatedBatchBellmanFord(CSR *csr, DataChunk &args, int64_t input_size,

template <typename T>
void TemplatedBellmanFord(CSR *csr, DataChunk &args, int64_t input_size,
Vector &result, UnifiedVectorFormat vdata_src,
Vector &result, UnifiedVectorFormat &vdata_src,
int64_t *src_data,
const UnifiedVectorFormat &vdata_target,
int64_t *target_data, std::vector<T> weight_array) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind(
auto pg_table =
duckpgq_state->registered_property_graphs.find(info->property_graph_name);

if (pg_table != duckpgq_state->registered_property_graphs.end()) {
if (pg_table != duckpgq_state->registered_property_graphs.end() &&
info->on_conflict == OnCreateConflict::ERROR_ON_CONFLICT) {
throw Exception(ExceptionType::INVALID, "Property graph table with name " + info->property_graph_name + " already exists");
}

Expand Down Expand Up @@ -163,13 +164,7 @@ void CreatePropertyGraphFunction::CreatePropertyGraphFunc(
throw Exception(ExceptionType::INVALID,"Registered DuckPGQ state not found");
}
auto duckpgq_state = (DuckPGQState *)lookup->second.get();
auto pg_lookup = duckpgq_state->registered_property_graphs.find(
pg_info->property_graph_name);
if (pg_lookup == duckpgq_state->registered_property_graphs.end()) {
duckpgq_state->registered_property_graphs[pg_info->property_graph_name] =
pg_info->Copy();
} else {
throw Exception(ExceptionType::INVALID,"A property graph with name " + pg_info->property_graph_name + " already exists.");
}
duckpgq_state->registered_property_graphs[pg_info->property_graph_name] =
pg_info->Copy();
}
}; // namespace duckdb
18 changes: 12 additions & 6 deletions test/python/duckpgq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@
import os
import pytest


# Get a fresh connection to DuckDB with the duckpgq extension binary loaded
@pytest.fixture
def duckdb_conn():
extension_binary = os.getenv('DUCKPGQ_EXTENSION_BINARY_PATH')
if (extension_binary == ''):
if extension_binary == '':
raise Exception('Please make sure the `DUCKPGQ_EXTENSION_BINARY_PATH` is set to run the python tests')
conn = duckdb.connect('', config={'allow_unsigned_extensions': 'true'})
conn.execute(f"load '{extension_binary}'")
return conn


def test_duckpgq(duckdb_conn):
duckdb_conn.execute("SELECT duckpgq('Sam') as value;");
duckdb_conn.execute("SELECT duckpgq('Sam') as value;")
res = duckdb_conn.fetchall()
assert(res[0][0] == "Duckpgq Sam 🐥");
assert (res[0][0] == "Duckpgq Sam 🐥");


def test_duckpgq_openssl_version_test(duckdb_conn):
duckdb_conn.execute("SELECT duckpgq_openssl_version('Michael');");
def test_property_graph(duckdb_conn):
duckdb_conn.execute("CREATE TABLE foo(i bigint)")
duckdb_conn.execute("INSERT INTO foo(i) VALUES (1)")
duckdb_conn.execute("-CREATE PROPERTY GRAPH t VERTEX TABLES (foo);")
duckdb_conn.execute("-FROM GRAPH_TABLE(t MATCH (f:foo))")
res = duckdb_conn.fetchall()
assert(res[0][0][0:51] == "Duckpgq Michael, my linked OpenSSL version is OpenSSL");
assert (res[0][0] == 1)
42 changes: 42 additions & 0 deletions test/sql/create_pg/create_or_replace_pg.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# name: test/sql/sqlpgq/snb.test
# group: [duckpgq]

require duckpgq

statement ok
import database 'duckdb-pgq/data/SNB0.003';

statement ok
-CREATE PROPERTY GRAPH snb
VERTEX TABLES (
Person LABEL Person
)
EDGE TABLES (
Person_knows_person SOURCE KEY (Person1Id) REFERENCES Person (id)
DESTINATION KEY (Person2Id) REFERENCES Person (id)
LABEL Knows
);

# Fails because University is not registered
statement error
-FROM GRAPH_TABLE(snb MATCH (a:Person)-[w:workAt_Organisation]->(u:University)) limit 10;
----
Binder Error: The label university is not registered in property graph snb

statement ok
-CREATE OR REPLACE PROPERTY GRAPH snb
VERTEX TABLES (
Person LABEL Person,
Organisation LABEL Organisation IN typemask(company, university)
)
EDGE TABLES (
Person_knows_person SOURCE KEY (Person1Id) REFERENCES Person (id)
DESTINATION KEY (Person2Id) REFERENCES Person (id)
LABEL Knows,
person_workAt_Organisation SOURCE KEY (PersonId) REFERENCES Person (id)
DESTINATION KEY (OrganisationId) REFERENCES Organisation (id)
LABEL workAt_Organisation
);

statement ok
-FROM GRAPH_TABLE(snb MATCH (a:Person)-[w:workAt_Organisation]->(u:University)) limit 10;
88 changes: 88 additions & 0 deletions test/sql/optional_columns.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# name: test/sql/sqlpgq/snb.test
# group: [duckpgq]

require duckpgq

statement ok
import database 'duckdb-pgq/data/SNB0.003'

statement ok
-CREATE PROPERTY GRAPH snb
VERTEX TABLES (
Person LABEL Person,
Organisation LABEL Organisation IN typemask(company, university)
)
EDGE TABLES (
Person_knows_person SOURCE KEY (Person1Id) REFERENCES Person (id)
DESTINATION KEY (Person2Id) REFERENCES Person (id)
LABEL Knows,
person_workAt_Organisation SOURCE KEY (PersonId) REFERENCES Person (id)
DESTINATION KEY (OrganisationId) REFERENCES Organisation (id)
LABEL workAt_Organisation
);

query IIIIIIIIIII
-FROM GRAPH_TABLE (snb MATCH (p:Person)) limit 1;
----
2010-01-03 23:10:31.499+00 14 Hossein Forouhar male 1984-03-11 77.245.239.11 Firefox 1166 fa;ku;en [email protected]

query I
-FROM GRAPH_TABLE (snb MATCH (p:Person) COLUMNS (p.id)) limit 10;
----
14
16
32
2199023255557
2199023255573
2199023255594
4398046511139
6597069766702
8796093022234
8796093022237

query I
-SELECT p_id FROM GRAPH_TABLE (snb MATCH (p:Person) COLUMNS (p.id as p_id,)) limit 10;
----
14
16
32
2199023255557
2199023255573
2199023255594
4398046511139
6597069766702
8796093022234
8796093022237

query I
-FROM GRAPH_TABLE (snb MATCH (p:Person) COLUMNS (p.id as p_id)) limit 10;
----
14
16
32
2199023255557
2199023255573
2199023255594
4398046511139
6597069766702
8796093022234
8796093022237

query II
-FROM GRAPH_TABLE (snb MATCH (p:Person) COLUMNS (p.id, p.firstname as first_name)) limit 10;
----
14 Hossein
16 Jan
32 Miguel
2199023255557 Eric
2199023255573 Arbaaz
2199023255594 Ali
4398046511139 Ayesha
6597069766702 Alejandro
8796093022234 Rahul
8796093022237 Lei

query I
-SELECT count(*) FROM GRAPH_TABLE (snb MATCH (p:Person)) GROUP BY ALL limit 10;
----
50
20 changes: 10 additions & 10 deletions test/sql/path-finding/subpath_match.test
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ EDGE TABLES (
PROPERTIES ( id ) LABEL Knows
);

#query II
#-SELECT study.a_id, study.name
#FROM GRAPH_TABLE (pg
# MATCH
# (a:Person WHERE a.id = 0)
# COLUMNS (a.id as a_id, a.name)
# ) study
#----
#0 Daniel
#
query II
-SELECT study.a_id, study.name
FROM GRAPH_TABLE (pg
MATCH
(a:Person WHERE a.id = 0)
COLUMNS (a.id as a_id, a.name)
) study
----
0 Daniel

#query II
#-SELECT study.a_id, study.b_id
#FROM GRAPH_TABLE (pg
Expand Down

0 comments on commit d6c801b

Please sign in to comment.