Skip to content

Commit

Permalink
Avoid double computing the expressions for the /query/exp endpoint.
Browse files Browse the repository at this point in the history
Also make sure both versions of next() handle booleans.

Signed-off-by: Chris Larsen <clarsen@yahoo-inc.com>
  • Loading branch information
manolama committed Jan 30, 2017
1 parent cac608a commit a6a9ec4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/query/expression/ExpressionIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ public ExpressionDataPoint[] next(final long timestamp) {
}
final Object output = expression.execute(context);
if (output instanceof Double) {
result = (Double) expression.execute(context);
result = (Double) output;
} else if (output instanceof Boolean) {
result = (((Boolean) expression.execute(context)) ? 1 : 0);
result = (((Boolean) output) ? 1 : 0);
} else {
throw new IllegalStateException("Expression returned a result of type: "
+ output.getClass().getName() + " for " + this);
Expand Down Expand Up @@ -465,7 +465,15 @@ public void next(final int i) {
}
}
}
result = (Double)expression.execute(context);
final Object output = expression.execute(context);
if (output instanceof Double) {
result = (Double) output;
} else if (output instanceof Boolean) {
result = (((Boolean) output) ? 1 : 0);
} else {
throw new IllegalStateException("Expression returned a result of type: "
+ output.getClass().getName() + " for " + this);
}
dps[i].reset(ts, result);
}

Expand Down

0 comments on commit a6a9ec4

Please sign in to comment.