diff --git a/duckdb b/duckdb index 6236d0b5..0c82f0ed 160000 --- a/duckdb +++ b/duckdb @@ -1 +1 @@ -Subproject commit 6236d0b555a3a6a400fcea2f024eaa245324dca1 +Subproject commit 0c82f0ed582ed2737216539845028826badb4bda diff --git a/src/core/functions/scalar/shortest_path.cpp b/src/core/functions/scalar/shortest_path.cpp index b70f35e9..669426a7 100644 --- a/src/core/functions/scalar/shortest_path.cpp +++ b/src/core/functions/scalar/shortest_path.cpp @@ -67,8 +67,6 @@ static void ShortestPathFunction(DataChunk &args, ExpressionState &state, throw ConstraintException( "Need to initialize CSR before doing shortest path"); } - - int32_t id = args.data[0].GetValue(0).GetValue(); int64_t v_size = args.data[1].GetValue(0).GetValue(); auto *v = (int64_t *)csr->v; diff --git a/src/core/functions/table/create_property_graph.cpp b/src/core/functions/table/create_property_graph.cpp index 1c36fae9..f156432b 100644 --- a/src/core/functions/table/create_property_graph.cpp +++ b/src/core/functions/table/create_property_graph.cpp @@ -169,21 +169,22 @@ unique_ptr CreatePropertyGraphFunction::CreatePropertyGraphBind( " already exists"); } - auto &catalog = Catalog::GetCatalog(context, info->catalog); case_insensitive_set_t v_table_names; for (auto &vertex_table : info->vertex_tables) { try { + auto &catalog = Catalog::GetCatalog(context, vertex_table->catalog_name); auto table = catalog.GetEntry( context, info->schema, vertex_table->table_name, OnEntryNotFound::RETURN_NULL); if (!table) { throw Exception(ExceptionType::INVALID, - "Table " + vertex_table->table_name + " not found"); + "Table " + vertex_table->schema_name + "." + vertex_table->table_name + " not found"); } CheckPropertyGraphTableColumns(vertex_table, *table); CheckPropertyGraphTableLabels(vertex_table, *table); } catch (CatalogException &e) { + auto &catalog = Catalog::GetCatalog(context, vertex_table->catalog_name); auto table = catalog.GetEntry(context, info->schema, vertex_table->table_name, OnEntryNotFound::RETURN_NULL); if (table) { throw Exception(ExceptionType::INVALID, "Found a view with name " + vertex_table->table_name + ". Creating property graph tables over views is currently not supported."); @@ -200,11 +201,13 @@ unique_ptr CreatePropertyGraphFunction::CreatePropertyGraphBind( for (auto &edge_table : info->edge_tables) { try { - auto table = catalog.GetEntry(context, info->schema, + auto &catalog = Catalog::GetCatalog(context, edge_table->catalog_name); + + auto table = catalog.GetEntry(context, edge_table->schema_name, edge_table->table_name, OnEntryNotFound::RETURN_NULL); if (!table) { throw Exception(ExceptionType::INVALID, - "Table " + edge_table->table_name + " not found"); + "Table " + edge_table->schema_name + "." + edge_table->table_name + " not found"); } CheckPropertyGraphTableColumns(edge_table, *table); @@ -237,6 +240,7 @@ unique_ptr CreatePropertyGraphFunction::CreatePropertyGraphBind( // Validate primary keys in the destination table ValidatePrimaryKeyInTable(catalog, context, info->schema, edge_table->destination_reference, edge_table->destination_pk); } catch (CatalogException &e) { + auto &catalog = Catalog::GetCatalog(context, edge_table->catalog_name); auto table = catalog.GetEntry(context, info->schema, edge_table->table_name, OnEntryNotFound::RETURN_NULL); if (table) { throw Exception(ExceptionType::INVALID, "Found a view with name " + edge_table->table_name + ". Creating property graph tables over views is currently not supported."); @@ -307,10 +311,12 @@ void CreatePropertyGraphFunction::CreatePropertyGraphFunc( for (idx_t i = 0; i < v_table->sub_labels.size(); i++) { insert_info += "'" + v_table->sub_labels[i] + (i == v_table->sub_labels.size() - 1 ? "'" : "', "); } - insert_info += "]"; + insert_info += "],"; } else { - insert_info += "NULL"; + insert_info += "NULL,"; } + insert_info += "'" + v_table->catalog_name + "', "; + insert_info += "'" + v_table->schema_name + "'"; insert_info += "), "; } @@ -350,10 +356,12 @@ void CreatePropertyGraphFunction::CreatePropertyGraphFunc( for (idx_t i = 0; i < e_table->sub_labels.size(); i++) { insert_info += "'" + e_table->sub_labels[i] + (i == e_table->sub_labels.size() - 1 ? "'" : "', "); } - insert_info += "]"; + insert_info += "], "; } else { - insert_info += "NULL"; + insert_info += "NULL, "; } + insert_info += "'" + e_table->catalog_name + "', "; + insert_info += "'" + e_table->schema_name + "'"; insert_info += "), "; } diff --git a/src/core/functions/table/local_clustering_coefficient.cpp b/src/core/functions/table/local_clustering_coefficient.cpp index 71c6850f..6eba3768 100644 --- a/src/core/functions/table/local_clustering_coefficient.cpp +++ b/src/core/functions/table/local_clustering_coefficient.cpp @@ -7,8 +7,6 @@ #include "duckdb/parser/expression/function_expression.hpp" #include "duckpgq/core/utils/compressed_sparse_row.hpp" #include -#include -#include #include #include diff --git a/src/core/functions/table/match.cpp b/src/core/functions/table/match.cpp index 812a76c3..52aac7bb 100644 --- a/src/core/functions/table/match.cpp +++ b/src/core/functions/table/match.cpp @@ -160,7 +160,7 @@ unique_ptr PGQMatchFunction::CreateCountCTESubquery() { auto count_function = make_uniq("count", std::move(children)); - auto zero = make_uniq(Value::INTEGER((int32_t)0)); + auto zero = make_uniq(Value::INTEGER(0)); vector> multiply_children; @@ -190,14 +190,13 @@ void PGQMatchFunction::EdgeTypeAny( // START SELECT src, dst, * from edge_table auto src_dst_select_node = make_uniq(); - auto edge_left_ref = make_uniq(); - edge_left_ref->table_name = edge_table->table_name; + auto edge_left_ref = edge_table->CreateBaseTableRef(edge_binding); src_dst_select_node->from_table = std::move(edge_left_ref); auto src_dst_children = vector>(); src_dst_children.push_back(make_uniq( - edge_table->source_fk[0], edge_table->table_name)); + edge_table->source_fk[0], edge_binding)); src_dst_children.push_back(make_uniq( - edge_table->destination_fk[0], edge_table->table_name)); + edge_table->destination_fk[0], edge_binding)); src_dst_children.push_back(make_uniq()); src_dst_select_node->select_list = std::move(src_dst_children); @@ -206,15 +205,14 @@ void PGQMatchFunction::EdgeTypeAny( // START SELECT dst, src, * from edge_table auto dst_src_select_node = make_uniq(); - auto edge_right_ref = make_uniq(); - edge_right_ref->table_name = edge_table->table_name; + auto edge_right_ref = edge_table->CreateBaseTableRef(edge_binding); auto dst_src_children = vector>(); dst_src_select_node->from_table = std::move(edge_right_ref); dst_src_children.push_back(make_uniq( - edge_table->destination_fk[0], edge_table->table_name)); + edge_table->destination_fk[0], edge_binding)); dst_src_children.push_back(make_uniq( - edge_table->source_fk[0], edge_table->table_name)); + edge_table->source_fk[0], edge_binding)); dst_src_children.push_back(make_uniq()); dst_src_select_node->select_list = std::move(dst_src_children); @@ -289,7 +287,7 @@ void PGQMatchFunction::EdgeTypeLeftRight( const string &edge_binding, const string &prev_binding, const string &next_binding, vector> &conditions, - unordered_map &alias_map, int32_t &extra_alias_counter) { + case_insensitive_map_t> &alias_map, int32_t &extra_alias_counter) { auto src_left_expr = CreateMatchJoinExpression( edge_table->source_pk, edge_table->source_fk, next_binding, edge_binding); auto dst_left_expr = CreateMatchJoinExpression(edge_table->destination_pk, @@ -304,7 +302,7 @@ void PGQMatchFunction::EdgeTypeLeftRight( edge_binding + std::to_string(extra_alias_counter); extra_alias_counter++; - alias_map[additional_edge_alias] = edge_table->table_name; + alias_map[additional_edge_alias] = edge_table; auto src_right_expr = CreateMatchJoinExpression(edge_table->source_pk, edge_table->source_fk, @@ -345,7 +343,7 @@ PGQMatchFunction::CreateWhereClause(vector> &condit } unique_ptr PGQMatchFunction::GenerateShortestPathCTE(CreatePropertyGraphInfo &pg_table, SubPath *edge_subpath, - PathElement * previous_vertex_element, PathElement * next_vertex_element, vector> &path_finding_conditions) { + PathElement *previous_vertex_element, PathElement * next_vertex_element, vector> &path_finding_conditions) { auto cte_info = make_uniq(); auto select_statement = make_uniq(); auto select_node = make_uniq(); @@ -362,7 +360,7 @@ unique_ptr PGQMatchFunction::GenerateShortestPathCTE( vector> pathfinding_children; pathfinding_children.push_back(std::move(csr_id)); pathfinding_children.push_back(std::move(GetCountTable( - edge_table->source_reference, previous_vertex_element->variable_binding, edge_table->source_pk[0]))); + edge_table->source_pg_table, previous_vertex_element->variable_binding, edge_table->source_pk[0]))); pathfinding_children.push_back(std::move(src_row_id)); pathfinding_children.push_back(std::move(dst_row_id)); @@ -377,11 +375,9 @@ unique_ptr PGQMatchFunction::GenerateShortestPathCTE( dst_rowid_outer_select->alias = "dst_rowid"; select_node->select_list.push_back(std::move(dst_rowid_outer_select)); - auto src_tableref = make_uniq(); - src_tableref->table_name = edge_table->source_reference; + auto src_tableref = edge_table->source_pg_table->CreateBaseTableRef(); src_tableref->alias = previous_vertex_element->variable_binding; - auto dst_tableref = make_uniq(); - dst_tableref->table_name = edge_table->destination_reference; + auto dst_tableref = edge_table->destination_pg_table->CreateBaseTableRef(); dst_tableref->alias = next_vertex_element->variable_binding; auto first_cross_join_ref = make_uniq(JoinRefType::CROSS); first_cross_join_ref->left = std::move(src_tableref); @@ -560,10 +556,10 @@ void PGQMatchFunction::AddEdgeJoins( PGQMatchType edge_type, const string &edge_binding, const string &prev_binding, const string &next_binding, vector> &conditions, - unordered_map &alias_map, int32_t &extra_alias_counter, + case_insensitive_map_t> &alias_map, int32_t &extra_alias_counter, unique_ptr &from_clause) { if (edge_type != PGQMatchType::MATCH_EDGE_ANY) { - alias_map[edge_binding] = edge_table->table_name; + alias_map[edge_binding] = edge_table; } switch (edge_type) { case PGQMatchType::MATCH_EDGE_ANY: { @@ -602,7 +598,7 @@ unique_ptr PGQMatchFunction::AddPathQuantifierCondition( vector> pathfinding_children; pathfinding_children.push_back(std::move(csr_id)); pathfinding_children.push_back( - std::move(GetCountTable(edge_table->source_reference, prev_binding, edge_table->source_pk[0]))); + std::move(GetCountTable(edge_table->source_pg_table, prev_binding, edge_table->source_pk[0]))); pathfinding_children.push_back(std::move(src_row_id)); pathfinding_children.push_back(std::move(dst_row_id)); @@ -773,7 +769,7 @@ void PGQMatchFunction::ProcessPathList( vector> &path_list, vector> &conditions, unique_ptr &final_select_node, - unordered_map &alias_map, CreatePropertyGraphInfo &pg_table, + case_insensitive_map_t> &alias_map, CreatePropertyGraphInfo &pg_table, int32_t &extra_alias_counter, MatchExpression &original_ref) { PathElement *previous_vertex_element = GetPathElement(path_list[0]); @@ -801,7 +797,7 @@ void PGQMatchFunction::ProcessPathList( FindGraphTable(previous_vertex_element->label, pg_table); CheckInheritance(previous_vertex_table, previous_vertex_element, conditions); alias_map[previous_vertex_element->variable_binding] = - previous_vertex_table->table_name; + previous_vertex_table; for (idx_t idx_j = 1; idx_j < path_list.size(); idx_j = idx_j + 2) { PathElement *next_vertex_element = GetPathElement(path_list[idx_j + 1]); @@ -824,8 +820,7 @@ void PGQMatchFunction::ProcessPathList( auto next_vertex_table = FindGraphTable(next_vertex_element->label, pg_table); CheckInheritance(next_vertex_table, next_vertex_element, conditions); - alias_map[next_vertex_element->variable_binding] = - next_vertex_table->table_name; + alias_map[next_vertex_element->variable_binding] = next_vertex_table; PathElement *edge_element = GetPathElement(path_list[idx_j]); if (!edge_element) { @@ -892,7 +887,7 @@ PGQMatchFunction::MatchBindReplace(ClientContext &context, vector> conditions; auto final_select_node = make_uniq(); - unordered_map alias_map; + case_insensitive_map_t> alias_map; int32_t extra_alias_counter = 0; for (idx_t idx_i = 0; idx_i < ref->path_patterns.size(); idx_i++) { @@ -906,10 +901,8 @@ PGQMatchFunction::MatchBindReplace(ClientContext &context, // Go through all aliases encountered for (auto &table_alias_entry : alias_map) { - auto table_ref = make_uniq(); - table_ref->table_name = table_alias_entry.second; + auto table_ref = table_alias_entry.second->CreateBaseTableRef(); table_ref->alias = table_alias_entry.first; - if (final_select_node->from_table) { auto new_root = make_uniq(JoinRefType::CROSS); new_root->left = std::move(final_select_node->from_table); diff --git a/src/core/utils/compressed_sparse_row.cpp b/src/core/utils/compressed_sparse_row.cpp index 0d5436c1..bea9d714 100644 --- a/src/core/utils/compressed_sparse_row.cpp +++ b/src/core/utils/compressed_sparse_row.cpp @@ -100,20 +100,13 @@ CSRFunctionData::CSRBind(ClientContext &context, ScalarFunction &bound_function, // Helper function to create a JoinRef -unique_ptr CreateJoin(const std::string &fk_column, const std::string &pk_column, const std::string &table_name, const std::string &source_reference) { +unique_ptr CreateJoin(const string &fk_column, const string &pk_column, + const shared_ptr &fk_table, const shared_ptr &pk_table) { auto join = make_uniq(JoinRefType::REGULAR); - - auto left_side = make_uniq(); - left_side->table_name = source_reference; - join->left = std::move(left_side); - - auto right_side = make_uniq(); - right_side->table_name = table_name; - join->right = std::move(right_side); - - join->type = JoinType::INNER; - join->condition = make_uniq(ExpressionType::COMPARE_EQUAL, make_uniq(fk_column, table_name), make_uniq(pk_column, source_reference)); - + join->left = fk_table->CreateBaseTableRef(); + join->right = pk_table->CreateBaseTableRef(); + join->condition = make_uniq(ExpressionType::COMPARE_EQUAL, + make_uniq(fk_column, fk_table->table_name), make_uniq(pk_column, pk_table->table_name)); return join; } @@ -127,23 +120,20 @@ void SetupSelectNode(unique_ptr &select_node, const shared_ptrselect_list.emplace_back(CreateColumnRefExpression(edge_table->source_fk[0], edge_table->table_name, "outgoing_edges")); select_node->select_list.emplace_back(CreateColumnRefExpression(edge_table->destination_fk[0], edge_table->table_name, "incoming_edges")); - select_node->from_table = CreateJoin(edge_table->source_fk[0], edge_table->source_pk[0], edge_table->table_name, edge_table->source_reference); + select_node->from_table = CreateJoin(edge_table->source_fk[0], edge_table->source_pk[0], edge_table, edge_table->source_pg_table); } else { select_node->select_list.emplace_back(CreateColumnRefExpression(edge_table->destination_fk[0], edge_table->table_name, "outgoing_edges")); select_node->select_list.emplace_back(CreateColumnRefExpression(edge_table->source_fk[0], edge_table->table_name, "incoming_edges")); - select_node->from_table = CreateJoin(edge_table->destination_fk[0], edge_table->source_pk[0], edge_table->table_name, edge_table->source_reference); + select_node->from_table = CreateJoin(edge_table->destination_fk[0], edge_table->source_pk[0], edge_table, edge_table->source_pg_table); } } // Function to create a subquery expression for counting table entries -unique_ptr GetCountTable(const string &table_name, const string &table_alias, const string &primary_key) { +unique_ptr GetCountTable(const shared_ptr &table, const string &table_alias, const string &primary_key) { auto select_count = make_uniq(); auto select_inner = make_uniq(); - auto ref = make_uniq(); - - ref->table_name = table_name; - ref->alias = table_alias; + auto ref = table->CreateBaseTableRef(table_alias); select_inner->from_table = std::move(ref); vector> children; @@ -170,14 +160,8 @@ GetJoinRef(const shared_ptr &edge_table, auto second_join_ref = make_uniq(JoinRefType::REGULAR); second_join_ref->type = JoinType::INNER; - auto edge_base_ref = make_uniq(); - edge_base_ref->table_name = edge_table->table_name; - edge_base_ref->alias = edge_binding; - auto src_base_ref = make_uniq(); - src_base_ref->table_name = edge_table->source_reference; - src_base_ref->alias = prev_binding; - second_join_ref->left = std::move(edge_base_ref); - second_join_ref->right = std::move(src_base_ref); + second_join_ref->left = edge_table->CreateBaseTableRef(edge_binding); + second_join_ref->right = edge_table->source_pg_table->CreateBaseTableRef(prev_binding); auto t_from_ref = make_uniq(edge_table->source_fk[0], edge_binding); auto src_cid_ref = @@ -185,11 +169,8 @@ GetJoinRef(const shared_ptr &edge_table, second_join_ref->condition = make_uniq( ExpressionType::COMPARE_EQUAL, std::move(t_from_ref), std::move(src_cid_ref)); - auto dst_base_ref = make_uniq(); - dst_base_ref->table_name = edge_table->destination_reference; - dst_base_ref->alias = next_binding; first_join_ref->left = std::move(second_join_ref); - first_join_ref->right = std::move(dst_base_ref); + first_join_ref->right = edge_table->destination_pg_table->CreateBaseTableRef(next_binding); auto t_to_ref = make_uniq(edge_table->destination_fk[0], edge_binding); @@ -201,8 +182,8 @@ GetJoinRef(const shared_ptr &edge_table, return first_join_ref; } -unique_ptr CreateDirectedCSRVertexSubquery(const shared_ptr &edge_table, const std::string &prev_binding) { - auto count_create_vertex_expr = GetCountTable(edge_table->source_reference, prev_binding, edge_table->source_pk[0]); +unique_ptr CreateDirectedCSRVertexSubquery(const shared_ptr &edge_table, const string &prev_binding) { + auto count_create_vertex_expr = GetCountTable(edge_table->source_pg_table, prev_binding, edge_table->source_pk[0]); vector> csr_vertex_children; csr_vertex_children.push_back(make_uniq(Value::INTEGER(0))); @@ -226,18 +207,10 @@ unique_ptr CreateDirectedCSRVertexSubquery(const shared_ptr< count_function->alias = "cnt"; inner_select_node->select_list.emplace_back(std::move(count_function)); - auto src_tableref = make_uniq(); - src_tableref->table_name = edge_table->source_reference; - src_tableref->alias = prev_binding; - - auto edge_tableref = make_uniq(); - edge_tableref->table_name = edge_table->table_name; - edge_tableref->alias = edge_table->table_name_alias; - auto left_join_ref = make_uniq(JoinRefType::REGULAR); left_join_ref->type = JoinType::LEFT; - left_join_ref->left = std::move(src_tableref); - left_join_ref->right = std::move(edge_tableref); + left_join_ref->left = edge_table->source_pg_table->CreateBaseTableRef(prev_binding); + left_join_ref->right = edge_table->CreateBaseTableRef(edge_table->table_name_alias); auto join_condition = make_uniq(ExpressionType::COMPARE_EQUAL, make_uniq(edge_table->source_fk[0], edge_table->table_name), @@ -269,8 +242,8 @@ unique_ptr CreateDirectedCSRVertexSubquery(const shared_ptr< } // Helper function to create CSR Vertex Subquery -unique_ptr CreateUndirectedCSRVertexSubquery(const shared_ptr &edge_table, const std::string &binding) { - auto count_create_vertex_expr = GetCountTable(edge_table->source_reference, binding, edge_table->source_pk[0]); +unique_ptr CreateUndirectedCSRVertexSubquery(const shared_ptr &edge_table, const string &binding) { + auto count_create_vertex_expr = GetCountTable(edge_table->source_pg_table, binding, edge_table->source_pk[0]); vector> csr_vertex_children; csr_vertex_children.push_back(make_uniq(Value::INTEGER(0))); @@ -392,32 +365,20 @@ unique_ptr MakeEdgesCTE(const shared_ptr(); select_node->select_list = std::move(select_expression); - auto edge_table_ref = make_uniq(); - edge_table_ref->table_name = edge_table->table_name; - - auto src_table_ref = make_uniq(); - src_table_ref->table_name = edge_table->source_reference; - src_table_ref->alias = "src_table"; - auto join_ref = make_uniq(JoinRefType::REGULAR); - auto first_join_ref = make_uniq(JoinRefType::REGULAR); first_join_ref->type = JoinType::INNER; - first_join_ref->left = std::move(edge_table_ref); - first_join_ref->right = std::move(src_table_ref); + first_join_ref->left = edge_table->CreateBaseTableRef(); + first_join_ref->right = edge_table->source_pg_table->CreateBaseTableRef("src_table"); auto edge_from_ref = make_uniq(edge_table->source_fk[0], edge_table->table_name); auto src_cid_ref = make_uniq(edge_table->source_pk[0], "src_table"); first_join_ref->condition = make_uniq(ExpressionType::COMPARE_EQUAL, std::move(edge_from_ref), std::move(src_cid_ref)); - auto dst_table_ref = make_uniq(); - dst_table_ref->table_name = edge_table->destination_reference; - dst_table_ref->alias = "dst_table"; - auto second_join_ref = make_uniq(JoinRefType::REGULAR); second_join_ref->type = JoinType::INNER; second_join_ref->left = std::move(first_join_ref); - second_join_ref->right = std::move(dst_table_ref); + second_join_ref->right = edge_table->destination_pg_table->CreateBaseTableRef("dst_table"); auto edge_to_ref = make_uniq(edge_table->destination_fk[0], edge_table->table_name); auto dst_cid_ref = make_uniq(edge_table->destination_pk[0], "dst_table"); @@ -442,7 +403,7 @@ unique_ptr CreateUndirectedCSRCTE(const shared_ptr(Value::INTEGER(0)); - auto count_create_edge_select = GetCountTable(edge_table->source_reference, edge_table->source_reference, edge_table->source_pk[0]); + auto count_create_edge_select = GetCountTable(edge_table->source_pg_table, edge_table->source_reference, edge_table->source_pk[0]); auto count_edges_subquery = GetCountUndirectedEdgeTable(); @@ -507,12 +468,12 @@ unique_ptr GetCountUndirectedEdgeTable() { auto count_edges_select_statement = make_uniq(); auto count_edges_select_node = make_uniq(); vector> count_children; - auto count_function = make_uniq(INVALID_CATALOG, INVALID_SCHEMA, "count", std::move(count_children)); + auto count_function = make_uniq("count", std::move(count_children)); vector> multiply_children; auto constant_two = make_uniq(Value::BIGINT(2)); multiply_children.push_back(std::move(constant_two)); multiply_children.push_back(std::move(count_function)); - auto multiply_function = make_uniq(INVALID_CATALOG, INVALID_SCHEMA, "multiply", std::move(multiply_children)); + auto multiply_function = make_uniq("multiply", std::move(multiply_children)); count_edges_select_node->select_list.emplace_back(std::move(multiply_function)); auto inner_select_statement = make_uniq(); @@ -548,18 +509,16 @@ unique_ptr GetCountEdgeTable(const shared_ptr(); auto outer_select_node = make_uniq(); vector> count_children; - outer_select_node->select_list.push_back(make_uniq(INVALID_CATALOG, INVALID_SCHEMA, "count", std::move(count_children))); + outer_select_node->select_list.push_back(make_uniq("count", std::move(count_children))); auto inner_select_node = make_uniq(); auto first_join = make_uniq(JoinRefType::REGULAR); - first_join->type = JoinType::INNER; - first_join->left = CreateBaseTableRef(edge_table->table_name); - first_join->right = CreateBaseTableRef(edge_table->source_reference, "src"); + first_join->left = edge_table->CreateBaseTableRef(); + first_join->right = edge_table->source_pg_table->CreateBaseTableRef("src"); first_join->condition = make_uniq(ExpressionType::COMPARE_EQUAL, make_uniq(edge_table->source_fk[0], edge_table->table_name), make_uniq(edge_table->source_pk[0], "src")); auto second_join = make_uniq(JoinRefType::REGULAR); - second_join->type = JoinType::INNER; second_join->left = std::move(first_join); - second_join->right = CreateBaseTableRef(edge_table->destination_reference, "dst"); + second_join->right = edge_table->destination_pg_table->CreateBaseTableRef("dst"); second_join->condition = make_uniq(ExpressionType::COMPARE_EQUAL, make_uniq(edge_table->destination_fk[0], edge_table->table_name), make_uniq(edge_table->destination_pk[0], "dst")); outer_select_node->from_table = std::move(second_join); outer_select_statement->node = std::move(outer_select_node); @@ -570,9 +529,9 @@ unique_ptr GetCountEdgeTable(const shared_ptr CreateDirectedCSRCTE(const shared_ptr &edge_table, const std::string &prev_binding, const std::string &edge_binding, const std::string &next_binding) { +unique_ptr CreateDirectedCSRCTE(const shared_ptr &edge_table, const string &prev_binding, const string &edge_binding, const string &next_binding) { auto csr_edge_id_constant = make_uniq(Value::INTEGER(0)); - auto count_create_edge_select = GetCountTable(edge_table->source_reference, prev_binding, edge_table->source_pk[0]); + auto count_create_edge_select = GetCountTable(edge_table->source_pg_table, prev_binding, edge_table->source_pk[0]); auto cast_subquery_expr = CreateDirectedCSRVertexSubquery(edge_table, prev_binding); auto count_edge_table = GetCountEdgeTable(edge_table); // Count the number of edges diff --git a/src/core/utils/duckpgq_utils.cpp b/src/core/utils/duckpgq_utils.cpp index 8ac55889..35f15fb8 100644 --- a/src/core/utils/duckpgq_utils.cpp +++ b/src/core/utils/duckpgq_utils.cpp @@ -33,11 +33,11 @@ CreatePropertyGraphInfo* GetPropertyGraphInfo(const shared_ptr &du // Function to validate the source node and edge table shared_ptr ValidateSourceNodeAndEdgeTable(CreatePropertyGraphInfo *pg_info, const std::string &node_label, const std::string &edge_label) { - auto source_node_pg_entry = pg_info->GetTable(node_label, true, true); + auto source_node_pg_entry = pg_info->GetTableByLabel(node_label, true, true); if (!source_node_pg_entry->is_vertex_table) { throw Exception(ExceptionType::INVALID, node_label + " is an edge table, expected a vertex table"); } - auto edge_pg_entry = pg_info->GetTable(edge_label, true, false); + auto edge_pg_entry = pg_info->GetTableByLabel(edge_label, true, false); if (edge_pg_entry->is_vertex_table) { throw Exception(ExceptionType::INVALID, edge_label + " is a vertex table, expected an edge table"); } @@ -70,8 +70,7 @@ unique_ptr CreateSelectNode(const shared_ptr &ed select_expression.emplace_back(std::move(addition_function)); select_node->select_list = std::move(select_expression); - auto src_base_ref = make_uniq(); - src_base_ref->table_name = edge_pg_entry->source_reference; + auto src_base_ref = edge_pg_entry->source_pg_table->CreateBaseTableRef(); auto temp_cte_select_subquery = CreateCountCTESubquery(); diff --git a/src/duckpgq_state.cpp b/src/duckpgq_state.cpp index b606b70d..35d5df51 100644 --- a/src/duckpgq_state.cpp +++ b/src/duckpgq_state.cpp @@ -16,7 +16,9 @@ DuckPGQState::DuckPGQState(shared_ptr context) { "destination_pk varchar[], " "destination_fk varchar[], " "discriminator varchar, " - "sub_labels varchar[])", + "sub_labels varchar[], " + "catalog varchar, " + "schema varchar)", false); if (query->HasError()) { throw TransactionException(query->GetError()); @@ -25,71 +27,100 @@ DuckPGQState::DuckPGQState(shared_ptr context) { RetrievePropertyGraphs(new_conn); } -void DuckPGQState::RetrievePropertyGraphs(shared_ptr context) { - auto retrieve_pg = context->Query("SELECT * FROM __duckpgq_internal", false); +void DuckPGQState::RetrievePropertyGraphs(const shared_ptr &context) { + // Retrieve and process vertex property graphs + auto vertex_property_graphs = context->Query("SELECT * FROM __duckpgq_internal WHERE is_vertex_table", false); + ProcessPropertyGraphs(vertex_property_graphs, true); - auto &materialized_result = retrieve_pg->Cast(); - auto row_count = materialized_result.RowCount(); - if (row_count == 0) { - return; // no results - } - auto chunk = materialized_result.Fetch(); - for (idx_t i = 0; i < row_count; i++) { - auto table = make_shared_ptr(); - string property_graph_name = chunk->GetValue(0, i).GetValue(); - table->table_name = chunk->GetValue(1, i).GetValue(); - table->main_label = chunk->GetValue(2, i).GetValue(); - table->is_vertex_table = chunk->GetValue(3, i).GetValue(); - table->all_columns = true; // TODO Be stricter on properties - if (!table->is_vertex_table) { - // Handle edge table related things. - table->source_reference = chunk->GetValue(4, i).GetValue(); - auto source_pk_chunk = ListValue::GetChildren(chunk->GetValue(5, i)); - for (const auto &source_pk : source_pk_chunk) { - table->source_pk.push_back(source_pk.GetValue()); - } - auto source_fk_chunk = ListValue::GetChildren(chunk->GetValue(6, i)); - for (const auto &source_fk : source_fk_chunk) { - table->source_fk.push_back(source_fk.GetValue()); - } - table->destination_reference = chunk->GetValue(7, i).GetValue(); - auto destination_pk_chunk = ListValue::GetChildren(chunk->GetValue(8, i)); - for (const auto &dest_pk : destination_pk_chunk) { - table->destination_pk.push_back(dest_pk.GetValue()); - } - auto destination_fk_chunk = ListValue::GetChildren(chunk->GetValue(9, i)); - for (const auto &dest_fk : destination_fk_chunk) { - table->destination_fk.push_back(dest_fk.GetValue()); - } + // Retrieve and process edge property graphs + auto edge_property_graphs = context->Query("SELECT * FROM __duckpgq_internal WHERE NOT is_vertex_table", false); + ProcessPropertyGraphs(edge_property_graphs, false); +} + +void DuckPGQState::ProcessPropertyGraphs(unique_ptr &property_graphs, bool is_vertex) { + if (!property_graphs || property_graphs->type != QueryResultType::MATERIALIZED_RESULT) { + throw std::runtime_error("Failed to fetch property graphs or invalid result type."); } - string discriminator = chunk->GetValue(10, i).GetValue(); - if (discriminator != "NULL") { - table->discriminator = discriminator; - auto sublabels = ListValue::GetChildren(chunk->GetValue(11, i)); - for (const auto &sublabel : sublabels) { - table->sub_labels.push_back(sublabel.GetValue()); - } + + auto &materialized_result = property_graphs->Cast(); + auto row_count = materialized_result.RowCount(); + if (row_count == 0) { + return; // No results } - if (registered_property_graphs.find(property_graph_name) == - registered_property_graphs.end()) { - registered_property_graphs[property_graph_name] = - make_uniq(property_graph_name); + auto chunk = materialized_result.Fetch(); + for (idx_t i = 0; i < row_count; i++) { + auto table = make_shared_ptr(); + + // Extract and validate common properties + table->table_name = chunk->GetValue(1, i).GetValue(); + table->main_label = chunk->GetValue(2, i).GetValue(); + table->is_vertex_table = chunk->GetValue(3, i).GetValue(); + table->all_columns = true; // TODO: Be stricter on properties + + // Handle discriminator and sub-labels + const auto &discriminator = chunk->GetValue(10, i).GetValue(); + if (discriminator != "NULL") { + table->discriminator = discriminator; + auto sublabels = ListValue::GetChildren(chunk->GetValue(11, i)); + for (const auto &sublabel : sublabels) { + table->sub_labels.push_back(sublabel.GetValue()); + } + } + + // Extract catalog and schema names + table->catalog_name = chunk->GetValue(12, i).GetValue(); + table->schema_name = chunk->GetValue(13, i).GetValue(); + + // Additional edge-specific handling + if (!is_vertex) { + PopulateEdgeSpecificFields(chunk, i, *table); + } + + RegisterPropertyGraph(table, chunk->GetValue(0, i).GetValue(), is_vertex); } - auto &pg_info = registered_property_graphs[property_graph_name] - ->Cast(); +} + +void DuckPGQState::PopulateEdgeSpecificFields(unique_ptr &chunk, idx_t row_idx, PropertyGraphTable &table) { + table.source_reference = chunk->GetValue(4, row_idx).GetValue(); + ExtractListValues(chunk->GetValue(5, row_idx), table.source_pk); + ExtractListValues(chunk->GetValue(6, row_idx), table.source_fk); + table.destination_reference = chunk->GetValue(7, row_idx).GetValue(); + ExtractListValues(chunk->GetValue(8, row_idx), table.destination_pk); + ExtractListValues(chunk->GetValue(9, row_idx), table.destination_fk); +} + +void DuckPGQState::ExtractListValues(const Value &list_value, vector &output) { + auto children = ListValue::GetChildren(list_value); + for (const auto &child : children) { + output.push_back(child.GetValue()); + } +} + +void DuckPGQState::RegisterPropertyGraph(const shared_ptr &table, const string &graph_name, bool is_vertex) { + // Ensure the property graph exists in the registry + if (registered_property_graphs.find(graph_name) == registered_property_graphs.end()) { + registered_property_graphs[graph_name] = make_uniq(graph_name); + } + + auto &pg_info = registered_property_graphs[graph_name]->Cast(); pg_info.label_map[table->main_label] = table; + if (!table->discriminator.empty()) { - for (const auto &label : table->sub_labels) { - pg_info.label_map[label] = table; - } + for (const auto &label : table->sub_labels) { + pg_info.label_map[label] = table; + } } - if (table->is_vertex_table) { - pg_info.vertex_tables.push_back(std::move(table)); + + if (is_vertex) { + pg_info.vertex_tables.push_back(table); } else { - pg_info.edge_tables.push_back(std::move(table)); + table->source_pg_table = pg_info.GetTableByName(table->source_reference); + D_ASSERT(table->source_pg_table); + table->destination_pg_table = pg_info.GetTableByName(table->destination_reference); + D_ASSERT(table->destination_pg_table); + pg_info.edge_tables.push_back(table); } - } } void DuckPGQState::QueryEnd() { diff --git a/src/include/duckpgq/core/functions/table/match.hpp b/src/include/duckpgq/core/functions/table/match.hpp index 8f92dc9c..f319578d 100644 --- a/src/include/duckpgq/core/functions/table/match.hpp +++ b/src/include/duckpgq/core/functions/table/match.hpp @@ -16,6 +16,7 @@ #include "duckdb/parser/path_element.hpp" #include "duckdb/parser/path_pattern.hpp" #include "duckdb/parser/subpath_element.hpp" +#include "duckdb/parser/property_graph_table.hpp" #include @@ -94,7 +95,7 @@ struct PGQMatchFunction : public TableFunction { const string &edge_binding, const string &prev_binding, const string &next_binding, vector> &conditions, - unordered_map &alias_map, + case_insensitive_map_t> &alias_map, int32_t &extra_alias_counter); static PathElement * @@ -135,14 +136,14 @@ struct PGQMatchFunction : public TableFunction { PGQMatchType edge_type, const string &edge_binding, const string &prev_binding, const string &next_binding, vector> &conditions, - unordered_map &alias_map, + case_insensitive_map_t> &alias_map, int32_t &extra_alias_counter, unique_ptr &from_clause); static void ProcessPathList( vector> &path_pattern, vector> &conditions, unique_ptr &select_node, - unordered_map &alias_map, + case_insensitive_map_t> &alias_map, CreatePropertyGraphInfo &pg_table, int32_t &extra_alias_counter, MatchExpression &original_ref); diff --git a/src/include/duckpgq/core/utils/compressed_sparse_row.hpp b/src/include/duckpgq/core/utils/compressed_sparse_row.hpp index 76cf84b4..1eca95e4 100644 --- a/src/include/duckpgq/core/utils/compressed_sparse_row.hpp +++ b/src/include/duckpgq/core/utils/compressed_sparse_row.hpp @@ -72,12 +72,12 @@ unique_ptr CreateDirectedCSRCTE(const shared_ptr MakeEdgesCTE(const shared_ptr &edge_table); -unique_ptr CreateDirectedCSRVertexSubquery(const shared_ptr &edge_table, const std::string &binding); -unique_ptr CreateUndirectedCSRVertexSubquery(const shared_ptr &edge_table, const std::string &binding); +unique_ptr CreateDirectedCSRVertexSubquery(const shared_ptr &edge_table, const string &binding); +unique_ptr CreateUndirectedCSRVertexSubquery(const shared_ptr &edge_table, const string &binding); unique_ptr CreateOuterSelectEdgesNode(); unique_ptr CreateOuterSelectNode(unique_ptr create_csr_edge_function); unique_ptr GetJoinRef(const shared_ptr &edge_table,const string &edge_binding, const string &prev_binding, const string &next_binding); -unique_ptr GetCountTable(const string &table_name, const string &table_alias, const string &primary_key); +unique_ptr GetCountTable(const shared_ptr &table, const string &table_alias, const string &primary_key); void SetupSelectNode(unique_ptr &select_node, const shared_ptr &edge_table, bool reverse = false); unique_ptr CreateCountCTESubquery(); unique_ptr GetCountUndirectedEdgeTable(); diff --git a/src/include/duckpgq_state.hpp b/src/include/duckpgq_state.hpp index be6c9c89..dcecaf82 100644 --- a/src/include/duckpgq_state.hpp +++ b/src/include/duckpgq_state.hpp @@ -14,7 +14,12 @@ class DuckPGQState : public ClientContextState { CreatePropertyGraphInfo *GetPropertyGraph(const string &pg_name); duckpgq::core::CSR *GetCSR(int32_t id); - void RetrievePropertyGraphs(shared_ptr context); + void RetrievePropertyGraphs(const shared_ptr &context); + void ProcessPropertyGraphs(unique_ptr &property_graphs, bool is_vertex); + void PopulateEdgeSpecificFields(unique_ptr &chunk, idx_t row_idx, + PropertyGraphTable &table); + static void ExtractListValues(const Value &list_value, vector &output); + void RegisterPropertyGraph(const shared_ptr &table, const string &graph_name, bool is_vertex); public: unique_ptr parse_data; diff --git a/test/sql/create_pg/attach_pg.test b/test/sql/create_pg/attach_pg.test new file mode 100644 index 00000000..dd2e94ed --- /dev/null +++ b/test/sql/create_pg/attach_pg.test @@ -0,0 +1,138 @@ +# name: test/sql/create_pg/attach_pg.test +# description: Testing create property graph with an attached database +# group: [duckpgq_sql_create_pg] + +require duckpgq + +statement ok con1 +attach 'duckdb/data/bluesky/bluesky.duckdb'; + +query I con1 +select count(*) from bluesky.follows; +---- +19566 + + +statement ok con1 +-CREATE OR REPLACE PROPERTY GRAPH bluesky + VERTEX TABLES (bluesky.account LABEL account) + EDGE TABLES (bluesky.follows SOURCE KEY (source) REFERENCES bluesky.account (did) + DESTINATION KEY (destination) REFERENCES bluesky.account (did) + LABEL follows); + +statement ok con1 +-FROM GRAPH_TABLE (bluesky MATCH (a:account)); + +query I +select count(*) from bluesky.account; +---- +8921 + +statement ok con2 +-FROM GRAPH_TABLE (bluesky MATCH (a:account)); + +statement ok con2 +-FROM GRAPH_TABLE (bluesky MATCH (a:account)-[f:follows]->(b:account)); + +statement ok con1 +-FROM GRAPH_TABLE (bluesky MATCH (a:account)-[f:follows]->(b:account)); + +query II con1 +-FROM GRAPH_TABLE (bluesky MATCH (a:account)-[f:follows]->(b:account) COLUMNS (a.did as a_id, b.did as b_id)) ORDER BY a_id, b_id LIMIT 10; +---- +did:plc:23df55poeztue4terk3s5ain did:plc:274qq3cgl4vrrofdg77balfw +did:plc:23df55poeztue4terk3s5ain did:plc:2ktpgfwt7cc2osldzh6uyww5 +did:plc:23df55poeztue4terk3s5ain did:plc:2p5eadzea3yb2ghwtzrlaebo +did:plc:23df55poeztue4terk3s5ain did:plc:37drmtazrclxzxezzk4ijuk7 +did:plc:23df55poeztue4terk3s5ain did:plc:42qpqlgojbezm3gt2nxdfikk +did:plc:23df55poeztue4terk3s5ain did:plc:45g7v5rojoj4tpspb7fg6dvp +did:plc:23df55poeztue4terk3s5ain did:plc:4kv7ldgzot7q4w4y65kpsbwo +did:plc:23df55poeztue4terk3s5ain did:plc:4nt6nwx353a3xxo5mzjiy4ha +did:plc:23df55poeztue4terk3s5ain did:plc:6k63663icgdybm5evgszxjn2 +did:plc:23df55poeztue4terk3s5ain did:plc:7562tstpez4aexd75ttshl3z + +query II con1 +-FROM GRAPH_TABLE (bluesky MATCH (a:account where a.did='did:plc:7qqkrwwec4qeujs6hthlgpbe')-[f:follows]->{1,3}(b:account) COLUMNS (a.did as a_id, b.did as b_id)) ORDER BY a_id, b_id LIMIT 10; +---- +did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:224f4aj5p5vgk7tpcc4lltgx +did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:225ihm6x4pkgdpbmvfpxyicf +did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22btehtv4y5dogqne5nuu2jx +did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22exfzbkuj3dlzj3ukyy4g5y +did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22m65anrpfstjo5ymgyl2vwu +did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22mof5hzsrituokdxsnoi7qi +did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22nbqn2zjp2pobu6cwquhjuu +did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22qt6jzmwtgyxzft57kvwut6 +did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22u3xlfdxqxyzva2fsljotcy +did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:23df55poeztue4terk3s5ain + +query III con1 +-FROM GRAPH_TABLE (bluesky MATCH p = ANY SHORTEST (a:account where a.did='did:plc:7qqkrwwec4qeujs6hthlgpbe')-[f:follows]->*(b:account) + COLUMNS (element_id(p) as path, a.did as a_id, b.did as b_id)) +ORDER BY a_id, b_id +LIMIT 10; +---- +[15, 13, 9, 347, 276, 11536, 5145] did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:224f4aj5p5vgk7tpcc4lltgx +[15, 8, 1, 27, 65, 2565, 1530] did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:225ihm6x4pkgdpbmvfpxyicf +[15, 8, 1, 44, 31, 1058, 863] did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22btehtv4y5dogqne5nuu2jx +[15, 3, 0, 22, 18, 620, 484] did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22exfzbkuj3dlzj3ukyy4g5y +[15, 8, 1, 64, 68, 2709, 1594] did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22m65anrpfstjo5ymgyl2vwu +[15, 7, 6, 260, 206, 8273, 4031] did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22mof5hzsrituokdxsnoi7qi +[15, 6, 11, 424, 316, 13257, 5646] did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22nbqn2zjp2pobu6cwquhjuu +[15, 8, 1, 39, 27, 882, 730] did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22qt6jzmwtgyxzft57kvwut6 +[15, 2, 4, 140, 104, 4215, 2188] did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:22u3xlfdxqxyzva2fsljotcy +[15, 3, 0, 24, 17, 585, 461, 19521, 8887] did:plc:7qqkrwwec4qeujs6hthlgpbe did:plc:23czq4ad6kgrjdgke52yapso + + +query II con1 +from local_clustering_coefficient(bluesky, account, follows) limit 10; +---- +did:plc:rsfoi33e4iya2rd7jw52nfmo 0.11904762 +did:plc:btsulrw4wcqdai23fkl5qwm5 0.12508735 +did:plc:z72i7hdynmk6r22z27h6tvur 0.028301887 +did:plc:twcatus5xoa7jaeysmrhzcpv 0.15726179 +did:plc:wptnzi6wyzqltbenxapqa5qd 0.07191316 +did:plc:edglm4muiyzty2snc55ysuqx 0.117788464 +did:plc:sc6ieuzeygvm55vv2bjubkgt 0.102591224 +did:plc:g5gf5ho5yn3n5anprzf45hvm 0.103670634 +did:plc:cwcykfexwbxozuxhpuud63qa 0.35714287 +did:plc:c5ccfcya6zez3rhry6gluup4 0.07952872 + +query II con1 +from weakly_connected_component(bluesky, account, follows) limit 10; +---- +did:plc:rsfoi33e4iya2rd7jw52nfmo 0 +did:plc:btsulrw4wcqdai23fkl5qwm5 0 +did:plc:z72i7hdynmk6r22z27h6tvur 0 +did:plc:twcatus5xoa7jaeysmrhzcpv 0 +did:plc:wptnzi6wyzqltbenxapqa5qd 0 +did:plc:edglm4muiyzty2snc55ysuqx 0 +did:plc:sc6ieuzeygvm55vv2bjubkgt 0 +did:plc:g5gf5ho5yn3n5anprzf45hvm 0 +did:plc:cwcykfexwbxozuxhpuud63qa 0 +did:plc:c5ccfcya6zez3rhry6gluup4 0 + +query II con1 +from pagerank(bluesky, account, follows) limit 10; +---- +did:plc:rsfoi33e4iya2rd7jw52nfmo 0.0001775254576762574 +did:plc:btsulrw4wcqdai23fkl5qwm5 0.0002686321909810804 +did:plc:z72i7hdynmk6r22z27h6tvur 0.0008689709539525615 +did:plc:twcatus5xoa7jaeysmrhzcpv 0.00018038910592903322 +did:plc:wptnzi6wyzqltbenxapqa5qd 0.00019702956517977273 +did:plc:edglm4muiyzty2snc55ysuqx 0.000183535102914441 +did:plc:sc6ieuzeygvm55vv2bjubkgt 0.00016956149650616158 +did:plc:g5gf5ho5yn3n5anprzf45hvm 0.00019340188585017924 +did:plc:cwcykfexwbxozuxhpuud63qa 0.0001771935670038598 +did:plc:c5ccfcya6zez3rhry6gluup4 0.00047818698168931504 + +statement error con1 +select count(*) from follows; +---- +Catalog Error: Table with name follows does not exist! + +statement error con1 +from pagerank(bluesky, bluesky.account, follows) limit 10; +---- +Invalid Error: Label 'bluesky.account' not found. Did you mean the vertex label 'account'? + + diff --git a/test/sql/create_pg/create_pg_with_pk_fk.test b/test/sql/create_pg/create_pg_with_pk_fk.test index 4e661689..e303098e 100644 --- a/test/sql/create_pg/create_pg_with_pk_fk.test +++ b/test/sql/create_pg/create_pg_with_pk_fk.test @@ -51,7 +51,7 @@ statement error vertex tables (v) edge tables (e2 source v destination w); ---- -Invalid Error: Referenced vertex table w is not registered in the vertex tables +Invalid Error: Table 'w' not found in the property graph g. statement ok -create property graph g diff --git a/test/sql/create_pg/create_property_graph.test b/test/sql/create_pg/create_property_graph.test index 45e070a4..132a6bb4 100644 --- a/test/sql/create_pg/create_property_graph.test +++ b/test/sql/create_pg/create_property_graph.test @@ -11,7 +11,7 @@ statement error -CREATE PROPERTY GRAPH pg4 VERTEX TABLES (tabledoesnotexist); ---- -Invalid Error: Table tabledoesnotexist not found +Invalid Error: Table main.tabledoesnotexist not found statement ok @@ -24,7 +24,7 @@ EDGE TABLES (edgetabledoesnotexist SOURCE KEY (id) REFERENCES Student (id) DESTINATION KEY (id) REFERENCES Student (id) ); ---- -Invalid Error: Table edgetabledoesnotexist not found +Invalid Error: Table main.edgetabledoesnotexist not found statement ok CREATE TABLE know(src BIGINT, dst BIGINT, createDate BIGINT); @@ -147,8 +147,7 @@ EDGE TABLES ( PROPERTIES ( createDate ) LABEL Knows ) ---- -Invalid Error: Referenced vertex table Student is not registered in the vertex tables. - +Invalid Error: Table 'Student' not found in the property graph pg3. # Should fail since the edge table references vertex tables that do not exist statement error @@ -157,12 +156,12 @@ VERTEX TABLES ( School LABEL School IN School_kind (Hogeschool, University) ) EDGE TABLES ( - know SOURCE KEY ( src ) REFERENCES Student ( id ) + know SOURCE KEY ( src ) REFERENCES School ( school_id ) DESTINATION KEY ( dst ) REFERENCES Student__ ( id ) PROPERTIES ( createDate ) LABEL Knows ); ---- -Invalid Error: Referenced vertex table Student is not registered in the vertex tables. +Invalid Error: Table 'Student__' not found in the property graph pg3. # Check duplicate labels diff --git a/test/sql/path_finding/subpath_match.test b/test/sql/path_finding/subpath_match.test index 5f29b442..a6ceba89 100644 --- a/test/sql/path_finding/subpath_match.test +++ b/test/sql/path_finding/subpath_match.test @@ -43,16 +43,16 @@ FROM GRAPH_TABLE (pg ---- 0 Daniel -#query II -#-SELECT study.a_id, study.b_id -#FROM GRAPH_TABLE (pg -# MATCH -# (a:Person)-[k:Knows WHERE k.id = 10]->(b:Person) -# COLUMNS (a.id as a_id, b.id as b_id) -# ) study -#---- -#0 1 -# +query II +-SELECT study.a_id, study.b_id +FROM GRAPH_TABLE (pg + MATCH + (a:Person)-[k:Knows WHERE k.id = 10]->(b:Person) + COLUMNS (a.id as a_id, b.id as b_id) + ) study +---- +0 1 + #query II #WITH cte1 AS ( # SELECT CREATE_CSR_EDGE(