Skip to content

Commit

Permalink
Merge pull request #111 from cwida/103-internal-exception-when-creati…
Browse files Browse the repository at this point in the history
…ng-property-graph-on-non-existing-table

Properly catch exception when creating property graph on table that does not exist
  • Loading branch information
Dtenwolde authored Mar 22, 2024
2 parents 67c2cc1 + dc2f49d commit 836bd20
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -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 <duckpgq_extension.hpp>

namespace duckdb {
Expand Down Expand Up @@ -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<TableCatalogEntry>(context, info->schema,
vertex_table->table_name);

CheckPropertyGraphTableColumns(vertex_table, table);
CheckPropertyGraphTableLabels(vertex_table, table);
try {
auto &table = catalog.GetEntry<TableCatalogEntry>(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()) {
Expand All @@ -101,11 +106,27 @@ CreatePropertyGraphFunction::CreatePropertyGraphBind(
}

for (auto &edge_table : info->edge_tables) {
auto &table = catalog.GetEntry<TableCatalogEntry>(context, info->schema,
try {
auto &table = catalog.GetEntry<TableCatalogEntry>(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()) {
Expand Down Expand Up @@ -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<CreatePropertyGraphBindData>(info);
}
Expand Down
17 changes: 17 additions & 0 deletions test/sql/create_pg/create_property_graph.test
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -146,3 +162,4 @@ EDGE TABLES (
);
----
Invalid Error: Referenced vertex table Student does not exist.

0 comments on commit 836bd20

Please sign in to comment.