Skip to content

Commit

Permalink
Improved error messages and updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dtenwolde committed Sep 6, 2024
1 parent 234bd3e commit be7c097
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/core/functions/table/create_property_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void CreatePropertyGraphFunction::ValidateKeys(shared_ptr<PropertyGraphTable> &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);
}

Expand All @@ -89,9 +89,9 @@ void CreatePropertyGraphFunction::ValidateKeys(shared_ptr<PropertyGraphTable> &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 <primary key> REFERENCES " + reference + " <foreign key>`");
StringUtil::Upper(key_type) + " KEY <primary key> REFERENCES " + reference + " <foreign key>`");
}
pk_columns = fk_constraint.pk_columns;
fk_columns = fk_constraint.fk_columns;
Expand All @@ -100,13 +100,13 @@ void CreatePropertyGraphFunction::ValidateKeys(shared_ptr<PropertyGraphTable> &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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class CreatePropertyGraphFunction : public TableFunction {

static void ValidateForeignKeyColumns(shared_ptr<PropertyGraphTable> &edge_table,
const vector<string> &fk_columns,
optional_ptr<TableCatalogEntry> &table)
optional_ptr<TableCatalogEntry> &table);

static unique_ptr<GlobalTableFunctionState>
CreatePropertyGraphInit(ClientContext &context,
Expand Down
17 changes: 12 additions & 5 deletions test/sql/create_pg/create_pg_with_pk_fk.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 <primary key> REFERENCES v <foreign key>`
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 <primary key> REFERENCES v <foreign key>`

statement ok
create table w (
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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 <primary key> REFERENCES x <foreign key>`
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 <primary key> REFERENCES x <foreign key>`

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 <primary key> REFERENCES x <foreign key>`

statement ok
-CREATE PROPERTY GRAPH g3_explicit
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 <primary key> REFERENCES node_a <foreign key>`
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 <primary key> REFERENCES node_a <foreign key>`

statement ok
-CREATE PROPERTY GRAPH g10
Expand Down

0 comments on commit be7c097

Please sign in to comment.