Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds helper functions to property graph #202

Merged
merged 5 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ struct CreatePropertyGraphInfo : public CreateInfo {
return result;
};

shared_ptr<PropertyGraphTable> GetTable(const string &table_name, bool error_not_found = true) {
auto entry = label_map.find(table_name);
if (entry == label_map.end()) {
if (error_not_found) {
throw Exception(ExceptionType::INVALID,
"Table " + table_name + " not found in property graph " + property_graph_name);
}
return nullptr;
}
return entry->second;
}

//! Serializes a blob into a CreatePropertyGraphInfo
void Serialize(Serializer &serializer) const override;
//! Deserializes a blob back into a CreatePropertyGraphInfo
Expand Down
4 changes: 4 additions & 0 deletions src/include/duckdb/parser/property_graph_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@ class PropertyGraphTable {
bool hasTableNameAlias() {
return !table_name_alias.empty();
}

string ToLower(const std::string &str);

bool IsSourceTable(const string &table_name);
};
} // namespace duckdb
14 changes: 14 additions & 0 deletions src/parser/property_graph_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,20 @@ shared_ptr<PropertyGraphTable> PropertyGraphTable::Deserialize(Deserializer &des
return pg_table;
}


// Helper function to convert a string to lowercase
string PropertyGraphTable::ToLower(const std::string &str) {
string result = str;
transform(result.begin(), result.end(), result.begin(),
[](unsigned char c){ return std::tolower(c); });
return result;
}


bool PropertyGraphTable::IsSourceTable(const string& table_name) {
return ToLower(this->source_reference) == ToLower(table_name);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ Transformer::TransformPropertyGraphTable(duckdb_libpgquery::PGPropertyGraphTable
} else {
pg_table->source_reference = possible_src_alias->second;
}

D_ASSERT(graph_table->dst_name);
auto dst_name = TransformQualifiedName(*graph_table->dst_name);
auto possible_dst_alias = table_alias_map.find(dst_name.name);
Expand Down
Loading