From be7c0974038c2e4d9209fbf7bcd08879aeb251fb Mon Sep 17 00:00:00 2001 From: dtenwolde Date: Fri, 6 Sep 2024 16:20:08 +0200 Subject: [PATCH] Improved error messages and updated tests --- .../functions/table/create_property_graph.cpp | 10 +++++----- .../functions/table/create_property_graph.hpp | 2 +- test/sql/create_pg/create_pg_with_pk_fk.test | 17 ++++++++++++----- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/core/functions/table/create_property_graph.cpp b/src/core/functions/table/create_property_graph.cpp index 9fd7846..20621ab 100644 --- a/src/core/functions/table/create_property_graph.cpp +++ b/src/core/functions/table/create_property_graph.cpp @@ -75,7 +75,7 @@ void CreatePropertyGraphFunction::ValidateKeys(shared_ptr &e if (table_constraints.empty()) { throw Exception(ExceptionType::INVALID, "No primary key - foreign key relationship found in " + - edge_table->table_name + " with " + key_type + + edge_table->table_name + " with " + StringUtil::Upper(key_type) + " table " + reference); } @@ -89,9 +89,9 @@ void CreatePropertyGraphFunction::ValidateKeys(shared_ptr &e if (!pk_columns.empty() && !fk_columns.empty()) { throw Exception( ExceptionType::INVALID, - "Multiple primary key - foreign key relationships detected with the same table. " + "Multiple primary key - foreign key relationships detected between " + edge_table->table_name + " and " + reference + ". " "Please explicitly define the primary key and foreign key columns using `" + - key_type + " KEY REFERENCES " + reference + " `"); + StringUtil::Upper(key_type) + " KEY REFERENCES " + reference + " `"); } pk_columns = fk_constraint.pk_columns; fk_columns = fk_constraint.fk_columns; @@ -100,13 +100,13 @@ void CreatePropertyGraphFunction::ValidateKeys(shared_ptr &e if (pk_columns.empty()) { throw Exception(ExceptionType::INVALID, - "The primary key for the " + key_type + " table " + reference + + "The primary key for the " + StringUtil::Upper(key_type) + " table " + reference + " is not defined in the edge table " + edge_table->table_name); } if (fk_columns.empty()) { throw Exception(ExceptionType::INVALID, - "The foreign key for the " + key_type + " table " + reference + + "The foreign key for the " + StringUtil::Upper(key_type) + " table " + reference + " is not defined in the edge table " + edge_table->table_name); } } diff --git a/src/include/duckpgq/core/functions/table/create_property_graph.hpp b/src/include/duckpgq/core/functions/table/create_property_graph.hpp index 46e9af1..bb55c81 100644 --- a/src/include/duckpgq/core/functions/table/create_property_graph.hpp +++ b/src/include/duckpgq/core/functions/table/create_property_graph.hpp @@ -60,7 +60,7 @@ class CreatePropertyGraphFunction : public TableFunction { static void ValidateForeignKeyColumns(shared_ptr &edge_table, const vector &fk_columns, - optional_ptr &table) + optional_ptr &table); static unique_ptr CreatePropertyGraphInit(ClientContext &context, 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 a88e9c5..4e66168 100644 --- a/test/sql/create_pg/create_pg_with_pk_fk.test +++ b/test/sql/create_pg/create_pg_with_pk_fk.test @@ -25,7 +25,7 @@ statement error vertex tables (v) edge tables (e source v destination v); ---- -Invalid Error: Multiple primary key - foreign key relationships detected with the same table. Please explicitly define the primary key and foreign key columns using `SOURCE KEY REFERENCES v ` +Invalid Error: Multiple primary key - foreign key relationships detected between e and v. Please explicitly define the primary key and foreign key columns using `SOURCE KEY REFERENCES v ` statement ok create table w ( @@ -88,7 +88,7 @@ CREATE TABLE b ( statement error -CREATE PROPERTY GRAPH g2 VERTEX TABLES (a) EDGE TABLES (b SOURCE a DESTINATION a); ---- -Invalid Error: No primary key - foreign key relationship found in b with source table a +Invalid Error: No primary key - foreign key relationship found in b with SOURCE table a statement ok CREATE TABLE a_pk ( @@ -124,7 +124,14 @@ statement error VERTEX TABLES (x) EDGE TABLES (y SOURCE x DESTINATION x); ---- -Invalid Error: Multiple primary key - foreign key relationships detected with the same table. Please explicitly define the primary key and foreign key columns using `SOURCE KEY REFERENCES x ` +Invalid Error: Multiple primary key - foreign key relationships detected between y and x. Please explicitly define the primary key and foreign key columns using `SOURCE KEY REFERENCES x ` + +statement error +-CREATE PROPERTY GRAPH g3 +VERTEX TABLES (x) +EDGE TABLES (y SOURCE KEY (src) REFERENCES x (id) DESTINATION x); +---- +Invalid Error: Multiple primary key - foreign key relationships detected between y and x. Please explicitly define the primary key and foreign key columns using `DESTINATION KEY REFERENCES x ` statement ok -CREATE PROPERTY GRAPH g3_explicit @@ -154,7 +161,7 @@ statement error VERTEX TABLES (m) EDGE TABLES (n SOURCE m DESTINATION m); ---- -Invalid Error: The primary key for the source table m is not defined in the edge table n +Invalid Error: The primary key for the SOURCE table m is not defined in the edge table n statement error -CREATE PROPERTY GRAPH g4 @@ -244,7 +251,7 @@ statement error VERTEX TABLES (node_a) EDGE TABLES (edge_a SOURCE node_a DESTINATION KEY (dst) REFERENCES node_a (id)); ---- -Invalid Error: Multiple primary key - foreign key relationships detected with the same table. Please explicitly define the primary key and foreign key columns using `SOURCE KEY REFERENCES node_a ` +Invalid Error: Multiple primary key - foreign key relationships detected between edge_a and node_a. Please explicitly define the primary key and foreign key columns using `SOURCE KEY REFERENCES node_a ` statement ok -CREATE PROPERTY GRAPH g10