Skip to content

Commit

Permalink
Improve error message for empty ColumnAggregation(s) (#3242)
Browse files Browse the repository at this point in the history
Provides better developer experience, see #3235
  • Loading branch information
devinrsmith authored Jan 11, 2023
1 parent c4dfb04 commit 845f50d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions table-api/src/main/java/io/deephaven/api/agg/Aggregation.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ static Aggregation of(AggSpec spec, String... pairs) {
* @return The aggregation
*/
static Aggregation of(AggSpec spec, List<String> pairs) {
if (pairs.isEmpty()) {
throw new IllegalArgumentException(
"Must have at least one pair to create an Aggregation from an AggSpec. Did you mean to use TableOperations#aggAllBy?");
}
if (pairs.size() == 1) {
return of(spec, pairs.get(0));
}
Expand All @@ -89,6 +93,9 @@ static Aggregation of(AggSpec spec, List<String> pairs) {
* @return The combined aggregation
*/
static Aggregation of(Aggregation... aggregations) {
if (aggregations.length == 0) {
throw new IllegalArgumentException("Unable to create an empty aggregation.");
}
if (aggregations.length == 1) {
return aggregations[0];
}
Expand All @@ -108,6 +115,9 @@ static Aggregation of(Aggregation... aggregations) {
@SafeVarargs
static <INPUT_TYPE> Aggregation of(BiFunction<ColumnName, INPUT_TYPE, ColumnAggregation> columnAggFactory,
String inputColumn, INPUT_TYPE... inputs) {
if (inputs.length == 0) {
throw new IllegalArgumentException("Unable to create an empty aggregation.");
}
final ColumnName inputColumnName = ColumnName.of(inputColumn);
if (inputs.length == 1) {
return columnAggFactory.apply(inputColumnName, inputs[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public final <V extends Visitor> V walk(V visitor) {
@Check
final void checkSize() {
if (aggregations().size() < 2) {
throw new IllegalArgumentException(
String.format("%s should have at least two aggregations", Aggregations.class));
throw new IllegalArgumentException(String.format("%s should have at least two aggregations, has %d",
Aggregations.class, aggregations().size()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public final <V extends Visitor> V walk(V visitor) {
@Check
final void checkSize() {
if (pairs().size() < 2) {
throw new IllegalArgumentException(
String.format("%s should have at least two pairs", ColumnAggregations.class));
throw new IllegalArgumentException(String.format("%s should have at least two pairs, has %d",
ColumnAggregations.class, pairs().size()));
}
}

Expand Down

0 comments on commit 845f50d

Please sign in to comment.