public SampleFamily count(List<String> by) {
        ExpressionParsingContext.get().ifPresent(ctx -> ctx.aggregationLabels.addAll(by));
        if (this == EMPTY) {
            return EMPTY;
        }
        if (by == null) {
            long result = Arrays.stream(samples).count();
            return SampleFamily.build(
                    this.context, InternalOps.newSample(samples[0].name, ImmutableMap.of(), samples[0].timestamp, result));
        }

        if (by.size() == 1) {
            Set<String> set = Arrays
                    .stream(samples)
                    .map(sample -> sample.labels.get(by.get(0)))
                    .filter(StringUtils::isNotBlank)
                    .collect(Collectors.toSet());

            return SampleFamily.build(
                    this.context, InternalOps.newSample(samples[0].name, ImmutableMap.of(), samples[0].timestamp, set.size()));
        }

        Stream<Map.Entry<ImmutableMap<String, String>, List<Sample>>> stream = Arrays
                .stream(samples)
                .filter(sample -> sample.labels.keySet().containsAll(by))
                .collect(groupingBy(it -> InternalOps.getLabels(by, it)))
                .entrySet()
                .stream()
                .map(entry -> InternalOps.newSample(
                        entry.getValue().get(0).getName(),
                        entry.getKey(),
                        entry.getValue().get(0).getTimestamp(),
                        entry.getValue().size()))
                .collect(groupingBy(it -> InternalOps.groupByExcludedLabel(by.get(by.size() - 1), it), mapping(identity(), toList())))
                .entrySet()
                .stream();

        Sample[] array = stream
                .map(entry -> InternalOps.newSample(
                        entry.getValue().get(0).getName(),
                        entry.getKey(),
                        entry.getValue().get(0).getTimestamp(),
                        entry.getValue().size()
                ))
                .toArray(Sample[]::new);

        SampleFamily sampleFamily = SampleFamily.build(
                this.context,
                array
        );
        return sampleFamily;
    }
Following operations are used in DSL
oap-server/analyzer/meter-analyzer/src/main/java/org/apache/skywalking/oap/meter/analyzer/dsl/SampleFamily.java