Skip to content

Commit

Permalink
Add catalog information
Browse files Browse the repository at this point in the history
  • Loading branch information
Dtenwolde committed Nov 4, 2024
1 parent bc77b88 commit c8526e6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 73 deletions.
7 changes: 4 additions & 3 deletions src/include/duckdb/parser/property_graph_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ class PropertyGraphTable {
//! Used for Copy
PropertyGraphTable();
//! Specify both the column and table name
PropertyGraphTable(string table_name, vector<string> column_name, vector<string> label);
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);

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;
string table_name_alias;

Expand Down
116 changes: 50 additions & 66 deletions src/parser/property_graph_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ namespace duckdb {

PropertyGraphTable::PropertyGraphTable() = default;

PropertyGraphTable::PropertyGraphTable(string table_name_p, vector<string> column_names_p, vector<string> labels_p)
: table_name(std::move(table_name_p)), column_names(std::move(column_names_p)), sub_labels(std::move(labels_p)) {
PropertyGraphTable::PropertyGraphTable(string table_name_p, vector<string> column_names_p,
vector<string> labels_p, string catalog_p, string schema_p)
: table_name(std::move(table_name_p)), catalog_name(std::move(catalog_p)), schema_name(std::move(schema_p)),
column_names(std::move(column_names_p)), sub_labels(std::move(labels_p)) {

#ifdef DEBUG
for (auto &col_name : column_names) {
Expand All @@ -21,8 +23,8 @@ PropertyGraphTable::PropertyGraphTable(string table_name_p, vector<string> colum
}

PropertyGraphTable::PropertyGraphTable(string table_name_p, string table_name_alias_p, vector<string> column_names_p,
vector<string> labels_p)
: table_name(std::move(table_name_p)), table_name_alias(std::move(table_name_alias_p)),
vector<string> labels_p, string catalog_p, string schema_p)
: table_name(std::move(table_name_p)), catalog_name(std::move(catalog_p)), table_name_alias(std::move(table_name_alias_p)), schema_name(std::move(schema_p)),
column_names(std::move(column_names_p)), sub_labels(std::move(labels_p)) {
#ifdef DEBUG
for (auto &col_name : column_names) {
Expand All @@ -39,7 +41,7 @@ PropertyGraphTable::PropertyGraphTable(string table_name_p, string table_name_al
}

string PropertyGraphTable::ToString() const {
string result = table_name + " " + (table_name_alias.empty() ? "" : "AS " + table_name_alias);
string result = 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 @@ -107,6 +109,9 @@ string PropertyGraphTable::ToString() const {
bool PropertyGraphTable::Equals(const PropertyGraphTable *other_p) const {

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

void PropertyGraphTable::Serialize(Serializer &serializer) const {
serializer.WriteProperty(100, "table_name", table_name);
serializer.WriteProperty(101, "table_name", table_name); // alias (not used for now)
serializer.WriteProperty(102, "column_names", column_names);
serializer.WriteProperty(103, "column_aliases", column_aliases);
serializer.WriteProperty(104, "except_columns", except_columns);
serializer.WriteProperty(105, "sub_labels", sub_labels);

serializer.WriteProperty(106, "main_label", main_label);
serializer.WriteProperty(107, "is_vertex_table", is_vertex_table);
serializer.WriteProperty(108, "all_columns", all_columns);
serializer.WriteProperty(109, "no_columns", no_columns);
serializer.WriteProperty(100, "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(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);

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

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

shared_ptr<PropertyGraphTable> PropertyGraphTable::Deserialize(Deserializer &deserializer) {
auto pg_table = make_shared_ptr<PropertyGraphTable>();
deserializer.ReadProperty(100, "table_name", pg_table->table_name);
deserializer.ReadProperty(101, "table_name", pg_table->table_name_alias);
deserializer.ReadProperty(102, "column_names", pg_table->column_names);
deserializer.ReadProperty(103, "column_aliases", pg_table->column_aliases);
deserializer.ReadProperty(104, "except_columns", pg_table->except_columns);
deserializer.ReadProperty(105, "sub_labels", pg_table->sub_labels);

deserializer.ReadProperty(106, "main_label", pg_table->main_label);
deserializer.ReadProperty(107, "is_vertex_table", pg_table->is_vertex_table);
deserializer.ReadProperty(108, "all_columns", pg_table->all_columns);
deserializer.ReadProperty(109, "no_columns", pg_table->no_columns);
deserializer.ReadProperty(100, "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(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);

if (!pg_table->is_vertex_table) {
deserializer.ReadProperty(110, "source_pk", pg_table->source_pk);
deserializer.ReadProperty(111, "source_fk", pg_table->source_fk);
deserializer.ReadProperty(112, "source_reference", pg_table->source_reference);
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(113, "destination_pk", pg_table->destination_pk);
deserializer.ReadProperty(114, "destination_fk", pg_table->destination_fk);
deserializer.ReadProperty(115, "destination_reference", pg_table->destination_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);
}
return pg_table;
}
Expand All @@ -273,7 +282,7 @@ bool PropertyGraphTable::IsSourceTable(const string& table_name) {

shared_ptr<PropertyGraphTable> PropertyGraphTable::Copy() const {
auto result = make_shared_ptr<PropertyGraphTable>();

result->schema_name = schema_name;
result->table_name = table_name;
result->table_name_alias = table_name_alias;
for (auto &column_name : column_names) {
Expand Down Expand Up @@ -314,29 +323,4 @@ shared_ptr<PropertyGraphTable> PropertyGraphTable::Copy() const {
return result;
}

} // namespace duckdb

// void PropertyGraphTable::Serialize(Serializer &serializer) const {
// FieldWriter writer(serializer);
// writer.WriteString(table_name);
//
// writer.WriteList<string>(column_names);
// writer.WriteList<string>(column_aliases);
// writer.WriteList<string>(except_columns);
// writer.WriteList<string>(sub_labels);
// writer.WriteString(main_label);
//
// writer.WriteField<bool>(is_vertex_table);
// writer.WriteField<bool>(all_columns);
// writer.WriteField<bool>(no_columns);
// if (!is_vertex_table) {
// writer.WriteList<string>(source_pk);
// writer.WriteList<string>(source_fk);
// writer.WriteString(source_reference);
//
// writer.WriteList<string>(destination_pk);
// writer.WriteList<string>(destination_fk);
// writer.WriteString(destination_reference);
// }
// writer.Finalize();
//}
} // namespace duckdb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Transformer::TransformPropertyGraphTable(duckdb_libpgquery::PGPropertyGraphTable
vector<string> label_names;

auto table_name = reinterpret_cast<duckdb_libpgquery::PGRangeVar *>(graph_table->table->head->data.ptr_value);
auto graph_table_name = TransformQualifiedName(*table_name).name;
auto transformed_name = TransformQualifiedName(*table_name);
string table_name_alias =
reinterpret_cast<duckdb_libpgquery::PGValue *>(graph_table->table->head->next->data.ptr_value)->val.str;
if (!table_name_alias.empty()) {
table_alias_map[table_name_alias] = graph_table_name;
table_alias_map[table_name_alias] = transformed_name.name;
}

bool all_columns = false;
Expand Down Expand Up @@ -53,7 +53,7 @@ Transformer::TransformPropertyGraphTable(duckdb_libpgquery::PGPropertyGraphTable
D_ASSERT(label->type == duckdb_libpgquery::T_PGString);
std::string label_str;
if (label->val.str == nullptr) {
label_str = graph_table_name;
label_str = transformed_name.name;
} else {
label_str = label->val.str;
}
Expand All @@ -65,7 +65,8 @@ Transformer::TransformPropertyGraphTable(duckdb_libpgquery::PGPropertyGraphTable
label_names.emplace_back(label_str);
}

auto pg_table = make_shared_ptr<PropertyGraphTable>(graph_table_name, table_name_alias, column_names, label_names);
auto pg_table = make_shared_ptr<PropertyGraphTable>(transformed_name.name,
table_name_alias, column_names, label_names, 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 c8526e6

Please sign in to comment.