hanahmily commented on a change in pull request #5202:
URL: https://github.com/apache/skywalking/pull/5202#discussion_r467454611



##########
File path: 
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IMetricsQueryDAO.java
##########
@@ -76,5 +87,54 @@ public static IntValues sortValues(IntValues origin, 
List<String> expectedOrder,
             }
             return origin;
         }
+
+        /**
+         * Compose the multiple metric result based on conditions.
+         */
+        public static List<MetricsValues> composeLabelValue(final 
MetricsCondition condition,
+            final List<String> labels,
+            final List<String> ids,
+            final Map<String, DataTable> idMap) {
+            List<String> allLabels;
+            if (Objects.isNull(labels) || labels.size() < 1) {
+                allLabels = idMap.values().stream()
+                    .flatMap(dataTable -> dataTable.keys().stream())
+                    .distinct().collect(Collectors.toList());
+            } else {
+                allLabels = labels;
+            }
+            final int defaultValue = 
ValueColumnMetadata.INSTANCE.getDefaultValue(condition.getName());
+            List<LabeledValue> labeledValues = 
Sets.newTreeSet(allLabels).stream()
+                .flatMap(label -> ids.stream().map(id ->
+                    new LabeledValue(label, id, Optional.ofNullable(
+                        idMap.getOrDefault(id, new 
DataTable()).get(label)).orElse((long) defaultValue))))
+                .collect(toList());
+            MetricsValues current = new MetricsValues();
+            List<MetricsValues> result = new ArrayList<>();
+            for (LabeledValue each : labeledValues) {
+                if (!Strings.isNullOrEmpty(current.getLabel()) && 
each.label.equals(current.getLabel())) {

Review comment:
       `Objects.equals` is a better choice.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to