diff --git a/duckdb-pgq b/duckdb-pgq index 253edcef..f484fe08 160000 --- a/duckdb-pgq +++ b/duckdb-pgq @@ -1 +1 @@ -Subproject commit 253edcefd9283c4aa11ab7442971d0c81c29a8e0 +Subproject commit f484fe0899e67fc29b6aec7ef1734925dca7ef45 diff --git a/duckpgq/include/duckpgq/functions/tablefunctions/match.hpp b/duckpgq/include/duckpgq/functions/tablefunctions/match.hpp index 4063df22..3576bc00 100644 --- a/duckpgq/include/duckpgq/functions/tablefunctions/match.hpp +++ b/duckpgq/include/duckpgq/functions/tablefunctions/match.hpp @@ -15,9 +15,9 @@ namespace duckdb { -struct MatchFunction : public TableFunction { +struct PGQMatchFunction : public TableFunction { public: - MatchFunction() { + PGQMatchFunction() { name = "duckpgq_match"; bind_replace = MatchBindReplace; } diff --git a/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp b/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp index 85994d28..6c219f19 100644 --- a/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp +++ b/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp @@ -94,6 +94,9 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind( CheckPropertyGraphTableLabels(vertex_table, table); v_table_names.insert(vertex_table->table_name); + if (vertex_table->hasTableNameAlias()) { + v_table_names.insert(vertex_table->table_name_alias); + } } for (auto &edge_table : info->edge_tables) { diff --git a/duckpgq/src/duckpgq/functions/tablefunctions/match.cpp b/duckpgq/src/duckpgq/functions/tablefunctions/match.cpp index bec85208..49494c6c 100644 --- a/duckpgq/src/duckpgq/functions/tablefunctions/match.cpp +++ b/duckpgq/src/duckpgq/functions/tablefunctions/match.cpp @@ -28,7 +28,7 @@ namespace duckdb { shared_ptr -MatchFunction::FindGraphTable(const string &label, +PGQMatchFunction::FindGraphTable(const string &label, CreatePropertyGraphInfo &pg_table) { auto graph_table_entry = pg_table.label_map.find(label); if (graph_table_entry == pg_table.label_map.end()) { @@ -39,7 +39,7 @@ MatchFunction::FindGraphTable(const string &label, return graph_table_entry->second; } -void MatchFunction::CheckInheritance( +void PGQMatchFunction::CheckInheritance( shared_ptr &tableref, PathElement *element, vector> &conditions) { if (tableref->main_label == element->label) { @@ -79,7 +79,7 @@ void MatchFunction::CheckInheritance( conditions.push_back(std::move(subset_compare)); } -void MatchFunction::CheckEdgeTableConstraints( +void PGQMatchFunction::CheckEdgeTableConstraints( const string &src_reference, const string &dst_reference, const shared_ptr &edge_table) { if (src_reference != edge_table->source_reference) { @@ -94,7 +94,7 @@ void MatchFunction::CheckEdgeTableConstraints( } } -unique_ptr MatchFunction::CreateMatchJoinExpression( +unique_ptr PGQMatchFunction::CreateMatchJoinExpression( vector vertex_keys, vector edge_keys, const string &vertex_alias, const string &edge_alias) { vector> conditions; @@ -125,7 +125,7 @@ unique_ptr MatchFunction::CreateMatchJoinExpression( return where_clause; } -PathElement *MatchFunction::GetPathElement( +PathElement *PGQMatchFunction::GetPathElement( unique_ptr &path_reference, vector> &conditions) { if (path_reference->path_reference_type == @@ -151,7 +151,7 @@ PathElement *MatchFunction::GetPathElement( } unique_ptr -MatchFunction::GetCountTable(const shared_ptr &edge_table, +PGQMatchFunction::GetCountTable(const shared_ptr &edge_table, const string &prev_binding) { // SELECT count(s.id) FROM src s auto select_count = make_uniq(); @@ -176,7 +176,7 @@ MatchFunction::GetCountTable(const shared_ptr &edge_table, } unique_ptr -MatchFunction::GetJoinRef(const shared_ptr &edge_table, +PGQMatchFunction::GetJoinRef(const shared_ptr &edge_table, const string &edge_binding, const string &prev_binding, const string &next_binding) { @@ -217,7 +217,7 @@ MatchFunction::GetJoinRef(const shared_ptr &edge_table, return first_join_ref; } -unique_ptr MatchFunction::CreateCountCTESubquery() { +unique_ptr PGQMatchFunction::CreateCountCTESubquery() { //! BEGIN OF (SELECT count(cte1.temp) as temp * 0 from cte1) __x auto temp_cte_select_node = make_uniq(); @@ -252,7 +252,7 @@ unique_ptr MatchFunction::CreateCountCTESubquery() { } unique_ptr -MatchFunction::CreateCSRCTE(const shared_ptr &edge_table, +PGQMatchFunction::CreateCSRCTE(const shared_ptr &edge_table, const string &edge_binding, const string &prev_binding, const string &next_binding) { @@ -375,37 +375,42 @@ MatchFunction::CreateCSRCTE(const shared_ptr &edge_table, return info; } -void MatchFunction::EdgeTypeAny( +void PGQMatchFunction::EdgeTypeAny( shared_ptr &edge_table, const string &edge_binding, const string &prev_binding, const string &next_binding, vector> &conditions) { + // (a) src.key = edge.src auto src_left_expr = CreateMatchJoinExpression( - edge_table->source_pk, edge_table->source_fk, prev_binding, edge_binding); - auto dst_left_expr = CreateMatchJoinExpression(edge_table->destination_pk, - edge_table->destination_fk, - next_binding, edge_binding); - + edge_table->source_pk, edge_table->source_fk, + prev_binding, edge_binding); + // (b) dst.key = edge.dst + auto dst_left_expr = CreateMatchJoinExpression( + edge_table->destination_pk,edge_table->destination_fk, + next_binding, edge_binding); + // (a) AND (b) auto combined_left_expr = make_uniq( ExpressionType::CONJUNCTION_AND, std::move(src_left_expr), std::move(dst_left_expr)); - + // (c) src.key = edge.dst auto src_right_expr = CreateMatchJoinExpression(edge_table->source_pk, edge_table->destination_fk, prev_binding, edge_binding); + // (d) dst.key = edge.src auto dst_right_expr = CreateMatchJoinExpression(edge_table->destination_pk, edge_table->source_fk, next_binding, edge_binding); + // (c) AND (d) auto combined_right_expr = make_uniq( ExpressionType::CONJUNCTION_AND, std::move(src_right_expr), std::move(dst_right_expr)); - + // ((a) AND (b)) OR ((c) AND (d)) auto combined_expr = make_uniq( ExpressionType::CONJUNCTION_OR, std::move(combined_left_expr), std::move(combined_right_expr)); conditions.push_back(std::move(combined_expr)); } -void MatchFunction::EdgeTypeLeft( +void PGQMatchFunction::EdgeTypeLeft( shared_ptr &edge_table, const string &next_table_name, const string &prev_table_name, const string &edge_binding, const string &prev_binding, const string &next_binding, @@ -419,7 +424,7 @@ void MatchFunction::EdgeTypeLeft( prev_binding, edge_binding)); } -void MatchFunction::EdgeTypeRight( +void PGQMatchFunction::EdgeTypeRight( shared_ptr &edge_table, const string &next_table_name, const string &prev_table_name, const string &edge_binding, const string &prev_binding, const string &next_binding, @@ -433,7 +438,7 @@ void MatchFunction::EdgeTypeRight( next_binding, edge_binding)); } -void MatchFunction::EdgeTypeLeftRight( +void PGQMatchFunction::EdgeTypeLeftRight( shared_ptr &edge_table, const string &edge_binding, const string &prev_binding, const string &next_binding, vector> &conditions, @@ -470,7 +475,7 @@ void MatchFunction::EdgeTypeLeftRight( conditions.push_back(std::move(combined_expr)); } -PathElement *MatchFunction::HandleNestedSubPath( +PathElement *PGQMatchFunction::HandleNestedSubPath( unique_ptr &path_reference, vector> &conditions, idx_t element_idx) { auto subpath = reinterpret_cast(path_reference.get()); @@ -492,7 +497,7 @@ CreateWhereClause(vector> &conditions) { return where_clause; } -unique_ptr MatchFunction::CreatePathFindingFunction( +unique_ptr PGQMatchFunction::CreatePathFindingFunction( const string &prev_binding, const string &next_binding, shared_ptr &edge_table, const string &path_finding_udf) { @@ -511,9 +516,9 @@ unique_ptr MatchFunction::CreatePathFindingFunction( std::move(pathfinding_children)); } -unique_ptr MatchFunction::MatchBindReplace(ClientContext &context, +unique_ptr PGQMatchFunction::MatchBindReplace(ClientContext &context, TableFunctionBindInput &) { - auto data = make_uniq(); + auto data = make_uniq(); auto duckpgq_state_entry = context.registered_state.find("duckpgq"); auto duckpgq_state = (DuckPGQState *)duckpgq_state_entry->second.get(); @@ -821,7 +826,7 @@ unique_ptr MatchFunction::MatchBindReplace(ClientContext &context, return std::move(result); } -unique_ptr MatchFunction::GenerateSubpathPatternSubquery( +unique_ptr PGQMatchFunction::GenerateSubpathPatternSubquery( unique_ptr &path_pattern, CreatePropertyGraphInfo *pg_table, vector> &column_list, unordered_set &named_subpaths) { diff --git a/duckpgq/src/duckpgq_extension.cpp b/duckpgq/src/duckpgq_extension.cpp index 3d5622aa..5cc1404d 100644 --- a/duckpgq/src/duckpgq_extension.cpp +++ b/duckpgq/src/duckpgq_extension.cpp @@ -27,7 +27,6 @@ inline void DuckpgqScalarFun(DataChunk &args, ExpressionState &state, name_vector, result, args.size(), [&](string_t name) { return StringVector::AddString(result, "Duckpgq " + name.GetString() + " 🐥"); - ; }); } @@ -42,7 +41,7 @@ static void LoadInternal(DatabaseInstance &instance) { auto &catalog = Catalog::GetSystemCatalog(*con.context); - MatchFunction match_pg_function; + PGQMatchFunction match_pg_function; CreateTableFunctionInfo match_pg_info(match_pg_function); catalog.CreateTableFunction(*con.context, match_pg_info); diff --git a/test/sql/create_pg/create_property_graph.test b/test/sql/create_pg/create_property_graph.test index 13a000d4..cdf09fc6 100644 --- a/test/sql/create_pg/create_property_graph.test +++ b/test/sql/create_pg/create_property_graph.test @@ -21,7 +21,7 @@ INSERT INTO Student VALUES (0, 'Daniel'), (1, 'Tavneet'), (2, 'Gabor'), (3, 'Pet statement ok INSERT INTO know VALUES (0,1, 10), (0,2, 11), (0,3, 12), (1,2, 14), (1,3, 15), (2,3, 16); -# vertex table with alias +# Vertex table with alias statement ok -CREATE PROPERTY GRAPH pg VERTEX TABLES ( diff --git a/test/sql/duckpgq.test b/test/sql/duckpgq.test index 107aa330..35f8db76 100644 --- a/test/sql/duckpgq.test +++ b/test/sql/duckpgq.test @@ -17,7 +17,7 @@ SELECT duckpgq('Sam'); ---- Duckpgq Sam 🐥 -query I -SELECT duckpgq_openssl_version('Michael'); ----- -:Duckpgq Michael, my linked OpenSSL version is OpenSSL.* \ No newline at end of file +#query I +#SELECT duckpgq_openssl_version('Michael'); +#---- +#:Duckpgq Michael, my linked OpenSSL version is OpenSSL.* \ No newline at end of file diff --git a/test/sql/explain_duckpgq.test b/test/sql/explain_duckpgq.test index 842b26bb..957016bd 100644 --- a/test/sql/explain_duckpgq.test +++ b/test/sql/explain_duckpgq.test @@ -7,10 +7,13 @@ statement ok import database 'duckdb-pgq/data/SNB0.003' #IC 2 -statement ok +# EXPLAIN queries are not yet supported (https://github.com/cwida/duckpgq-extension/issues/61) +statement error -EXPLAIN FROM GRAPH_TABLE (snb MATCH (a:Person WHERE a.id = 17592186044461)-[k:knows]-(b:Person)<-[au:hasAuthor]-(m:message WHERE m.creationDate < '2010-10-16') COLUMNS (a.id, a.firstName, a.lastName, m.id as messageId, coalesce(m.imageFile, m.content), m.creationDate) ) tmp ORDER BY creationDate DESC, Messageid ASC LIMIT 20 +---- +Binder Error: Unknown DuckPGQ query encountered diff --git a/test/sql/path-finding/shortest_path.test b/test/sql/path-finding/shortest_path.test index 730a368a..ce6035f6 100644 --- a/test/sql/path-finding/shortest_path.test +++ b/test/sql/path-finding/shortest_path.test @@ -59,24 +59,25 @@ query IIII MATCH p = ANY SHORTEST (a:Person)-[k:knows]->{1,3}(b:Person) COLUMNS (path_length(p), p, a.name as name, b.name as b_name) - ) study; + ) study + order by study.name, study.b_name; ---- -1 [0, 0, 1] Daniel Tavneet 1 [0, 1, 2] Daniel Gabor 1 [0, 2, 3] Daniel Peter -2 [1, 5, 3, 3, 0] Tavneet Daniel -1 [1, 4, 2] Tavneet Gabor -1 [1, 5, 3] Tavneet Peter +1 [0, 0, 1] Daniel Tavneet +2 [4, 7, 3, 3, 0] David Daniel +3 [4, 7, 3, 3, 0, 1, 2] David Gabor +1 [4, 7, 3] David Peter +3 [4, 7, 3, 3, 0, 0, 1] David Tavneet 2 [2, 6, 3, 3, 0] Gabor Daniel -3 [2, 6, 3, 3, 0, 0, 1] Gabor Tavneet 1 [2, 6, 3] Gabor Peter +3 [2, 6, 3, 3, 0, 0, 1] Gabor Tavneet 1 [3, 3, 0] Peter Daniel -2 [3, 3, 0, 0, 1] Peter Tavneet 2 [3, 3, 0, 1, 2] Peter Gabor -2 [4, 7, 3, 3, 0] David Daniel -3 [4, 7, 3, 3, 0, 0, 1] David Tavneet -3 [4, 7, 3, 3, 0, 1, 2] David Gabor -1 [4, 7, 3] David Peter +2 [3, 3, 0, 0, 1] Peter Tavneet +2 [1, 5, 3, 3, 0] Tavneet Daniel +1 [1, 4, 2] Tavneet Gabor +1 [1, 5, 3] Tavneet Peter statement error diff --git a/test/sql/pattern-matching/basic_match.test b/test/sql/pattern-matching/basic_match.test index fa18f002..d9b6601e 100644 --- a/test/sql/pattern-matching/basic_match.test +++ b/test/sql/pattern-matching/basic_match.test @@ -132,19 +132,21 @@ Peter Tavneet Peter Gabor Peter David -query II --SELECT study.a_name, study.b_name -FROM GRAPH_TABLE (pg - MATCH - (a:Person)-[k:Knows]-(b:Person) - WHERE a.name = 'Peter' - COLUMNS (a.name as a_name, b.name as b_name) - ) study; ----- -Peter Daniel -Peter Tavneet -Peter Gabor -Peter David +# Disabled, see https://github.com/cwida/duckpgq-extension/issues/60 +#query II +#-SELECT study.a_name, study.b_name +#FROM GRAPH_TABLE (pg +# MATCH +# (a:Person)-[k:Knows]-(b:Person) +# WHERE a.name = 'Peter' +# COLUMNS (a.name as a_name, b.name as b_name) +# ) study +# ORDER BY a_name, b_name; +#---- +#Peter Daniel +#Peter David +#Peter Gabor +#Peter Tavneet query II -SELECT study.a_name, study.b_name @@ -165,13 +167,13 @@ FROM GRAPH_TABLE (pg COLUMNS (a.name as a_name, b.name as b_name) ) study GROUP BY study.a_name - ORDER BY count(study.b_name) DESC; + ORDER BY count(study.b_name) DESC, study.a_name; ---- Daniel 3 Tavneet 2 -Peter 1 -Gabor 1 David 1 +Gabor 1 +Peter 1 query III -SELECT study.a_name, study.b_name, study.c_name diff --git a/test/sql/snb/snb.test b/test/sql/snb/snb.test index e7294d12..de45a93e 100644 --- a/test/sql/snb/snb.test +++ b/test/sql/snb/snb.test @@ -174,5 +174,5 @@ query IIIII COLUMNS (c.id,c.content,c.creationDate, replyAuthor.id % 10, replyAuthor.firstName || replyAuthor.lastName) ) tmp; ---- -962072674306 thanks 2012-07-08 20:32:03.239+00 24189255811081 AlimGuliyev -962072674305 yes 2012-07-08 23:48:41.63+00 24189255811081 AlimGuliyev \ No newline at end of file +962072674305 yes 2012-07-08 23:48:41.63+00 1 AlimGuliyev +962072674306 thanks 2012-07-08 20:32:03.239+00 1 AlimGuliyev