docs: @Nullable
    public static AggregatorFactory[] mergeAggregators(List<AggregatorFactory[]> aggregatorsList)
    {
      if (aggregatorsList == null || aggregatorsList.isEmpty()) {
        return null;
      }
  
      if (aggregatorsList.size() == 1) {
        final AggregatorFactory[] aggregatorFactories = aggregatorsList.get(0);
        if (aggregatorFactories != null) {
          final AggregatorFactory[] combiningFactories = new AggregatorFactory[aggregatorFactories.length];
          Arrays.setAll(combiningFactories, i -> aggregatorFactories[i].getCombiningFactory());
          return combiningFactories;
        } else {
          return null;
        }
      }
  
      Map<String, AggregatorFactory> mergedAggregators = new LinkedHashMap<>();
  
      for (AggregatorFactory[] aggregators : aggregatorsList) {
  
        if (aggregators != null) {
          for (AggregatorFactory aggregator : aggregators) {
            String name = aggregator.getName();
            if (mergedAggregators.containsKey(name)) {
              AggregatorFactory other = mergedAggregators.get(name);
              try {
                // the order of aggregator matters when calling getMergingFactory()
                // because it returns a combiningAggregator which can be different from the original aggregator.
                mergedAggregators.put(name, aggregator.getMergingFactory(other));
              }
              catch (AggregatorFactoryNotMergeableException ex) {
                log.warn(ex, "failed to merge aggregator factories");
                mergedAggregators = null;
                break;
              }
            } else {
              mergedAggregators.put(name, aggregator);
            }
          }
        } else {
          mergedAggregators = null;
          break;
        }
      }
  
      return mergedAggregators == null
             ? null
             : mergedAggregators.values().toArray(new AggregatorFactory[0]);
    }