|
19 | 19 | package org.apache.gravitino.stats;
|
20 | 20 |
|
21 | 21 | import com.google.common.base.Preconditions;
|
22 |
| -import org.apache.gravitino.rel.types.Type; |
23 |
| -import org.apache.gravitino.rel.types.Types; |
24 |
| - |
25 | 22 | import java.util.List;
|
26 | 23 | import java.util.Map;
|
| 24 | +import org.apache.gravitino.rel.types.Type; |
| 25 | +import org.apache.gravitino.rel.types.Types; |
27 | 26 |
|
28 |
| -/** |
29 |
| - * A class representing a collection of statistic values. |
30 |
| - */ |
| 27 | +/** A class representing a collection of statistic values. */ |
31 | 28 | public class StatisticValues {
|
32 | 29 |
|
33 |
| - /** |
34 |
| - * A statistic value that holds a Boolean value. |
35 |
| - */ |
36 |
| - public static class BooleanValue implements StatisticValue<Boolean> { |
37 |
| - private final Boolean value; |
| 30 | + /** A statistic value that holds a Boolean value. */ |
| 31 | + public static class BooleanValue implements StatisticValue<Boolean> { |
| 32 | + private final Boolean value; |
38 | 33 |
|
39 |
| - public BooleanValue(Boolean value) { |
40 |
| - this.value = value; |
41 |
| - } |
| 34 | + public BooleanValue(Boolean value) { |
| 35 | + this.value = value; |
| 36 | + } |
42 | 37 |
|
43 |
| - @Override |
44 |
| - public Boolean value() { |
45 |
| - return value; |
46 |
| - } |
| 38 | + @Override |
| 39 | + public Boolean value() { |
| 40 | + return value; |
| 41 | + } |
47 | 42 |
|
48 |
| - @Override |
49 |
| - public Type dataType() { |
50 |
| - return Types.BooleanType.get(); |
51 |
| - } |
| 43 | + @Override |
| 44 | + public Type dataType() { |
| 45 | + return Types.BooleanType.get(); |
52 | 46 | }
|
| 47 | + } |
53 | 48 |
|
54 |
| - /** |
55 |
| - * A statistic value that holds a Long value. |
56 |
| - */ |
57 |
| - public static class LongValue implements StatisticValue<Long> { |
58 |
| - private final Long value; |
| 49 | + /** A statistic value that holds a Long value. */ |
| 50 | + public static class LongValue implements StatisticValue<Long> { |
| 51 | + private final Long value; |
59 | 52 |
|
60 |
| - public LongValue(Long value) { |
61 |
| - this.value = value; |
62 |
| - } |
| 53 | + public LongValue(Long value) { |
| 54 | + this.value = value; |
| 55 | + } |
63 | 56 |
|
64 |
| - @Override |
65 |
| - public Long value() { |
66 |
| - return value; |
67 |
| - } |
| 57 | + @Override |
| 58 | + public Long value() { |
| 59 | + return value; |
| 60 | + } |
68 | 61 |
|
69 |
| - @Override |
70 |
| - public Type dataType() { |
71 |
| - return Types.LongType.get(); |
72 |
| - } |
| 62 | + @Override |
| 63 | + public Type dataType() { |
| 64 | + return Types.LongType.get(); |
73 | 65 | }
|
| 66 | + } |
| 67 | + |
| 68 | + /** A statistic value that holds a Double value. */ |
| 69 | + public static class DoubleValue implements StatisticValue<Double> { |
| 70 | + private final Double value; |
74 | 71 |
|
75 | 72 | /**
|
76 |
| - * A statistic value that holds a Double value. |
| 73 | + * Creates a DoubleValue with the given double value. |
| 74 | + * |
| 75 | + * @param value The double value to be held by this statistic value. |
77 | 76 | */
|
78 |
| - public static class DoubleValue implements StatisticValue<Double> { |
79 |
| - private final Double value; |
80 |
| - |
81 |
| - /** |
82 |
| - * Creates a DoubleValue with the given double value. |
83 |
| - * @param value The double value to be held by this statistic value. |
84 |
| - */ |
85 |
| - public DoubleValue(Double value) { |
86 |
| - this.value = value; |
87 |
| - } |
| 77 | + public DoubleValue(Double value) { |
| 78 | + this.value = value; |
| 79 | + } |
88 | 80 |
|
89 |
| - @Override |
90 |
| - public Double value() { |
91 |
| - return value; |
92 |
| - } |
| 81 | + @Override |
| 82 | + public Double value() { |
| 83 | + return value; |
| 84 | + } |
93 | 85 |
|
94 |
| - @Override |
95 |
| - public Type dataType() { |
96 |
| - return Types.DoubleType.get(); |
97 |
| - } |
| 86 | + @Override |
| 87 | + public Type dataType() { |
| 88 | + return Types.DoubleType.get(); |
98 | 89 | }
|
| 90 | + } |
| 91 | + |
| 92 | + /** A statistic value that holds a String value. */ |
| 93 | + public static class StringValue implements StatisticValue<String> { |
| 94 | + private final String value; |
99 | 95 |
|
100 | 96 | /**
|
101 |
| - * A statistic value that holds a String value. |
| 97 | + * Creates a StringValue with the given string value. |
| 98 | + * |
| 99 | + * @param value The string value to be held by this statistic value. |
102 | 100 | */
|
103 |
| - public static class StringValue implements StatisticValue<String> { |
104 |
| - private final String value; |
105 |
| - |
106 |
| - /** |
107 |
| - * Creates a StringValue with the given string value. |
108 |
| - * @param value The string value to be held by this statistic value. |
109 |
| - */ |
110 |
| - public StringValue(String value) { |
111 |
| - this.value = value; |
112 |
| - } |
| 101 | + public StringValue(String value) { |
| 102 | + this.value = value; |
| 103 | + } |
113 | 104 |
|
114 |
| - @Override |
115 |
| - public String value() { |
116 |
| - return value; |
117 |
| - } |
| 105 | + @Override |
| 106 | + public String value() { |
| 107 | + return value; |
| 108 | + } |
118 | 109 |
|
119 |
| - @Override |
120 |
| - public Type dataType() { |
121 |
| - return Types.StringType.get(); |
122 |
| - } |
| 110 | + @Override |
| 111 | + public Type dataType() { |
| 112 | + return Types.StringType.get(); |
123 | 113 | }
|
| 114 | + } |
| 115 | + |
| 116 | + /** A statistic value that holds a List of other statistic values. */ |
| 117 | + public static class ListValue implements StatisticValue<List<StatisticValue>> { |
| 118 | + private final List<StatisticValue> values; |
124 | 119 |
|
125 | 120 | /**
|
126 |
| - * A statistic value that holds a List of other statistic values. |
| 121 | + * Creates a ListValue with the given list of statistic values. |
| 122 | + * |
| 123 | + * @param values A list of StatisticValue instances. |
127 | 124 | */
|
128 |
| - public static class ListValue implements StatisticValue<List<StatisticValue>> { |
129 |
| - private final List<StatisticValue> values; |
130 |
| - |
131 |
| - /** |
132 |
| - * Creates a ListValue with the given list of statistic values. |
133 |
| - * @param values A list of StatisticValue instances. |
134 |
| - */ |
135 |
| - public ListValue(List<StatisticValue> values) { |
136 |
| - Preconditions.checkArgument(values != null && values.isEmpty(), "Values cannot be null or empty"); |
137 |
| - this.values = values; |
138 |
| - } |
| 125 | + public ListValue(List<StatisticValue> values) { |
| 126 | + Preconditions.checkArgument( |
| 127 | + values != null && values.isEmpty(), "Values cannot be null or empty"); |
| 128 | + this.values = values; |
| 129 | + } |
139 | 130 |
|
140 |
| - @Override |
141 |
| - public List<StatisticValue> value() { |
142 |
| - return values; |
143 |
| - } |
| 131 | + @Override |
| 132 | + public List<StatisticValue> value() { |
| 133 | + return values; |
| 134 | + } |
144 | 135 |
|
145 |
| - @Override |
146 |
| - public Type dataType() { |
147 |
| - return Types.ListType.notNull(values.get(0).dataType()); |
148 |
| - } |
| 136 | + @Override |
| 137 | + public Type dataType() { |
| 138 | + return Types.ListType.notNull(values.get(0).dataType()); |
149 | 139 | }
|
| 140 | + } |
| 141 | + |
| 142 | + /** A statistic value that holds a Map of String keys to other statistic values. */ |
| 143 | + public static class ObjectValue implements StatisticValue<Map<String, StatisticValue>> { |
| 144 | + private final Map<String, StatisticValue> values; |
150 | 145 |
|
151 | 146 | /**
|
152 |
| - * A statistic value that holds a Map of String keys to other statistic values. |
| 147 | + * Creates an ObjectValue with the given map of statistic values. |
| 148 | + * |
| 149 | + * @param values A map where keys are String identifiers and values are StatisticValue |
| 150 | + * instances. |
153 | 151 | */
|
154 |
| - public static class ObjectValue implements StatisticValue<Map<String, StatisticValue>> { |
155 |
| - private final Map<String, StatisticValue> values; |
156 |
| - |
157 |
| - /** |
158 |
| - * Creates an ObjectValue with the given map of statistic values. |
159 |
| - * @param values A map where keys are String identifiers and values are StatisticValue instances. |
160 |
| - */ |
161 |
| - public ObjectValue(Map<String, StatisticValue> values) { |
162 |
| - Preconditions.checkArgument(values != null && !values.isEmpty(), "Values cannot be null or empty"); |
163 |
| - this.values = values; |
164 |
| - } |
165 |
| - |
166 |
| - @Override |
167 |
| - public Map<String, StatisticValue> value() { |
168 |
| - return values; |
169 |
| - } |
170 |
| - |
171 |
| - @Override |
172 |
| - public Type dataType() { |
173 |
| - return Types.StructType.of( |
174 |
| - values.entrySet().stream() |
175 |
| - .map( |
176 |
| - entry -> |
177 |
| - Types.StructType.Field.nullableField( |
178 |
| - entry.getKey(), entry.getValue().dataType())) |
179 |
| - .toArray(Types.StructType.Field[]::new)); |
180 |
| - } |
| 152 | + public ObjectValue(Map<String, StatisticValue> values) { |
| 153 | + Preconditions.checkArgument( |
| 154 | + values != null && !values.isEmpty(), "Values cannot be null or empty"); |
| 155 | + this.values = values; |
| 156 | + } |
| 157 | + |
| 158 | + @Override |
| 159 | + public Map<String, StatisticValue> value() { |
| 160 | + return values; |
| 161 | + } |
| 162 | + |
| 163 | + @Override |
| 164 | + public Type dataType() { |
| 165 | + return Types.StructType.of( |
| 166 | + values.entrySet().stream() |
| 167 | + .map( |
| 168 | + entry -> |
| 169 | + Types.StructType.Field.nullableField( |
| 170 | + entry.getKey(), entry.getValue().dataType())) |
| 171 | + .toArray(Types.StructType.Field[]::new)); |
181 | 172 | }
|
| 173 | + } |
182 | 174 | }
|
0 commit comments