public static List<String> composeLabelConditions(final List<KeyValue> queryLabels,
                                                          final Collection<DataTable> metricValues) {
            LinkedHashMap<String, List<String>> queryLabelIndex = buildLabelIndex(queryLabels, Const.COMMA);
            List<String> labelConditions = new ArrayList<>();
            if (queryLabelIndex.isEmpty()) {
                labelConditions = metricValues.stream()
                                      .flatMap(dataTable -> dataTable.keys().stream())
                                      .distinct()
                                      .filter(k -> k.startsWith(Const.LEFT_BRACE))
                                      .collect(Collectors.toList());
            } else {
                List<Set<String>> keySets = new ArrayList<>();
                for (Map.Entry<String, List<String>> queryLabel : queryLabelIndex.entrySet()) {
                    Set<String> keySet = new HashSet<>();
                    metricValues.forEach(dataTable -> {
                        var metricLabelIndex = dataTable.buildLabelIndex();
                        for (String labelValue : queryLabel.getValue()) {
                            //union labels
                            keySet.addAll(metricLabelIndex.getOrDefault(
                                queryLabel.getKey() + Const.EQUAL + labelValue,
                                new HashSet<>()
                            ));
                        }
                    });
                    if (!keySet.isEmpty()) {
                        keySets.add(keySet);
                    }
                }
                //intersection labels
                keySets.stream().reduce((a, b) -> {
                    a.retainAll(b);
                    return a;
                }).ifPresent(labelConditions::addAll);
            }
            return labelConditions;
        }
Compose the multiple metric result based on conditions.
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IMetricsQueryDAO.java