Skip to content

Commit

Permalink
fix(jdbc): missing filter on daily statistics for namespace and flow
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Aug 31, 2022
1 parent 3cbbc87 commit 7a8ac61
Showing 1 changed file with 34 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@ public ArrayListTotal<Execution> find(
.from(this.jdbcRepository.getTable())
.where(this.defaultFilter());

if (flowId != null && namespace != null) {
select = select.and(field("namespace").eq(namespace));
select = select.and(field("flow_id").eq(flowId));
} else if (namespace != null) {
select = select.and(field("namespace").likeIgnoreCase(namespace + "%"));
}
select = filteringQuery(select, namespace, flowId, query);

if (startDate != null) {
select = select.and(field("start_date").greaterOrEqual(startDate.toOffsetDateTime()));
Expand All @@ -137,9 +132,6 @@ public ArrayListTotal<Execution> find(
select = select.and(this.statesFilter(state));
}

if (query != null) {
select.and(this.findCondition(query));
}

return this.jdbcRepository.fetchPage(context, select, pageable);
});
Expand Down Expand Up @@ -200,6 +192,8 @@ public List<DailyExecutionStatistics> dailyStatistics(
field("state_current", String.class)
),
query,
namespace,
flowId,
startDate,
endDate
);
Expand All @@ -226,7 +220,14 @@ private static List<DailyExecutionStatistics> dailyStatisticsQueryMapRecord(Resu
.collect(Collectors.toList());
}

private Results dailyStatisticsQuery(List<Field<?>> fields, String query, ZonedDateTime startDate, ZonedDateTime endDate) {
private Results dailyStatisticsQuery(
List<Field<?>> fields,
@Nullable String query,
@Nullable String namespace,
@Nullable String flowId,
@Nullable ZonedDateTime startDate,
@Nullable ZonedDateTime endDate
) {
ZonedDateTime finalStartDate = startDate == null ? ZonedDateTime.now().minusDays(30) : startDate;
ZonedDateTime finalEndDate = endDate == null ? ZonedDateTime.now() : endDate;

Expand All @@ -250,9 +251,7 @@ private Results dailyStatisticsQuery(List<Field<?>> fields, String query, ZonedD
.and(field("start_date").greaterOrEqual(finalStartDate.toOffsetDateTime()))
.and(field("start_date").lessOrEqual(finalEndDate.toOffsetDateTime()));

if (query != null) {
select.and(this.findCondition(query));
}
select = filteringQuery(select, namespace, flowId, query);

List<Field<?>> groupFields = new ArrayList<>();
if (context.configuration().dialect() != SQLDialect.H2) {
Expand All @@ -270,6 +269,26 @@ private Results dailyStatisticsQuery(List<Field<?>> fields, String query, ZonedD
});
}

private <T extends Record> SelectConditionStep<T> filteringQuery(
SelectConditionStep<T> select,
@Nullable String namespace,
@Nullable String flowId,
@Nullable String query
) {
if (flowId != null && namespace != null) {
select = select.and(field("namespace").eq(namespace));
select = select.and(field("flow_id").eq(flowId));
} else if (namespace != null) {
select = select.and(field("namespace").likeIgnoreCase(namespace + "%"));
}

if (query != null) {
select = select.and(this.findCondition(query));
}

return select;
}


@Override
public Map<String, Map<String, List<DailyExecutionStatistics>>> dailyGroupByFlowStatistics(
Expand All @@ -293,6 +312,8 @@ public Map<String, Map<String, List<DailyExecutionStatistics>>> dailyGroupByFlow
Results results = dailyStatisticsQuery(
fields,
query,
namespace,
flowId,
startDate,
endDate
);
Expand Down

0 comments on commit 7a8ac61

Please sign in to comment.