jerqi commented on code in PR #7876:
URL: https://github.com/apache/gravitino/pull/7876#discussion_r2284701931


##########
common/src/main/java/org/apache/gravitino/dto/stats/PartitionStatisticsUpdateDTO.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.dto.stats;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.google.common.base.Preconditions;
+import java.util.Map;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.json.JsonUtils;
+import org.apache.gravitino.stats.PartitionStatisticsUpdate;
+import org.apache.gravitino.stats.StatisticValue;
+
+/**
+ * PartitionStatisticsUpdateDTO is a Data Transfer Object (DTO) that 
represents the request to
+ * update statistics for a specific partition in a data source.
+ */
+@EqualsAndHashCode
+@ToString
+public class PartitionStatisticsUpdateDTO implements PartitionStatisticsUpdate 
{
+
+  @JsonProperty("partitionName")
+  private final String partitionName;
+
+  @JsonProperty("statistics")
+  @JsonSerialize(contentUsing = JsonUtils.StatisticValueSerializer.class)
+  @JsonDeserialize(contentUsing = JsonUtils.StatisticValueDeserializer.class)
+  private final Map<String, StatisticValue<?>> statistics;
+
+  /** Default constructor for Jackson. */
+  protected PartitionStatisticsUpdateDTO() {
+    this(null, null);
+  }
+
+  private PartitionStatisticsUpdateDTO(
+      String partitionName, Map<String, StatisticValue<?>> statistics) {
+    this.partitionName = partitionName;
+    this.statistics = statistics;
+  }
+
+  @Override
+  public String partitionName() {
+    return partitionName;
+  }
+
+  @Override
+  public Map<String, StatisticValue<?>> statistics() {
+    return statistics;
+  }
+
+  /** Validates the PartitionStatisticsUpdateDTO instance. */
+  public void validate() {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(partitionName), "\"partitionName\" must not be 
null or empty");
+    Preconditions.checkArgument(
+        statistics != null && !statistics.isEmpty(), "\"statistics\" must not 
be null or empty");
+  }
+
+  /**
+   * Creates a new builder for PartitionStatisticsUpdateDTO.
+   *
+   * @return a new Builder instance
+   */
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  /** Builder class for PartitionStatisticsUpdateDTO. */
+  public static class Builder {

Review Comment:
   I added the method `of`.



##########
core/src/main/java/org/apache/gravitino/Configs.java:
##########
@@ -445,4 +446,11 @@ private Configs() {}
           .longConf()
           .checkValue(value -> value > 0, 
ConfigConstants.POSITIVE_NUMBER_ERROR_MSG)
           .createWithDefault(5 * 60 * 1000L); // Default is 5 minutes
+
+  public static final ConfigEntry<String> 
PARTITION_STATS_STORAGE_FACTORY_CLASS_NAME =
+      new ConfigBuilder("gravitino.stats.partition.storageFactoryClassName")
+          .doc("The partition stats storage factory class.")
+          .version(ConfigConstants.VERSION_1_0_0)
+          .stringConf()
+          
.createWithDefault(MemoryPartitionStatsStorageFactory.class.getCanonicalName());

Review Comment:
   I will change this after lance storage is merged. I will a `TODO` now.



##########
core/src/main/java/org/apache/gravitino/stats/StatisticManager.java:
##########
@@ -48,17 +56,34 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class StatisticManager {
+public class StatisticManager implements Closeable {
 
+  private static final String OPTIONS_PREFIX = 
"gravitino.stats.partition.option.";
   private static final Logger LOG = 
LoggerFactory.getLogger(StatisticManager.class);
 
   private final EntityStore store;
 
   private final IdGenerator idGenerator;
+  private final PartitionStatisticStorage partitionStorage;
 
-  public StatisticManager(EntityStore store, IdGenerator idGenerator) {
+  public StatisticManager(EntityStore store, IdGenerator idGenerator, Config 
config) {
     this.store = store;
     this.idGenerator = idGenerator;
+    String className = 
config.get(Configs.PARTITION_STATS_STORAGE_FACTORY_CLASS_NAME);
+    Map<String, String> options = config.getConfigsWithPrefix(OPTIONS_PREFIX);
+    try {
+      PartitionStatisticStorageFactory factory =
+          (PartitionStatisticStorageFactory)
+              Class.forName(className).getDeclaredConstructor().newInstance();
+      this.partitionStorage = factory.create(options);
+    } catch (Exception e) {
+      LOG.error(
+          "Failed to create and initialize partition statistics file factory 
by name {}.",

Review Comment:
   Fixed.



##########
common/src/main/java/org/apache/gravitino/dto/stats/PartitionStatisticsDropDTO.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.dto.stats;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import java.util.List;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.stats.PartitionStatisticsDrop;
+
+/**
+ * PartitionStatisticsDropDTO is a Data Transfer Object (DTO) that represents 
the request to drop
+ * statistics for a specific partition in a data source.
+ */
+@EqualsAndHashCode
+@ToString
+public class PartitionStatisticsDropDTO implements PartitionStatisticsDrop {
+
+  @JsonProperty("partitionName")
+  private final String partitionName;
+
+  @JsonProperty("statisticNames")
+  private final List<String> statisticNames;
+
+  /** Default constructor for Jackson. */
+  protected PartitionStatisticsDropDTO() {
+    this(null, null);
+  }
+
+  private PartitionStatisticsDropDTO(String partitionName, List<String> 
statisticNames) {
+    this.partitionName = partitionName;
+    this.statisticNames = statisticNames;
+  }
+
+  @Override
+  public String partitionName() {
+    return partitionName;
+  }
+
+  @Override
+  public List<String> statisticNames() {
+    return statisticNames;
+  }
+
+  /** Validates the PartitionStatisticsDropDTO instance. */
+  public void validate() {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(partitionName), "\"partitionName\" must not be 
null or empty");
+    Preconditions.checkArgument(
+        statisticNames != null && !statisticNames.isEmpty(),
+        "\"statisticNames\" must not be null or empty");
+    for (String statisticName : statisticNames) {
+      Preconditions.checkArgument(
+          StringUtils.isNotBlank(statisticName),
+          "Each statistic \"name\" in \"statisticNames\" must not be null or 
empty");
+    }
+  }
+
+  /**
+   * Creates a new builder for PartitionStatisticsDropDTO.
+   *
+   * @return a new Builder instance
+   */
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  /** Builder for PartitionStatisticsDropDTO. */
+  public static class Builder {

Review Comment:
   I added method `of`.



##########
common/src/main/java/org/apache/gravitino/dto/stats/PartitionStatisticsDTO.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.dto.stats;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.stats.PartitionStatistics;
+import org.apache.gravitino.stats.Statistic;
+
+/**
+ * PartitionStatisticsDTO is a Data Transfer Object (DTO) that represents the 
statistics for a
+ * specific partition in a data source.
+ */
+@EqualsAndHashCode
+@ToString
+public class PartitionStatisticsDTO implements PartitionStatistics {
+
+  @JsonProperty("name")
+  private String name;
+
+  @JsonProperty("statistics")
+  private StatisticDTO[] statistics;
+
+  /** Default constructor for Jackson. */
+  protected PartitionStatisticsDTO() {
+    this(null, null);
+  }
+
+  private PartitionStatisticsDTO(String name, StatisticDTO[] statistics) {
+    this.name = name;
+    this.statistics = statistics;
+  }
+
+  @Override
+  public String name() {
+    return name;
+  }
+
+  @Override
+  public Statistic[] statistics() {
+    return statistics;
+  }
+
+  /** Validates the PartitionStatisticsDTO instance. */
+  public void validate() {
+    Preconditions.checkArgument(StringUtils.isNotBlank(name), "\"name\" must 
not be null or empty");
+    Preconditions.checkArgument(statistics != null, "\"statistics\" must not 
be null");
+    for (StatisticDTO statistic : statistics) {
+      statistic.validate();
+    }
+  }
+
+  /**
+   * Creates a new builder for PartitionStatisticsDTO.
+   *
+   * @return a new Builder instance
+   */
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  /** Builder for PartitionStatisticsDTO. */
+  public static class Builder {

Review Comment:
   OK. I changed to `of` method.



##########
common/src/main/java/org/apache/gravitino/dto/stats/PartitionStatisticsDTO.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.dto.stats;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.stats.PartitionStatistics;
+import org.apache.gravitino.stats.Statistic;
+
+/**
+ * PartitionStatisticsDTO is a Data Transfer Object (DTO) that represents the 
statistics for a
+ * specific partition in a data source.
+ */
+@EqualsAndHashCode
+@ToString
+public class PartitionStatisticsDTO implements PartitionStatistics {
+
+  @JsonProperty("name")
+  private String name;

Review Comment:
   OK.



##########
core/src/main/java/org/apache/gravitino/Configs.java:
##########
@@ -445,4 +446,11 @@ private Configs() {}
           .longConf()
           .checkValue(value -> value > 0, 
ConfigConstants.POSITIVE_NUMBER_ERROR_MSG)
           .createWithDefault(5 * 60 * 1000L); // Default is 5 minutes
+
+  public static final ConfigEntry<String> 
PARTITION_STATS_STORAGE_FACTORY_CLASS_NAME =
+      new ConfigBuilder("gravitino.stats.partition.storageFactoryClassName")

Review Comment:
   Changed.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to