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

Improve error message for empty ColumnAggregation(s) #3242

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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