1 | /* | |
2 | * Copyright OpenSearch Contributors | |
3 | * SPDX-License-Identifier: Apache-2.0 | |
4 | */ | |
5 | ||
6 | package org.opensearch.sql.ast.expression; | |
7 | ||
8 | import com.google.common.collect.ImmutableList; | |
9 | import java.util.List; | |
10 | import lombok.Getter; | |
11 | import lombok.RequiredArgsConstructor; | |
12 | ||
13 | @Getter | |
14 | @RequiredArgsConstructor | |
15 | public enum SpanUnit { | |
16 | UNKNOWN("unknown"), | |
17 | NONE(""), | |
18 | MILLISECOND("ms"), | |
19 | MS("ms"), | |
20 | SECOND("s"), | |
21 | S("s"), | |
22 | MINUTE("m"), | |
23 | m("m"), | |
24 | HOUR("h"), | |
25 | H("h"), | |
26 | DAY("d"), | |
27 | D("d"), | |
28 | WEEK("w"), | |
29 | W("w"), | |
30 | MONTH("M"), | |
31 | M("M"), | |
32 | QUARTER("q"), | |
33 | Q("q"), | |
34 | YEAR("y"), | |
35 | Y("y"); | |
36 | ||
37 | private final String name; | |
38 | private static final List<SpanUnit> SPAN_UNITS; | |
39 | ||
40 | static { | |
41 | ImmutableList.Builder<SpanUnit> builder = ImmutableList.builder(); | |
42 | SPAN_UNITS = builder.add(SpanUnit.values()).build(); | |
43 | } | |
44 | ||
45 | /** | |
46 | * Util method to get span unit given the unit name. | |
47 | */ | |
48 | public static SpanUnit of(String unit) { | |
49 | switch (unit) { | |
50 | case "": | |
51 |
1
1. of : replaced return value with null for org/opensearch/sql/ast/expression/SpanUnit::of → KILLED |
return NONE; |
52 | case "M": | |
53 |
1
1. of : replaced return value with null for org/opensearch/sql/ast/expression/SpanUnit::of → KILLED |
return M; |
54 | case "m": | |
55 |
1
1. of : replaced return value with null for org/opensearch/sql/ast/expression/SpanUnit::of → KILLED |
return m; |
56 | default: | |
57 |
1
1. of : replaced return value with null for org/opensearch/sql/ast/expression/SpanUnit::of → KILLED |
return SPAN_UNITS.stream() |
58 |
2
1. lambda$of$0 : replaced boolean return with false for org/opensearch/sql/ast/expression/SpanUnit::lambda$of$0 → KILLED 2. lambda$of$0 : replaced boolean return with true for org/opensearch/sql/ast/expression/SpanUnit::lambda$of$0 → KILLED |
.filter(v -> unit.equalsIgnoreCase(v.name())) |
59 | .findFirst() | |
60 | .orElse(UNKNOWN); | |
61 | } | |
62 | } | |
63 | ||
64 | public static String getName(SpanUnit unit) { | |
65 |
1
1. getName : replaced return value with "" for org/opensearch/sql/ast/expression/SpanUnit::getName → NO_COVERAGE |
return unit.name; |
66 | } | |
67 | ||
68 | } | |
Mutations | ||
51 |
1.1 |
|
53 |
1.1 |
|
55 |
1.1 |
|
57 |
1.1 |
|
58 |
1.1 2.2 |
|
65 |
1.1 |