From c11efc69e5665c0739a82410357efb38c54fa56d Mon Sep 17 00:00:00 2001 From: dtenwolde Date: Fri, 22 Mar 2024 14:08:03 +0100 Subject: [PATCH 1/2] Properly catch exception when creating property graph on table that does not exist --- .../tablefunctions/create_property_graph.cpp | 49 ++++++++++++------- test/sql/create_pg/create_property_graph.test | 17 +++++++ 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp b/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp index c1949460..e959b5e0 100644 --- a/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp +++ b/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp @@ -1,7 +1,10 @@ #include "duckpgq/functions/tablefunctions/create_property_graph.hpp" #include "duckdb/parser/statement/create_statement.hpp" +#include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp" #include +#include + namespace duckdb { void CreatePropertyGraphFunction::CheckPropertyGraphTableLabels( @@ -88,11 +91,15 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind( auto &catalog = Catalog::GetCatalog(context, info->catalog); case_insensitive_set_t v_table_names; for (auto &vertex_table : info->vertex_tables) { - auto &table = catalog.GetEntry(context, info->schema, - vertex_table->table_name); - - CheckPropertyGraphTableColumns(vertex_table, table); - CheckPropertyGraphTableLabels(vertex_table, table); + try { + auto &table = catalog.GetEntry(context, info->schema, + vertex_table->table_name); + + CheckPropertyGraphTableColumns(vertex_table, table); + CheckPropertyGraphTableLabels(vertex_table, table); + } catch (Exception &) { + throw Exception(ExceptionType::INVALID, vertex_table->table_name + " does not exist"); + } v_table_names.insert(vertex_table->table_name); if (vertex_table->hasTableNameAlias()) { @@ -101,11 +108,27 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind( } for (auto &edge_table : info->edge_tables) { - auto &table = catalog.GetEntry(context, info->schema, + try { + auto &table = catalog.GetEntry(context, info->schema, edge_table->table_name); - CheckPropertyGraphTableColumns(edge_table, table); - CheckPropertyGraphTableLabels(edge_table, table); + CheckPropertyGraphTableColumns(edge_table, table); + CheckPropertyGraphTableLabels(edge_table, table); + + for (auto &fk : edge_table->source_fk) { + if (!table.ColumnExists(fk)) { + throw Exception(ExceptionType::INVALID,"Foreign key " + fk + " does not exist in table " + edge_table->table_name); + } + } + + for (auto &fk : edge_table->destination_fk) { + if (!table.ColumnExists(fk)) { + throw Exception(ExceptionType::INVALID,"Foreign key " + fk + " does not exist in table " + edge_table->table_name); + } + } + } catch(const Exception &) { + throw Exception(ExceptionType::INVALID, edge_table->table_name + " does not exist"); + } if (v_table_names.find(edge_table->source_reference) == v_table_names.end()) { @@ -134,17 +157,7 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind( } } - for (auto &fk : edge_table->source_fk) { - if (!table.ColumnExists(fk)) { - throw Exception(ExceptionType::INVALID,"Foreign key " + fk + " does not exist in table " + edge_table->table_name); - } - } - for (auto &fk : edge_table->destination_fk) { - if (!table.ColumnExists(fk)) { - throw Exception(ExceptionType::INVALID,"Foreign key " + fk + " does not exist in table " + edge_table->table_name); - } - } } return make_uniq(info); } diff --git a/test/sql/create_pg/create_property_graph.test b/test/sql/create_pg/create_property_graph.test index 4e13411e..41d4382d 100644 --- a/test/sql/create_pg/create_property_graph.test +++ b/test/sql/create_pg/create_property_graph.test @@ -6,9 +6,25 @@ require duckpgq statement ok pragma enable_verification +statement error +-CREATE PROPERTY GRAPH pg4 +VERTEX TABLES (tabledoesnotexist); +---- +Invalid Error: tabledoesnotexist does not exist + + statement ok CREATE TABLE Student(id BIGINT, name VARCHAR); +statement error +-CREATE PROPERTY GRAPH pg4 +VERTEX TABLES (Student) +EDGE TABLES (edgetabledoesnotexist SOURCE KEY (id) REFERENCES Student (id) + DESTINATION KEY (id) REFERENCES Student (id) + ); +---- +Invalid Error: edgetabledoesnotexist does not exist + statement ok CREATE TABLE know(src BIGINT, dst BIGINT, createDate BIGINT); @@ -146,3 +162,4 @@ EDGE TABLES ( ); ---- Invalid Error: Referenced vertex table Student does not exist. + From dc2f49d5aaa941c11d32b7ab7852ae8f3a105662 Mon Sep 17 00:00:00 2001 From: dtenwolde Date: Fri, 22 Mar 2024 14:15:49 +0100 Subject: [PATCH 2/2] Remove iostream --- .../duckpgq/functions/tablefunctions/create_property_graph.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp b/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp index e959b5e0..36ecac49 100644 --- a/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp +++ b/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp @@ -3,8 +3,6 @@ #include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp" #include -#include - namespace duckdb { void CreatePropertyGraphFunction::CheckPropertyGraphTableLabels(