Skip to content

Commit

Permalink
[NOID] Update argument descriptions for APOC Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gem-neo4j committed Aug 28, 2024
1 parent 337cd10 commit bb114bb
Show file tree
Hide file tree
Showing 33 changed files with 1,119 additions and 362 deletions.
25 changes: 19 additions & 6 deletions core/src/main/java/apoc/agg/CollAggregation.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ public static class NthFunction {
private int index;

@UserAggregationUpdate
public void nth(@Name("value") Object value, @Name("offset") long target) {
public void nth(
@Name(value = "value", description = "A value to be aggregated.") Object value,
@Name(
value = "offset",
description = "The index of the value to be returned, or -1 to return the last item.")
long target) {
if (value != null) {
if (target == index++ || target == -1) {
this.value = value;
Expand All @@ -81,9 +86,17 @@ public static class SliceFunction {

@UserAggregationUpdate
public void nth(
@Name("value") Object value,
@Name(value = "from", defaultValue = "0") long from,
@Name(value = "to", defaultValue = "-1") long len) {
@Name(value = "value", description = "A value to be multiplied in the aggregate.") Object value,
@Name(
value = "from",
defaultValue = "0",
description = "The index from which to start returning values in the specified range?")
long from,
@Name(
value = "to",
defaultValue = "-1",
description = "The non-inclusive index of the final value in the range.")
long len) {
if (value != null) {
if (index >= from && (len == -1 || index < from + len)) {
this.values.add(value);
Expand All @@ -102,7 +115,7 @@ public static class FirstFunction {
private Object value;

@UserAggregationUpdate
public void first(@Name("value") Object value) {
public void first(@Name(value = "value", description = "A value to be aggregated.") Object value) {
if (value != null && this.value == null) {
this.value = value;
}
Expand All @@ -118,7 +131,7 @@ public static class LastFunction {
private Object value;

@UserAggregationUpdate
public void last(@Name("value") Object value) {
public void last(@Name(value = "value", description = "A value to be aggregated.") Object value) {
if (value != null) {
this.value = value;
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/apoc/agg/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public static class GraphAggregation {
private Set<Relationship> plainRels = new HashSet<>();

@UserAggregationUpdate
public void aggregate(@Name("path") Object element) {
public void aggregate(
@Name(value = "path", description = "A path to return nodes and relationships from.") Object element) {
consume(element);
}

Expand Down
68 changes: 55 additions & 13 deletions core/src/main/java/apoc/agg/MaxAndMinItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,41 +53,83 @@ public class MaxAndMinItems {
@UserAggregationFunction("apoc.agg.maxItems")
@Description(
"Returns a `MAP` `{items: LIST<ANY>, value: ANY}` where the `value` key is the maximum value present, and `items` represent all items with the same value. The size of the list of items can be limited to a given max size.")
public MaxOrMinItemsFunction maxItems() {
return new MaxOrMinItemsFunction(true);
public MaxItemsFunction maxItems() {
return new MaxItemsFunction();
}

@UserAggregationFunction("apoc.agg.minItems")
@Description(
"Returns a `MAP` `{items: LIST<ANY>, value: ANY}` where the `value` key is the minimum value present, and `items` represent all items with the same value. The size of the list of items can be limited to a given max size.")
public MaxOrMinItemsFunction minItems() {
return new MaxOrMinItemsFunction(false);
public MinItemsFunction minItems() {
return new MinItemsFunction();
}

public static class MaxOrMinItemsFunction {
public static class MaxItemsFunction {
private final List<Object> items = new ArrayList<>();
private final boolean isMax;
private Comparable value;

private MaxOrMinItemsFunction(boolean isMax) {
this.isMax = isMax;
private MaxItemsFunction() {}

@UserAggregationUpdate
public void maxOrMinItems(
@Name(value = "item", description = "A value to be aggregated.") final Object item,
@Name(value = "value", description = "The value from which the max is selected.")
final Object inputValue,
@Name(
value = "groupLimit",
defaultValue = "-1",
description = "The limit on the number of items returned.")
final Long groupLimitParam) {
int groupLimit = groupLimitParam.intValue();
boolean noGroupLimit = groupLimit < 0;

if (item != null && inputValue != null) {
int result = value == null ? -1 : value.compareTo(inputValue);
if (result == 0) {
if (noGroupLimit || items.size() < groupLimit) {
items.add(item);
}
} else if (result < 0) {
// xnor logic, interested value should replace current value
items.clear();
items.add(item);
value = (Comparable) inputValue;
}
}
}

@UserAggregationResult
public Object result() {
return Util.map("items", items, "value", value);
}
}

public static class MinItemsFunction {
private final List<Object> items = new ArrayList<>();
private Comparable value;

private MinItemsFunction() {}

@UserAggregationUpdate
public void maxOrMinItems(
@Name("items") final Object item,
@Name("value") final Object inputValue,
@Name(value = "groupLimit", defaultValue = "-1") final Long groupLimitParam) {
@Name(value = "item", description = "A value to be aggregated.") final Object item,
@Name(value = "value", description = "The value from which the min is selected.")
final Object inputValue,
@Name(
value = "groupLimit",
defaultValue = "-1",
description = "The limit on the number of items returned.")
final Long groupLimitParam) {
int groupLimit = groupLimitParam.intValue();
boolean noGroupLimit = groupLimit < 0;

if (item != null && inputValue != null) {
int result = value == null ? (isMax ? -1 : 1) : value.compareTo(inputValue);
int result = value == null ? 1 : value.compareTo(inputValue);
if (result == 0) {
if (noGroupLimit || items.size() < groupLimit) {
items.add(item);
}
} else if (result < 0 == isMax) {
} else if (result >= 0) {
// xnor logic, interested value should replace current value
items.clear();
items.add(item);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/apoc/agg/Median.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static class MedianFunction {
private List<Double> values = new ArrayList<>();

@UserAggregationUpdate
public void aggregate(@Name("value") Object value) {
public void aggregate(@Name(value = "value", description = "A value to be aggregated.") Object value) {
if (value instanceof Number) {
values.add(((Number) value).doubleValue());
}
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/java/apoc/agg/Percentiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ public static class PercentilesFunction {

@UserAggregationUpdate
public void aggregate(
@Name("value") Number value,
@Name(value = "percentiles", defaultValue = "[0.5,0.75,0.9,0.95,0.99]") List<Double> percentiles) {
@Name(value = "value", description = "A value to be aggregated.") Number value,
@Name(
value = "percentiles",
defaultValue = "[0.5,0.75,0.9,0.95,0.99]",
description = "The percentiles from which the values are obtained.")
List<Double> percentiles) {
if (value != null) {
if (doubles != null) {
doubles.recordValue(value.doubleValue());
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/apoc/agg/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public static class ProductFunction {
private int count = 0;

@UserAggregationUpdate
public void aggregate(@Name("value") Number number) {
public void aggregate(
@Name(value = "value", description = "A value to be multiplied in the aggregate.") Number number) {
if (number != null) {
if (number instanceof Long) {
longProduct = Math.multiplyExact(longProduct, number.longValue());
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/java/apoc/agg/Statistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ public static class StatisticsFunction {

@UserAggregationUpdate
public void aggregate(
@Name("value") Number value,
@Name(value = "percentiles", defaultValue = "[0.5,0.75,0.9,0.95,0.99]") List<Double> percentiles) {
@Name(value = "value", description = "A value to be aggregated.") Number value,
@Name(
value = "percentiles",
defaultValue = "[0.5,0.75,0.9,0.95,0.99]",
description = "The percentiles from which the values are obtained?")
List<Double> percentiles) {
if (value != null) {
if (doubles != null) {
doubles.recordValue(value.doubleValue());
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/java/apoc/bitwise/BitwiseOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public class BitwiseOperations {

@UserFunction("apoc.bitwise.op")
@Description("Returns the result of the bitwise operation")
public Long op(@Name("a") final Long a, @Name("operator") final String operator, @Name("b") final Long b)
public Long op(
@Name(value = "a", description = "The lefthand side value of the bitwise operation.") final Long a,
@Name(value = "operator", description = "The type of bitwise operation to perform.") final String operator,
@Name(value = "b", description = "The righthand side value of the bitwise operation.") final Long b)
throws Exception {
if (a == null || operator == null || operator.isEmpty()) {
return null;
Expand Down
Loading

0 comments on commit bb114bb

Please sign in to comment.