xiaohui-sun commented on a change in pull request #5011: [TE] endpoint - 
harleyjj/yamlresource - add dataset as an optional pa…
URL: https://github.com/apache/incubator-pinot/pull/5011#discussion_r370742027
 
 

 ##########
 File path: 
thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/yaml/YamlResource.java
 ##########
 @@ -907,8 +907,46 @@ public Response toggleActivation(
    */
   @GET
   @Path("/list")
+  @ApiOperation("Get the list of all detection YAML configurations as JSON 
enhanced with additional information, optionally filtered.")
   @Produces(MediaType.APPLICATION_JSON)
-  public List<Map<String, Object>> listYamls() throws ExecutionException {
-    return 
this.detectionConfigDAO.findAll().parallelStream().map(this.detectionConfigFormatter::format).collect(Collectors.toList());
+  public List<Map<String, Object>> listYamls(
+      @ApiParam("Dataset the detection configurations should be filtered by") 
@QueryParam("dataset") String dataset,
+      @ApiParam("Metric the detection configurations should be filtered by") 
@QueryParam("metric") String metric) throws ExecutionException {
+    List<Map<String, Object>> yamls;
+    if (dataset == null && metric == null) {
+      yamls = this.detectionConfigDAO
+          .findAll()
+          .parallelStream()
+          .map(this.detectionConfigFormatter::format)
+          .collect(Collectors.toList());
+    } else {
+      yamls = this.detectionConfigDAO
+          .findAll()
+          .parallelStream()
+          .map(this.detectionConfigFormatter::format)
+          .filter(y -> {
+            List datasetList = (List) y.get("datasetNames");
+            String metricString = (String) y.get("metric");
+            boolean metricMatch = true;
+            boolean datasetMatch = true;
+            if (metric != null ) {
+              if (metricString != null) {
+                metricMatch = metricString.equals(metric);
+              } else {
+                metricMatch = false;
+              }
+            }
+            if (dataset != null && datasetList != null) {
+              if (datasetList != null) {
+                datasetMatch = datasetList.contains(dataset);
+              } else {
+                datasetMatch = false;
+              }
+            }
+            return (metricMatch && datasetMatch);
+          })
 
 Review comment:
   The readability is bad. Let's rewrite this logic.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to