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


##########
core/src/main/java/org/apache/gravitino/stats/StatisticManager.java:
##########
@@ -85,6 +85,56 @@ public StatisticManager(EntityStore store, IdGenerator 
idGenerator, Config confi
     }
   }
 
+  /**
+   * Builds storage options map by merging entity store JDBC configs (as 
defaults) with
+   * partition-specific configs (which override defaults).
+   *
+   * @param config the configuration
+   * @return merged options map
+   */
+  private Map<String, String> buildStorageOptions(Config config) {
+    Map<String, String> options = new java.util.HashMap<>();

Review Comment:
   Could u use `HashMap` instead of `java.util.HashMap`?



##########
core/src/test/java/org/apache/gravitino/stats/storage/TestJdbcPartitionStatisticStorageIT.java:
##########
@@ -0,0 +1,618 @@
+/*
+ * 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.stats.storage;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.gravitino.EntityStore;
+import org.apache.gravitino.GravitinoEnv;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.MetadataObjects;
+import org.apache.gravitino.integration.test.container.ContainerSuite;
+import org.apache.gravitino.integration.test.container.MySQLContainer;
+import org.apache.gravitino.integration.test.util.TestDatabaseName;
+import org.apache.gravitino.meta.TableEntity;
+import org.apache.gravitino.stats.PartitionRange;
+import org.apache.gravitino.stats.PartitionStatisticsDrop;
+import org.apache.gravitino.stats.PartitionStatisticsModification;
+import org.apache.gravitino.stats.PartitionStatisticsUpdate;
+import org.apache.gravitino.stats.StatisticValue;
+import org.apache.gravitino.stats.StatisticValues;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * End-to-end integration tests for {@link JdbcPartitionStatisticStorage} 
using real MySQL database
+ * via Testcontainers.
+ *
+ * <p>These tests verify the complete flow from API calls through JDBC to a 
real MySQL instance.
+ * They cover:
+ *
+ * <ul>
+ *   <li>Full CRUD operations (Create, Read, Update, Delete)
+ *   <li>Partition range queries with different bound types
+ *   <li>Transaction integrity and rollback behavior
+ *   <li>Concurrent access from multiple threads
+ *   <li>JSON serialization/deserialization
+ *   <li>Audit information preservation
+ *   <li>Large dataset handling
+ * </ul>
+ */
+@Tag("gravitino-docker-test")
+public class TestJdbcPartitionStatisticStorageIT {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(TestJdbcPartitionStatisticStorageIT.class);
+
+  private static final ContainerSuite containerSuite = 
ContainerSuite.getInstance();
+  private static final TestDatabaseName TEST_DB_NAME = 
TestDatabaseName.MYSQL_MYSQL_ABSTRACT_IT;
+
+  private static JdbcPartitionStatisticStorage storage;
+  private static MySQLContainer mySQLContainer;
+  private static EntityStore entityStore;
+
+  private static final String METALAKE = "test_metalake";
+  private static final MetadataObject TEST_TABLE =
+      MetadataObjects.of(
+          Lists.newArrayList("catalog", "schema", "table"), 
MetadataObject.Type.TABLE);
+
+  @BeforeAll
+  public static void setup() throws Exception {
+    LOG.info("Starting MySQL container for partition statistics integration 
tests");
+
+    // Start MySQL container
+    containerSuite.startMySQLContainer(TEST_DB_NAME);

Review Comment:
   Could u refer to TestJdbckBackend to add the test cases about Postgres and 
H2?



##########
core/src/main/java/org/apache/gravitino/stats/storage/JdbcPartitionStatisticStorage.java:
##########
@@ -0,0 +1,430 @@
+/*
+ * 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.stats.storage;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.common.collect.Lists;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import javax.sql.DataSource;
+import org.apache.gravitino.Entity;
+import org.apache.gravitino.EntityStore;
+import org.apache.gravitino.GravitinoEnv;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.json.JsonUtils;
+import org.apache.gravitino.meta.AuditInfo;
+import org.apache.gravitino.meta.TableEntity;
+import org.apache.gravitino.stats.PartitionRange;
+import org.apache.gravitino.stats.PartitionStatisticsDrop;
+import org.apache.gravitino.stats.PartitionStatisticsUpdate;
+import org.apache.gravitino.stats.StatisticValue;
+import org.apache.gravitino.utils.MetadataObjectUtil;
+import org.apache.gravitino.utils.PrincipalUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * JDBC-based implementation of {@link PartitionStatisticStorage}.
+ *
+ * <p>This implementation stores partition statistics in a JDBC-compatible 
database table, using
+ * Apache Commons DBCP2 for connection pooling. It supports multiple database 
backends (MySQL,
+ * PostgreSQL, H2). Statistics are stored as JSON-serialized values along with 
audit information.
+ */
+public class JdbcPartitionStatisticStorage implements 
PartitionStatisticStorage {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(JdbcPartitionStatisticStorage.class);
+
+  private final DataSource dataSource;
+  private final EntityStore entityStore;
+
+  // SQL statements
+  private static final String INSERT_OR_UPDATE_SQL =

Review Comment:
   The SQL didn't take effect for PostgreSQL. You should use
   `INSERT INTO xxx  (xxxx) VALUES (xxx) ON CONFLICT (xxxx) DO UPDATE SET xxx";`



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