Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hotfix] Improve handling of count queries, improve table widget #1484

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

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

public class DataExplorerInfluxQueryExecutor extends DataExplorerQueryExecutor<Query, QueryResult> {

Expand All @@ -52,12 +53,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