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

Add other types to give a more robust grouping proc #710

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

gem-neo4j
Copy link
Contributor

@gem-neo4j gem-neo4j force-pushed the fix_apoc_node_grouping branch from 58917ce to b179557 Compare December 23, 2024 12:22
@gem-neo4j gem-neo4j force-pushed the fix_apoc_node_grouping branch 5 times, most recently from fe586f3 to ce66ed6 Compare December 23, 2024 13:50
@gem-neo4j gem-neo4j marked this pull request as ready for review December 23, 2024 13:50
@gem-neo4j gem-neo4j force-pushed the fix_apoc_node_grouping branch from ce66ed6 to ce4da32 Compare January 2, 2025 07:03
@gem-neo4j gem-neo4j force-pushed the fix_apoc_node_grouping branch from ce4da32 to 9afc2fb Compare January 9, 2025 07:27
@gem-neo4j gem-neo4j force-pushed the fix_apoc_node_grouping branch from 9afc2fb to 45578eb Compare January 21, 2025 06:47
Copy link
Contributor

@loveleif loveleif left a comment

Choose a reason for hiding this comment

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

👍

@@ -368,6 +377,10 @@ private <C extends Collection<T>, T extends Entity> C fixAggregates(C pcs) {
double[] values = (double[]) v;
entry.setValue(values[1] == 0 ? 0 : values[0] / values[1]);
}
if (k.matches("^avg_.+") && v instanceof DurationValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Regexing the property name, not very rubust, but I guess this is the way of the apoc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Compiling a regex pattern is a bit expensive though (I don't think they're cached in java) so we could consider replacing this with k.startsWith("avg_") && k.size() > "avg_".length. Or to compile the Pattern once in a field and reuse.

Comment on lines 380 to 384
if (k.matches("^avg_.+") && v instanceof DurationValue) {
Long count = ((Number) pc.getProperty(k + "_count", 0)).longValue();
entry.setValue(divDurationValue((DurationValue) v, count));
}
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
if (k.matches("^avg_.+") && v instanceof DurationValue) {
Long count = ((Number) pc.getProperty(k + "_count", 0)).longValue();
entry.setValue(divDurationValue((DurationValue) v, count));
}
if (k.matches("^avg_.+") && v instanceof DurationValue duration) {
Long count = ((Number) pc.getProperty(k + "_count", 0)).longValue();
entry.setValue(divDurationValue(duration, count));
}

@@ -368,6 +377,10 @@ private <C extends Collection<T>, T extends Entity> C fixAggregates(C pcs) {
double[] values = (double[]) v;
entry.setValue(values[1] == 0 ? 0 : values[0] / values[1]);
}
if (k.matches("^avg_.+") && v instanceof DurationValue) {
Long count = ((Number) pc.getProperty(k + "_count", 0)).longValue();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it intentional to use .longValue() here? I thinking about Doubles for example, that will get rounded by that call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

APOC is the one that sets this value, so we know it is a long

Comment on lines 426 to 429
if (value instanceof DurationValue) {
DurationValue dv =
(DurationValue) pc.getProperty(key, DurationValue.duration(0, 0, 0, 0));
pc.setProperty(key, ((DurationValue) value).add(dv));
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
if (value instanceof DurationValue) {
DurationValue dv =
(DurationValue) pc.getProperty(key, DurationValue.duration(0, 0, 0, 0));
pc.setProperty(key, ((DurationValue) value).add(dv));
if (value instanceof DurationValue duration) {
DurationValue dv =
(DurationValue) pc.getProperty(key, DurationValue.duration(0, 0, 0, 0));
pc.setProperty(key, (duration.add(dv));

|| (prop instanceof PointValue && value instanceof PointValue);
}

private boolean compareValues(Object prop, Object value) {
Copy link
Contributor

@loveleif loveleif Jan 21, 2025

Choose a reason for hiding this comment

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

Could we use org.neo4j.values.storable.Values.COMPARATOR here to not have to maintain this in apoc?

return switch (Values.COMPARATOR.ternaryCompare(Value.of(a), Value.of(b))) {
  case UNDEFINED -> ...;
  case EQUAL -> ...;
  case GREATER_THAN -> ...;
  case SMALLER_THAN -> ...;
}

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 did not know this existed, looks interesting thanks! I'll play with it :D

@gem-neo4j gem-neo4j force-pushed the fix_apoc_node_grouping branch from 45578eb to aaff6e1 Compare January 22, 2025 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants