diff --git a/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp b/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp index c1949460..36ecac49 100644 --- a/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp +++ b/duckpgq/src/duckpgq/functions/tablefunctions/create_property_graph.cpp @@ -1,5 +1,6 @@ #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 namespace duckdb { @@ -88,11 +89,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 +106,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 +155,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. +