From 7a8ac61af82901e6af0e3c976dbbf054244f42ee Mon Sep 17 00:00:00 2001 From: Ludovic DEHON Date: Wed, 31 Aug 2022 18:18:24 +0200 Subject: [PATCH] fix(jdbc): missing filter on daily statistics for namespace and flow --- .../AbstractJdbcExecutionRepository.java | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcExecutionRepository.java b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcExecutionRepository.java index 07f5fa9dfbb..9d36fe341b2 100644 --- a/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcExecutionRepository.java +++ b/jdbc/src/main/java/io/kestra/jdbc/repository/AbstractJdbcExecutionRepository.java @@ -118,12 +118,7 @@ public ArrayListTotal 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())); @@ -137,9 +132,6 @@ public ArrayListTotal find( select = select.and(this.statesFilter(state)); } - if (query != null) { - select.and(this.findCondition(query)); - } return this.jdbcRepository.fetchPage(context, select, pageable); }); @@ -200,6 +192,8 @@ public List dailyStatistics( field("state_current", String.class) ), query, + namespace, + flowId, startDate, endDate ); @@ -226,7 +220,14 @@ private static List dailyStatisticsQueryMapRecord(Resu .collect(Collectors.toList()); } - private Results dailyStatisticsQuery(List> fields, String query, ZonedDateTime startDate, ZonedDateTime endDate) { + private Results dailyStatisticsQuery( + List> 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; @@ -250,9 +251,7 @@ private Results dailyStatisticsQuery(List> 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> groupFields = new ArrayList<>(); if (context.configuration().dialect() != SQLDialect.H2) { @@ -270,6 +269,26 @@ private Results dailyStatisticsQuery(List> fields, String query, ZonedD }); } + private SelectConditionStep filteringQuery( + SelectConditionStep 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>> dailyGroupByFlowStatistics( @@ -293,6 +312,8 @@ public Map>> dailyGroupByFlow Results results = dailyStatisticsQuery( fields, query, + namespace, + flowId, startDate, endDate );