Skip to content

Commit

Permalink
Add findMetrics for all the temp tables also
Browse files Browse the repository at this point in the history
  • Loading branch information
burmanm committed Jul 4, 2017
1 parent 99f6758 commit 753a910
Showing 1 changed file with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public class DataAccessImpl implements DataAccess {
private PreparedStatement[] dateRangeExclusiveWithLimit;
private PreparedStatement[] dataByDateRangeExclusiveASC;
private PreparedStatement[] dataByDateRangeExclusiveWithLimitASC;
private PreparedStatement[] metricsInDatas;
private PreparedStatement[] allMetricsInDatas;

private PreparedStatement insertTenant;

Expand Down Expand Up @@ -276,13 +278,22 @@ private void createGaugeTempInserters() {
"SET n_value = ? " +
"WHERE tenant_id = ? AND type = ? AND metric = ? AND dpart = ? AND time = ? ";

String findMetricInDataBase = "SELECT DISTINCT tenant_id, type, metric, dpart " +
"FROM data_temp_%d " +
"WHERE tenant_id = ? AND type = ? AND metric = ? AND dpart = ? ";

String findAllMetricsInDataBases = "SELECT DISTINCT tenant_id, type, metric, dpart " +
"FROM data_temp_%d";

// Generify

gaugeTempInserters = new PreparedStatement[12];
dateRangeExclusive = new PreparedStatement[12];
dateRangeExclusiveWithLimit = new PreparedStatement[12];
dataByDateRangeExclusiveASC = new PreparedStatement[12];
dataByDateRangeExclusiveWithLimitASC = new PreparedStatement[12];
metricsInDatas = new PreparedStatement[12];
allMetricsInDatas = new PreparedStatement[12];

for(int i = 0; i < 12; i++) {
gaugeTempInserters[i] = session.prepare(String.format(baseString, i));
Expand All @@ -291,6 +302,8 @@ private void createGaugeTempInserters() {
dataByDateRangeExclusiveASC[i] = session.prepare(String.format(DataByDateRangeExclusiveASCBase, i));
dataByDateRangeExclusiveWithLimitASC[i] = session.prepare(String.format
(DataByDateRangeExclusiveWithLimitASCBase, i));
metricsInDatas[i] = session.prepare(String.format(findMetricInDataBase, i));
allMetricsInDatas[i] = session.prepare(String.format(findAllMetricsInDataBases, i));
}
}

Expand Down Expand Up @@ -676,11 +689,14 @@ public <T> ResultSetFuture insertMetricInMetricsIndex(Metric<T> metric, boolean

@Override
public <T> Observable<Row> findMetricInData(MetricId<T> id) {
return rxSession.executeAndFetch(findMetricInData
.bind(id.getTenantId(), id.getType().getCode(), id.getName(), DPART))
.concatWith(
rxSession.executeAndFetch(findMetricInDataCompressed
.bind(id.getTenantId(), id.getType().getCode(), id.getName(), DPART)))
return Observable.from(metricsInDatas)
.map(b -> b.bind(id.getTenantId(), id.getType().getCode(), id.getName(), DPART))
.flatMap(b -> rxSession.executeAndFetch(b))
.concatWith(rxSession.executeAndFetch(findMetricInData
.bind(id.getTenantId(), id.getType().getCode(), id.getName(), DPART))
.concatWith(
rxSession.executeAndFetch(findMetricInDataCompressed
.bind(id.getTenantId(), id.getType().getCode(), id.getName(), DPART))))
.take(1);
}

Expand Down Expand Up @@ -761,8 +777,12 @@ public <T> Observable<Row> findMetricsInMetricsIndex(String tenantId, MetricType

@Override
public Observable<Row> findAllMetricsInData() {
return rxSession.executeAndFetch(findAllMetricsInData.bind())
.concatWith(rxSession.executeAndFetch(findAllMetricsInDataCompressed.bind()));
return Observable.from(allMetricsInDatas)
.map(PreparedStatement::bind)
.flatMap(b -> rxSession.executeAndFetch(b))
.concatWith(
rxSession.executeAndFetch(findAllMetricsInData.bind())
.concatWith(rxSession.executeAndFetch(findAllMetricsInDataCompressed.bind())));
}

/*
Expand Down

0 comments on commit 753a910

Please sign in to comment.