package com.linkedin.thirdeye.rootcause;

import java.util.Set;


/**
 * StaticPipeline emits a fixed set of entities as a result, regardless of the input. It is
 * used to encapsulate constants (such as user input) during framework execution.
 */
public class StaticPipeline extends Pipeline {
  private final Set<Entity> entities;

  /**
   * Constructor for dependency injection
   *
   * @param outputName pipeline output name
   * @param inputNames input pipeline names
   * @param entities entities to emit as result
   */
  public StaticPipeline(String outputName, Set<String> inputNames, Set<Entity> entities) {
    super(outputName, inputNames);
    this.entities = entities;
  }

  @Override
  public PipelineResult run(PipelineContext context) {
    return new PipelineResult(context, this.entities);
  }
}

@@ -35,16 +35,172 @@
 cause;%0A%0A
+import com.linkedin.thirdeye.rootcause.impl.EntityUtils;%0Aimport java.util.ArrayList;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Map;%0A
 import j
@@ -213,16 +213,16 @@
 il.Set;%0A
-
 %0A%0A/**%0A *
@@ -444,16 +444,129 @@
 eline %7B%0A
+  private static final String PROP_ENTITIES = %22entities%22;%0A  private static final String PROP_SCORES = %22scores%22;%0A%0A
   privat
@@ -952,16 +952,1430 @@
 s;%0A  %7D%0A%0A
+  /**%0A   * Alternate constructor for use by PipelineLoader%0A   *%0A   * @param outputName pipeline output name%0A   * @param inputNames input pipeline names%0A   * @param properties configuration properties (%7B@code PROP_ENTITIES%7D, %7B@code PROP_SCORES%7D)%0A   */%0A  public StaticPipeline(String outputName, Set%3CString%3E inputNames, Map%3CString, String%3E properties) %7B%0A    super(outputName, inputNames);%0A%0A    if(!properties.containsKey(PROP_ENTITIES))%0A      throw new IllegalArgumentException(String.format(%22Property '%25s' required, but not found%22, PROP_ENTITIES));%0A%0A    this.entities = new HashSet%3C%3E();%0A    String entitiesProp = properties.get(PROP_ENTITIES);%0A    String%5B%5D urns = entitiesProp.split(%22,%22);%0A%0A    List%3CDouble%3E scores = new ArrayList%3C%3E();%0A    if(properties.containsKey(PROP_SCORES)) %7B%0A      // per entity score%0A      String scoresProp = properties.get(PROP_SCORES);%0A      String%5B%5D scoreStrings = scoresProp.split(%22,%22);%0A      for(String s : scoreStrings) %7B%0A        scores.add(Double.parseDouble(s));%0A      %7D%0A%0A    %7D else %7B%0A      // default score%0A      for(int i=0; i%3Curns.length; i++)%0A        scores.add(1.0);%0A    %7D%0A%0A    if(scores.size() != urns.length)%0A      throw new IllegalArgumentException(String.format(%22Requires equal number of scores %5B=%25d%5D and entities %5B=%25d%5D%22, scores.size(), urns.length));%0A%0A    for(int i=0; i%3Curns.length; i++) %7B%0A      this.entities.add(EntityUtils.parseURN(urns%5Bi%5D, scores.get(i)));%0A    %7D%0A  %7D%0A%0A
   @Overr
@@ -2488,14 +2488,15 @@
 ities);%0A
-
   %7D%0A
+%0A
 %7D%0A

support dynamic loading of static pipeline (#1433)