-
Notifications
You must be signed in to change notification settings - Fork 31
Add refactor.mergeNodes
procedure
#623
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
base: main
Are you sure you want to change the base?
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
refactor.mergeNodes
procedure
Pull request type
Related issuesDelete if this PR doesn't resolve any issues. Link the issue if it does. ###################################### Reviewer checklist (the reviewer checks this part)Module/Algorithm
Documentation checklist
|
|
||
try { | ||
const auto nodes = arguments[0].ValueList(); | ||
const auto config = arguments[1].ValueMap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create local variable when you use it for the first time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it now fine?
bool mergeRels = false; | ||
if (config.KeyExists(kMergeNodesRelationshipsStrategy)) { | ||
if (!config.At(kMergeNodesRelationshipsStrategy).IsBool()) { | ||
throw mgp::ValueException(std::string(kMergeRelationshipsInvalidValueError).c_str()); | ||
} | ||
|
||
mergeRels = config.At(kMergeNodesRelationshipsStrategy).ValueBool(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool mergeRels = false; | |
if (config.KeyExists(kMergeNodesRelationshipsStrategy)) { | |
if (!config.At(kMergeNodesRelationshipsStrategy).IsBool()) { | |
throw mgp::ValueException(std::string(kMergeRelationshipsInvalidValueError).c_str()); | |
} | |
mergeRels = config.At(kMergeNodesRelationshipsStrategy).ValueBool(); | |
} | |
if (config.KeyExists(kMergeNodesRelationshipsStrategy) && !config.At(kMergeNodesRelationshipsStrategy).IsBool()) { | |
throw mgp::ValueException(std::string(kMergeRelationshipsInvalidValueError).c_str()); | |
} | |
bool mergeRels = config.At(kMergeNodesRelationshipsStrategy).ValueBool(); | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we didn't handle here the part where the value in config doesn't exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didn't change anything here because of that reason, so just leaving for discussion of that edge case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, use IIFE then to initialize boolean
auto source_node = nodes[i].ValueNode(); | ||
|
||
// Get properties strategy from config | ||
std::string prop_strategy = std::string(kMergeNodesPropertiesCombine); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put that outside the loop to avoid creating strings all the time
if (config.KeyExists(kMergeNodesPropertiesStrategy)) { | ||
prop_strategy = config.At(kMergeNodesPropertiesStrategy).ValueString(); | ||
} | ||
if (config.KeyExists(kMergeNodesPropertiesStrategyAlternative)) { | ||
prop_strategy = config.At(kMergeNodesPropertiesStrategyAlternative).ValueString(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can also be outside the loop
std::transform(prop_strategy.begin(), prop_strategy.end(), prop_strategy.begin(), ::tolower); | ||
// Validate property strategy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use cpp std::transform(s.begin(), s.end(), s.begin(),
[](unsigned char c) { return std::tolower(c); });
if (prop_strategy != std::string(kMergeNodesPropertiesCombine) && | ||
prop_strategy != std::string(kMergeNodesPropertiesDiscard) && | ||
prop_strategy != std::string(kMergeNodesPropertiesOverride) && | ||
prop_strategy != std::string(kMergeNodesPropertiesOverwrite)) { | ||
throw mgp::ValueException(std::string(kMergeNodesInvalidPropertyStrategyError).c_str()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out side the loop
} | ||
|
||
// Handle properties based on strategy | ||
if (prop_strategy == std::string(kMergeNodesPropertiesCombine)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string creation outside the loop
target_node.SetProperty(key, source_props[key]); | ||
} | ||
} | ||
} else if (prop_strategy == std::string(kMergeNodesPropertiesDiscard)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string creation outside the loop
} else if (prop_strategy == std::string(kMergeNodesPropertiesOverride) || | ||
prop_strategy == std::string(kMergeNodesPropertiesOverwrite)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string creation outside the loop
bool mergeRels = false; | ||
if (config.KeyExists(kMergeNodesRelationshipsStrategy)) { | ||
if (!config.At(kMergeNodesRelationshipsStrategy).IsBool()) { | ||
throw mgp::ValueException(std::string(kMergeRelationshipsInvalidValueError).c_str()); | ||
} | ||
|
||
mergeRels = config.At(kMergeNodesRelationshipsStrategy).ValueBool(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, use IIFE then to initialize boolean
auto source_props = source_node.Properties(); | ||
for (const auto &[key, value] : source_props) { | ||
if (!source_props.contains(key)) { | ||
// nothing to combine | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is wrong. You are iterating over source_props key-value pairs and checking source_props contains key
} else if (prop_strategy == mergeNodesPropertiesDiscardString) { | ||
// Keep only target node properties | ||
// No action needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to specify empty block, don't use else if then, write the comment about this case
// Copy labels from source to target | ||
auto source_labels = source_node.Labels(); | ||
for (size_t j = 0; j < source_labels.Size(); ++j) { | ||
target_node.AddLabel(source_labels[j]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you can move label?
|
Add
refactor.mergeNodes
procedure