Skip to content

Commit

Permalink
Fixed reads and hybrid mode + optimized it
Browse files Browse the repository at this point in the history
  • Loading branch information
EinsamHauer committed Mar 22, 2018
1 parent b510644 commit c643654
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>net.iponweb.disthene.reader</groupId>
<artifactId>disthene-reader</artifactId>
<packaging>jar</packaging>
<version>1.0.3</version>
<version>1.0.4</version>
<name>disthene-reader</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,12 @@ private static class SinglePathResult {
String json;
Double[] values = null;
boolean allNulls = true;
boolean isSumMetric;

private SinglePathResult(String path) {
this.path = path;
// trying to optimize something that JIT should do. Probably redundant
this.isSumMetric = isSumMetric(path);
}

public String getPath() {
Expand All @@ -251,30 +254,21 @@ boolean isAllNulls() {
}

void makeJson(List<ResultSet> resultSets, int length, Map<Long, Integer> timestampIndices) {
Double values[] = new Double[length];

// todo: in fact we assume here that there will be no simultaneous writes, which may not be true, resulting in a one data point glitch
for (ResultSet resultSet : resultSets) {
for (Row row : resultSet) {
allNulls = false;
values[timestampIndices.get(row.getLong("time"))] =
isSumMetric(path) ? CollectionUtils.unsafeSum(row.getList("data", Double.class)) : CollectionUtils.unsafeAverage(row.getList("data", Double.class));
}
}

makeArray(resultSets, length, timestampIndices);
json = new Gson().toJson(values);
}

void makeArray(List<ResultSet> resultSets, int length, Map<Long, Integer> timestampIndices) {
values = new Double[length];

// todo: in fact we assume here that there will be no simultaneous writes, which may not be true, resulting in a one data point glitch
for (ResultSet resultSet : resultSets) {
if (resultSet.getAvailableWithoutFetching() > 0) {
for (Row row : resultSet) {
allNulls = false;
for (Row row : resultSet) {
values[timestampIndices.get(row.getLong("time"))] =
isSumMetric(path) ? CollectionUtils.unsafeSum(row.getList("data", Double.class)) : CollectionUtils.unsafeAverage(row.getList("data", Double.class));
int index = timestampIndices.get(row.getLong("time"));
if (isSumMetric) {
values[index] = (values[index] != null ? values[index] : 0) + CollectionUtils.unsafeSum(row.getList("data", Double.class));
} else {
values[index] = CollectionUtils.unsafeAverage(row.getList("data", Double.class));
}
}
}
Expand Down

0 comments on commit c643654

Please sign in to comment.