Skip to content

Commit

Permalink
[hotfix] Improve handling of count queries, improve table widget (#1484)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikriemer committed Apr 6, 2023
1 parent cdcd83e commit 1dcc11b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class DataExplorerInfluxQueryExecutor extends DataExplorerQueryExecutor<Query, QueryResult> {

Expand All @@ -53,12 +54,22 @@ public DataExplorerInfluxQueryExecutor(int maximumAmountOfEvents) {
protected double getAmountOfResults(QueryResult countQueryResult) {
if (countQueryResult.getResults().get(0).getSeries() != null
&& countQueryResult.getResults().get(0).getSeries().get(0).getValues() != null) {
return (double) countQueryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1);
return getMaxCount(countQueryResult.getResults().get(0).getSeries().get(0).getValues().get(0));
} else {
return 0.0;
}
}

private double getMaxCount(List<Object> rows) {
return rows.stream()
.skip(1)
.filter(Objects::nonNull)
.filter(Number.class::isInstance)
.mapToDouble(r -> ((Number) r).doubleValue())
.max()
.orElse(Double.NEGATIVE_INFINITY);
}


protected DataSeries convertResult(QueryResult.Series series,
boolean ignoreMissingValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.apache.streampipes.dataexplorer.param.model.FillClauseParams;
import org.apache.streampipes.dataexplorer.param.model.GroupByTagsClauseParams;
import org.apache.streampipes.dataexplorer.param.model.GroupByTimeClauseParams;
import org.apache.streampipes.dataexplorer.param.model.ItemClauseParams;
import org.apache.streampipes.dataexplorer.param.model.LimitClauseParams;
import org.apache.streampipes.dataexplorer.param.model.OffsetClauseParams;
import org.apache.streampipes.dataexplorer.param.model.OrderByClauseParams;
import org.apache.streampipes.dataexplorer.param.model.SelectClauseParams;
Expand Down Expand Up @@ -99,7 +99,7 @@ public static SelectQueryParams getSelectQueryParams(ProvidedRestQueryParams par
}

if (params.has(QP_LIMIT)) {
queryParameters.withLimitParams(ItemClauseParams.from(params.getAsInt(QP_LIMIT)));
queryParameters.withLimitParams(LimitClauseParams.from(params.getAsInt(QP_LIMIT)));
}

if (params.has(QP_OFFSET)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.streampipes.dataexplorer.param.model.FillClauseParams;
import org.apache.streampipes.dataexplorer.param.model.GroupByTagsClauseParams;
import org.apache.streampipes.dataexplorer.param.model.GroupByTimeClauseParams;
import org.apache.streampipes.dataexplorer.param.model.ItemClauseParams;
import org.apache.streampipes.dataexplorer.param.model.LimitClauseParams;
import org.apache.streampipes.dataexplorer.param.model.OffsetClauseParams;
import org.apache.streampipes.dataexplorer.param.model.OrderByClauseParams;
import org.apache.streampipes.dataexplorer.param.model.SelectClauseParams;
Expand All @@ -39,7 +39,7 @@ public class SelectQueryParams {
private GroupByTimeClauseParams groupByTimeClauseParams;

private OrderByClauseParams orderByClauseParams;
private ItemClauseParams limitParams;
private LimitClauseParams limitParams;

private OffsetClauseParams offsetClauseParams;

Expand All @@ -59,7 +59,7 @@ public void withSelectParams(SelectClauseParams params) {
this.selectParams = params;
}

public void withLimitParams(ItemClauseParams params) {
public void withLimitParams(LimitClauseParams params) {
this.limitParams = params;
}

Expand Down Expand Up @@ -99,6 +99,14 @@ public <T> T toCountQuery(IDataLakeQueryBuilder<T> builder) {
return builder.build();
}

public int getLimit() {
if (Objects.nonNull(limitParams)) {
return limitParams.getLimit();
} else {
return Integer.MIN_VALUE;
}
}

private <T> void prepareBuilder(IDataLakeQueryBuilder<T> builder) {
if (Objects.nonNull(this.whereParams)) {
this.whereParams.buildStatement(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import org.apache.streampipes.dataexplorer.api.IQueryStatement;
import org.apache.streampipes.dataexplorer.querybuilder.IDataLakeQueryBuilder;

public class ItemClauseParams implements IQueryStatement {
public class LimitClauseParams implements IQueryStatement {

private final Integer limit;

public ItemClauseParams(Integer limit) {
public LimitClauseParams(Integer limit) {
this.limit = limit;
}

public static ItemClauseParams from(Integer limit) {
return new ItemClauseParams(limit);
public static LimitClauseParams from(Integer limit) {
return new LimitClauseParams(limit);
}

public Integer getLimit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public SpQueryResult executeQuery(SelectQueryParams params,
if (this.maximumAmountOfEvents != -1) {
X countQuery = makeCountQuery(params);
W countQueryResult = executeQuery(countQuery);
Double amountOfQueryResults = getAmountOfResults(countQueryResult);
var limit = params.getLimit();
Double amountOfQueryResults = limit == Integer.MIN_VALUE ? getAmountOfResults(countQueryResult) : limit;

if (amountOfQueryResults > this.maximumAmountOfEvents) {
SpQueryResult tooMuchData = new SpQueryResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<tr mat-row *matRowDef="let row; columns: columnNames"></tr>
</table>
<mat-paginator
*ngIf="showData"
[length]="100"
[pageSize]="500"
[pageSizeOptions]="[10, 20, 50, 100, 500, 1000]"
Expand Down

0 comments on commit 1dcc11b

Please sign in to comment.