Skip to content

Commit

Permalink
Also throw error for views on edge tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Dtenwolde committed Oct 30, 2024
1 parent b29e8ab commit ac29e24
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 25 deletions.
59 changes: 34 additions & 25 deletions src/core/functions/table/create_property_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,41 +199,50 @@ unique_ptr<FunctionData> 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, OnEntryNotFound::RETURN_NULL);
if (!table) {
throw Exception(ExceptionType::INVALID,
"Table " + edge_table->table_name + " not found");
}
if (!table) {
throw Exception(ExceptionType::INVALID,
"Table " + edge_table->table_name + " not found");
}

CheckPropertyGraphTableColumns(edge_table, *table);
CheckPropertyGraphTableLabels(edge_table, *table);
auto &table_constraints = table->GetConstraints();
CheckPropertyGraphTableColumns(edge_table, *table);
CheckPropertyGraphTableLabels(edge_table, *table);

ValidateKeys(edge_table, edge_table->source_reference, "source",
edge_table->source_pk, edge_table->source_fk, table_constraints);
auto &table_constraints = table->GetConstraints();

// Check source foreign key columns exist in the table
ValidateForeignKeyColumns(edge_table, edge_table->source_fk, table);
ValidateKeys(edge_table, edge_table->source_reference, "source",
edge_table->source_pk, edge_table->source_fk, table_constraints);

// Validate destination keys
ValidateKeys(edge_table, edge_table->destination_reference, "destination",
edge_table->destination_pk, edge_table->destination_fk, table_constraints);
// Check source foreign key columns exist in the table
ValidateForeignKeyColumns(edge_table, edge_table->source_fk, table);

// Check destination foreign key columns exist in the table
ValidateForeignKeyColumns(edge_table, edge_table->destination_fk, table);
// Validate destination keys
ValidateKeys(edge_table, edge_table->destination_reference, "destination",
edge_table->destination_pk, edge_table->destination_fk, table_constraints);

// Validate source table registration
ValidateVertexTableRegistration(edge_table->source_reference, v_table_names);
// Check destination foreign key columns exist in the table
ValidateForeignKeyColumns(edge_table, edge_table->destination_fk, table);

// Validate primary keys in the source table
ValidatePrimaryKeyInTable(catalog, context, info->schema, edge_table->source_reference, edge_table->source_pk);
// Validate source table registration
ValidateVertexTableRegistration(edge_table->source_reference, v_table_names);

// Validate destination table registration
ValidateVertexTableRegistration(edge_table->destination_reference, v_table_names);
// Validate primary keys in the source table
ValidatePrimaryKeyInTable(catalog, context, info->schema, edge_table->source_reference, edge_table->source_pk);

// Validate primary keys in the destination table
ValidatePrimaryKeyInTable(catalog, context, info->schema, edge_table->destination_reference, edge_table->destination_pk);
// Validate destination table registration
ValidateVertexTableRegistration(edge_table->destination_reference, v_table_names);

// Validate primary keys in the destination table
ValidatePrimaryKeyInTable(catalog, context, info->schema, edge_table->destination_reference, edge_table->destination_pk);
} catch (CatalogException &e) {
auto table = catalog.GetEntry<ViewCatalogEntry>(context, info->schema, edge_table->table_name, OnEntryNotFound::RETURN_NULL);
if (table) {
throw Exception(ExceptionType::INVALID, "Found a view with name " + edge_table->table_name + ". Creating property graph tables over views is currently not supported.");
}
throw Exception(ExceptionType::INVALID, e.what());
}
}
return make_uniq<CreatePropertyGraphBindData>(info);
}
Expand Down
14 changes: 14 additions & 0 deletions test/sql/create_pg/create_pg_on_view.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ CREATE TABLE w(id TEXT PRIMARY KEY);
statement ok
CREATE TABLE v_w(v_id TEXT, w_id TEXT);

statement ok
create view v_w_view as select * from v_w;

statement error
-CREATE PROPERTY GRAPH g1
VERTEX TABLES (v, w)
Expand All @@ -24,3 +27,14 @@ statement error
);
----
Invalid Error: Found a view with name v. Creating property graph tables over views is currently not supported.

statement error
-CREATE PROPERTY GRAPH g1
VERTEX TABLES (vdata, w)
EDGE TABLES (
v_w_view SOURCE KEY (v_id) REFERENCES vdata (id)
DESTINATION KEY (w_id) REFERENCES w (id)
LABEL hasW
);
----
Invalid Error: Found a view with name v_w_view. Creating property graph tables over views is currently not supported.

0 comments on commit ac29e24

Please sign in to comment.