-
Notifications
You must be signed in to change notification settings - Fork 29
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
base: dev
Are you sure you want to change the base?
Conversation
58917ce
to
b179557
Compare
fe586f3
to
ce66ed6
Compare
ce66ed6
to
ce4da32
Compare
ce4da32
to
9afc2fb
Compare
9afc2fb
to
45578eb
Compare
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.
👍
@@ -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) { |
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.
Regexing the property name, not very rubust, but I guess this is the way of the apoc.
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.
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.
if (k.matches("^avg_.+") && v instanceof DurationValue) { | ||
Long count = ((Number) pc.getProperty(k + "_count", 0)).longValue(); | ||
entry.setValue(divDurationValue((DurationValue) v, count)); | ||
} |
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.
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(); |
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 intentional to use .longValue()
here? I thinking about Double
s for example, that will get rounded by that call.
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.
APOC is the one that sets this value, so we know it is a long
if (value instanceof DurationValue) { | ||
DurationValue dv = | ||
(DurationValue) pc.getProperty(key, DurationValue.duration(0, 0, 0, 0)); | ||
pc.setProperty(key, ((DurationValue) value).add(dv)); |
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.
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) { |
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.
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 -> ...;
}
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 did not know this existed, looks interesting thanks! I'll play with it :D
45578eb
to
aaff6e1
Compare
#116