Skip to content

Commit d695e75

Browse files
committed
Address the comment
1 parent 8a77b81 commit d695e75

File tree

4 files changed

+232
-6
lines changed

4 files changed

+232
-6
lines changed

api/src/main/java/org/apache/gravitino/stats/Statistic.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import java.util.Optional;
2222
import org.apache.gravitino.annotation.Evolving;
23-
import org.apache.gravitino.rel.expressions.literals.Literal;
2423

2524
/**
2625
* Statistic interface represents a statistic that can be associated with a metadata object. It can
@@ -43,7 +42,7 @@ public interface Statistic {
4342
*
4443
* @return An optional containing the value of the statistic if it is set, otherwise empty.
4544
*/
46-
Optional<Literal> value();
45+
Optional<StatisticValue> value();
4746

4847
/**
4948
* The statistic is predefined by Gravitino if the value is true. The statistic is defined by
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.gravitino.stats;
20+
21+
import org.apache.gravitino.rel.types.Type;
22+
23+
/**
24+
* An interface representing a statistic value.
25+
*/
26+
public interface StatisticValue<T> {
27+
28+
/**
29+
* Returns the value of the statistic.
30+
* @return the value of the statistic
31+
*/
32+
T value();
33+
34+
/**
35+
* Returns the data type of the statistic value.
36+
* @return the data type of the statistic value
37+
*/
38+
Type dataType();
39+
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.gravitino.stats;
20+
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+
import java.util.List;
26+
import java.util.Map;
27+
28+
/**
29+
* A class representing a collection of statistic values.
30+
*/
31+
public class StatisticValues {
32+
33+
/**
34+
* A statistic value that holds a Boolean value.
35+
*/
36+
public static class BooleanValue implements StatisticValue<Boolean> {
37+
private final Boolean value;
38+
39+
public BooleanValue(Boolean value) {
40+
this.value = value;
41+
}
42+
43+
@Override
44+
public Boolean value() {
45+
return value;
46+
}
47+
48+
@Override
49+
public Type dataType() {
50+
return Types.BooleanType.get();
51+
}
52+
}
53+
54+
/**
55+
* A statistic value that holds a Long value.
56+
*/
57+
public static class LongValue implements StatisticValue<Long> {
58+
private final Long value;
59+
60+
public LongValue(Long value) {
61+
this.value = value;
62+
}
63+
64+
@Override
65+
public Long value() {
66+
return value;
67+
}
68+
69+
@Override
70+
public Type dataType() {
71+
return Types.LongType.get();
72+
}
73+
}
74+
75+
/**
76+
* A statistic value that holds a Double value.
77+
*/
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+
}
88+
89+
@Override
90+
public Double value() {
91+
return value;
92+
}
93+
94+
@Override
95+
public Type dataType() {
96+
return Types.DoubleType.get();
97+
}
98+
}
99+
100+
/**
101+
* A statistic value that holds a String value.
102+
*/
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+
}
113+
114+
@Override
115+
public String value() {
116+
return value;
117+
}
118+
119+
@Override
120+
public Type dataType() {
121+
return Types.StringType.get();
122+
}
123+
}
124+
125+
/**
126+
* A statistic value that holds a List of other statistic values.
127+
*/
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+
}
139+
140+
@Override
141+
public List<StatisticValue> value() {
142+
return values;
143+
}
144+
145+
@Override
146+
public Type dataType() {
147+
return Types.ListType.notNull(values.get(0).dataType());
148+
}
149+
}
150+
151+
/**
152+
* A statistic value that holds a Map of String keys to other statistic values.
153+
*/
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+
}
181+
}
182+
}

api/src/main/java/org/apache/gravitino/stats/SupportsStatistics.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,21 @@ public interface SupportsStatistics {
4141

4242
/**
4343
* Updates statistics with the provided values. If the statistic exists, it will be updated with
44-
* the new value. If the statistic does not exist, it will be created. If the provided statistic
45-
* value is null and the statistic is custom, the statistic will be deleted. If the provided
46-
* statistic value is null and the statistic is reserved, the statistic will set value null. If
44+
* the new value. If the statistic does not exist, it will be created. If
4745
* the statistic is unmodifiable, it will throw an UnmodifiableStatisticException. If the
4846
* statistic name is illegal, it will throw an IllegalStatisticNameException.
4947
*
5048
* @param statistics a map of statistic names to their values
5149
* @return a list of updated statistics
5250
*/
53-
List<Statistic> updateStatistics(Map<String, Literal> statistics)
51+
List<Statistic> updateStatistics(Map<String, StatisticValue> statistics)
5452
throws UnmodifiableStatisticException, IllegalStatisticNameException;
53+
54+
/**
55+
* Drop statistics by their names. If the statistic is unmodifiable, it will throw an UnmodifiableStatisticException.
56+
* @param statistics a list of statistic names to be dropped
57+
* @return true if the statistics were successfully dropped, false if no statistics were dropped
58+
* @throws UnmodifiableStatisticException if any of the statistics to be dropped are unmodifiable
59+
*/
60+
boolean dropStatistics(List<String> statistics) throws UnmodifiableStatisticException;
5561
}

0 commit comments

Comments
 (0)