Skip to content

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

Josipmrden
Copy link
Contributor

@Josipmrden Josipmrden commented Jun 9, 2025

Add refactor.mergeNodes procedure

Copy link

coderabbitai bot commented Jun 9, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Josipmrden Josipmrden changed the title Add merge nodes procedure Add refactor.mergeNodes procedure Jun 16, 2025
@Josipmrden Josipmrden requested review from as51340 and DavIvek June 16, 2025 09:40
@Josipmrden Josipmrden self-assigned this Jun 16, 2025
@Josipmrden Josipmrden added this to the mage-v3.4.0 milestone Jun 16, 2025
@Josipmrden Josipmrden added the Docs needed Docs needed label Jun 16, 2025
@Josipmrden
Copy link
Contributor Author

Josipmrden commented Jun 16, 2025

Pull request type

  • Bugfix
  • Algorithm/Module
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Related issues

Delete if this PR doesn't resolve any issues. Link the issue if it does.

######################################

Reviewer checklist (the reviewer checks this part)

Module/Algorithm

  • Core algorithm/module implementation
  • Query module implementation
  • Tests provided (unit / e2e)
  • Code documentation
  • README short description

Documentation checklist

  • Add the documentation label tag
  • Add the bug / feature label tag
  • Add the milestone for which this feature is intended
    • If not known, set for a later milestone
  • Write a release note, including added/changed clauses
    • Added refactor.mergeNodes procedure #623
  • Link the documentation PR here
  • Tag someone from docs team in the comments @matea16

@Josipmrden Josipmrden marked this pull request as ready for review June 16, 2025 09:42

try {
const auto nodes = arguments[0].ValueList();
const auto config = arguments[1].ValueMap();
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it now fine?

Comment on lines 888 to 895
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();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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();

Copy link
Contributor Author

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?

Copy link
Contributor Author

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

Copy link
Contributor

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);
Copy link
Contributor

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

Comment on lines 906 to 911
if (config.KeyExists(kMergeNodesPropertiesStrategy)) {
prop_strategy = config.At(kMergeNodesPropertiesStrategy).ValueString();
}
if (config.KeyExists(kMergeNodesPropertiesStrategyAlternative)) {
prop_strategy = config.At(kMergeNodesPropertiesStrategyAlternative).ValueString();
}
Copy link
Contributor

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

Comment on lines 914 to 915
std::transform(prop_strategy.begin(), prop_strategy.end(), prop_strategy.begin(), ::tolower);
// Validate property strategy
Copy link
Contributor

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); });

Comment on lines 916 to 922
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());
}

Copy link
Contributor

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)) {
Copy link
Contributor

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)) {
Copy link
Contributor

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

Comment on lines 950 to 951
} else if (prop_strategy == std::string(kMergeNodesPropertiesOverride) ||
prop_strategy == std::string(kMergeNodesPropertiesOverwrite)) {
Copy link
Contributor

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

@Josipmrden Josipmrden requested a review from as51340 June 17, 2025 08:00
Comment on lines 888 to 895
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();
}
Copy link
Contributor

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

Comment on lines 930 to 935
auto source_props = source_node.Properties();
for (const auto &[key, value] : source_props) {
if (!source_props.contains(key)) {
// nothing to combine
continue;
}
Copy link
Contributor

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

Comment on lines 951 to 953
} else if (prop_strategy == mergeNodesPropertiesDiscardString) {
// Keep only target node properties
// No action needed
Copy link
Contributor

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]);
Copy link
Contributor

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?

@Josipmrden Josipmrden requested a review from as51340 June 17, 2025 14:49
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apoc customer customer Docs needed Docs needed feature feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants