Skip to content

Commit

Permalink
Add catalog to property graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Dtenwolde committed Nov 7, 2024
1 parent 1b4ddbe commit 6f60830
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
8 changes: 6 additions & 2 deletions src/include/duckdb/parser/property_graph_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ class PropertyGraphTable {
//! Used for Copy
PropertyGraphTable();
//! Specify both the column and table name
PropertyGraphTable(string table_name, vector<string> column_name, vector<string> label, string catalog_name = "", string schema = DEFAULT_SCHEMA);
PropertyGraphTable(string table_name, vector<string> column_name,
vector<string> label, string catalog_name = "",
string schema = DEFAULT_SCHEMA);
//! Specify both the column and table name with alias
PropertyGraphTable(string table_name, string table_alias, vector<string> column_name, vector<string> label, string catalog_name = "", string schema = DEFAULT_SCHEMA);
PropertyGraphTable(string table_name, string table_alias,
vector<string> column_name, vector<string> label,
string catalog_name = "", string schema = DEFAULT_SCHEMA);
string catalog_name;
string schema_name;
string table_name;
Expand Down
78 changes: 43 additions & 35 deletions src/parser/property_graph_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ PropertyGraphTable::PropertyGraphTable(string table_name_p, string table_name_al
}

string PropertyGraphTable::ToString() const {
string result = schema_name + "." + table_name + " " + (table_name_alias.empty() ? "" : "AS " + table_name_alias);
string result = (catalog_name.empty() ? "" : catalog_name + ".") + schema_name + "."
+ table_name + " " + (table_name_alias.empty() ? "" : "AS " + table_name_alias);
if (!is_vertex_table) {
result += " SOURCE KEY (";
for (idx_t i = 0; i < source_fk.size(); i++) {
Expand Down Expand Up @@ -109,6 +110,9 @@ string PropertyGraphTable::ToString() const {
bool PropertyGraphTable::Equals(const PropertyGraphTable *other_p) const {

auto other = (PropertyGraphTable *)other_p;
if (catalog_name != other->catalog_name) {
return false;
}
if (schema_name != other->schema_name) {
return false;
}
Expand Down Expand Up @@ -213,55 +217,58 @@ bool PropertyGraphTable::Equals(const PropertyGraphTable *other_p) const {
}

void PropertyGraphTable::Serialize(Serializer &serializer) const {
serializer.WriteProperty(100, "schema_name", schema_name);
serializer.WriteProperty(100, "catalog_name", catalog_name);

serializer.WriteProperty(101, "schema_name", schema_name);

serializer.WriteProperty(101, "table_name", table_name);
serializer.WriteProperty(102, "table_name_alias", table_name_alias); // alias (not used for now)
serializer.WriteProperty(103, "column_names", column_names);
serializer.WriteProperty(104, "column_aliases", column_aliases);
serializer.WriteProperty(105, "except_columns", except_columns);
serializer.WriteProperty(106, "sub_labels", sub_labels);
serializer.WriteProperty(102, "table_name", table_name);
serializer.WriteProperty(103, "table_name_alias", table_name_alias); // alias (not used for now)
serializer.WriteProperty(104, "column_names", column_names);
serializer.WriteProperty(105, "column_aliases", column_aliases);
serializer.WriteProperty(106, "except_columns", except_columns);
serializer.WriteProperty(107, "sub_labels", sub_labels);

serializer.WriteProperty(107, "main_label", main_label);
serializer.WriteProperty(108, "is_vertex_table", is_vertex_table);
serializer.WriteProperty(109, "all_columns", all_columns);
serializer.WriteProperty(110, "no_columns", no_columns);
serializer.WriteProperty(108, "main_label", main_label);
serializer.WriteProperty(109, "is_vertex_table", is_vertex_table);
serializer.WriteProperty(110, "all_columns", all_columns);
serializer.WriteProperty(111, "no_columns", no_columns);

if (!is_vertex_table) {
serializer.WriteProperty(111, "source_pk", source_pk);
serializer.WriteProperty(112, "source_fk", source_fk);
serializer.WriteProperty(113, "source_reference", source_reference);
serializer.WriteProperty(112, "source_pk", source_pk);
serializer.WriteProperty(113, "source_fk", source_fk);
serializer.WriteProperty(114, "source_reference", source_reference);

serializer.WriteProperty(114, "destination_pk", destination_pk);
serializer.WriteProperty(115, "destination_fk", destination_fk);
serializer.WriteProperty(116, "destination_reference", destination_reference);
serializer.WriteProperty(115, "destination_pk", destination_pk);
serializer.WriteProperty(116, "destination_fk", destination_fk);
serializer.WriteProperty(117, "destination_reference", destination_reference);
}
}

shared_ptr<PropertyGraphTable> PropertyGraphTable::Deserialize(Deserializer &deserializer) {
auto pg_table = make_shared_ptr<PropertyGraphTable>();
deserializer.ReadProperty(100, "schema_name", pg_table->schema_name);
deserializer.ReadProperty(100, "catalog_name", pg_table->catalog_name);
deserializer.ReadProperty(101, "schema_name", pg_table->schema_name);

deserializer.ReadProperty(101, "table_name", pg_table->table_name);
deserializer.ReadProperty(102, "table_name_alias", pg_table->table_name_alias);
deserializer.ReadProperty(103, "column_names", pg_table->column_names);
deserializer.ReadProperty(104, "column_aliases", pg_table->column_aliases);
deserializer.ReadProperty(105, "except_columns", pg_table->except_columns);
deserializer.ReadProperty(106, "sub_labels", pg_table->sub_labels);
deserializer.ReadProperty(102, "table_name", pg_table->table_name);
deserializer.ReadProperty(103, "table_name_alias", pg_table->table_name_alias);
deserializer.ReadProperty(104, "column_names", pg_table->column_names);
deserializer.ReadProperty(105, "column_aliases", pg_table->column_aliases);
deserializer.ReadProperty(106, "except_columns", pg_table->except_columns);
deserializer.ReadProperty(107, "sub_labels", pg_table->sub_labels);

deserializer.ReadProperty(107, "main_label", pg_table->main_label);
deserializer.ReadProperty(108, "is_vertex_table", pg_table->is_vertex_table);
deserializer.ReadProperty(109, "all_columns", pg_table->all_columns);
deserializer.ReadProperty(110, "no_columns", pg_table->no_columns);
deserializer.ReadProperty(108, "main_label", pg_table->main_label);
deserializer.ReadProperty(109, "is_vertex_table", pg_table->is_vertex_table);
deserializer.ReadProperty(110, "all_columns", pg_table->all_columns);
deserializer.ReadProperty(111, "no_columns", pg_table->no_columns);

if (!pg_table->is_vertex_table) {
deserializer.ReadProperty(111, "source_pk", pg_table->source_pk);
deserializer.ReadProperty(112, "source_fk", pg_table->source_fk);
deserializer.ReadProperty(113, "source_reference", pg_table->source_reference);
deserializer.ReadProperty(112, "source_pk", pg_table->source_pk);
deserializer.ReadProperty(113, "source_fk", pg_table->source_fk);
deserializer.ReadProperty(114, "source_reference", pg_table->source_reference);

deserializer.ReadProperty(114, "destination_pk", pg_table->destination_pk);
deserializer.ReadProperty(115, "destination_fk", pg_table->destination_fk);
deserializer.ReadProperty(116, "destination_reference", pg_table->destination_reference);
deserializer.ReadProperty(115, "destination_pk", pg_table->destination_pk);
deserializer.ReadProperty(116, "destination_fk", pg_table->destination_fk);
deserializer.ReadProperty(117, "destination_reference", pg_table->destination_reference);
}
return pg_table;
}
Expand All @@ -282,6 +289,7 @@ bool PropertyGraphTable::IsSourceTable(const string& table_name) {

shared_ptr<PropertyGraphTable> PropertyGraphTable::Copy() const {
auto result = make_shared_ptr<PropertyGraphTable>();
result->catalog_name = catalog_name;
result->schema_name = schema_name;
result->table_name = table_name;
result->table_name_alias = table_name_alias;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Transformer::TransformPropertyGraphTable(duckdb_libpgquery::PGPropertyGraphTable
}

auto pg_table = make_shared_ptr<PropertyGraphTable>(transformed_name.name,
table_name_alias, column_names, label_names, transformed_name.schema);
table_name_alias, column_names, label_names, transformed_name.catalog, transformed_name.schema);

pg_table->is_vertex_table = graph_table->is_vertex_table;
pg_table->except_columns = std::move(except_list);
Expand Down

0 comments on commit 6f60830

Please sign in to comment.