Skip to content

Commit

Permalink
Merge pull request #202 from cwida/123-udf-for-clustering-coefficient
Browse files Browse the repository at this point in the history
Adds helper functions to property graph
  • Loading branch information
Dtenwolde authored Jun 29, 2024
2 parents 6d727d0 + 87840f4 commit 6a998d8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
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

0 comments on commit 6a998d8

Please sign in to comment.