Skip to content

Commit

Permalink
Handle empty counter results.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuetschard committed Jul 26, 2019
1 parent 5b9df9b commit 9e9a3ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ protected ListenableFuture<Data> computeData(QueryEngine qe, DataRequest req) {
private ListenableFuture<Data> computeData(QueryEngine qe, DataRequest req, Window win) {
return transform(qe.query(win.quantized ? summarySql() : counterSQL()), res -> {
int rows = res.getNumRows();
if (rows == 0) {
return Data.empty(req);
}

Data data = new Data(req, new long[rows + 1], new double[rows + 1]);
res.forEachRow((i, r) -> {
data.ts[i] = r.getLong(0);
Expand Down Expand Up @@ -134,6 +138,10 @@ public Data(DataRequest request, long[] ts, double[] values) {
this.ts = ts;
this.values = values;
}

public static Data empty(DataRequest req) {
return new Data(req, new long[0], new double[0]);
}
}

public static class Values implements Selection, Selection.CombiningBuilder.Combinable<Values> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ protected ListenableFuture<Data> computeData(QueryEngine qe, DataRequest req) {
private ListenableFuture<Data> computeData(QueryEngine qe, DataRequest req, Window win) {
return transform(qe.query(win.quantized ? summarySql() : counterSQL()), res -> {
int rows = res.getNumRows();
if (rows == 0) {
return Data.empty(req);
}

Data data = new Data(
req, new long[rows + 1], new long[rows + 1], new long[rows + 1], new long[rows + 1]);
res.forEachRow((i, r) -> {
Expand Down Expand Up @@ -162,5 +166,9 @@ public Data(DataRequest request, long[] ts, long[] total, long[] unusued, long[]
this.unused = unusued;
this.buffCache = buffCache;
}

public static Data empty(DataRequest req) {
return new Data(req, new long[0], new long[0], new long[0], new long[0]);
}
}
}

0 comments on commit 9e9a3ff

Please sign in to comment.