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


##########
core/src/test/java/org/apache/gravitino/stats/storage/TestMysqlPartitionStatisticStorageIT.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 MysqlPartitionStatisticStorage} 
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 TestMysqlPartitionStatisticStorageIT {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(TestMysqlPartitionStatisticStorageIT.class);
+
+  private static final ContainerSuite containerSuite = 
ContainerSuite.getInstance();
+  private static final TestDatabaseName TEST_DB_NAME = 
TestDatabaseName.MYSQL_MYSQL_ABSTRACT_IT;
+
+  private static MysqlPartitionStatisticStorage 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);
+    mySQLContainer = containerSuite.getMySQLContainer();
+
+    // Create database schema
+    createSchema();
+
+    // Create storage factory with MySQL container connection
+    Map<String, String> properties = Maps.newHashMap();
+    properties.put("jdbc-url", mySQLContainer.getJdbcUrl(TEST_DB_NAME));
+    properties.put("jdbc-user", mySQLContainer.getUsername());
+    properties.put("jdbc-password", mySQLContainer.getPassword());
+    properties.put("jdbc-driver", 
mySQLContainer.getDriverClassName(TEST_DB_NAME));
+
+    MysqlPartitionStatisticStorageFactory factory = new 
MysqlPartitionStatisticStorageFactory();
+    storage = (MysqlPartitionStatisticStorage) factory.create(properties);
+
+    // Mock EntityStore to return a test table entity
+    entityStore = mock(EntityStore.class);
+    TableEntity tableEntity = mock(TableEntity.class);
+    when(entityStore.get(any(), any(), any())).thenReturn(tableEntity);
+    when(tableEntity.id()).thenReturn(100L);
+    FieldUtils.writeField(GravitinoEnv.getInstance(), "entityStore", 
entityStore, true);
+
+    LOG.info("MySQL partition statistics storage initialized successfully");
+  }
+
+  @AfterAll
+  public static void teardown() throws IOException {
+    if (storage != null) {
+      storage.close();
+      LOG.info("MySQL partition statistics storage closed");
+    }
+  }
+
+  /** Creates the partition_statistic_meta table in the test database. */
+  private static void createSchema() throws SQLException {
+    String jdbcUrl = mySQLContainer.getJdbcUrl(TEST_DB_NAME);
+    String username = mySQLContainer.getUsername();
+    String password = mySQLContainer.getPassword();
+
+    try (Connection conn = DriverManager.getConnection(jdbcUrl, username, 
password);
+        Statement stmt = conn.createStatement()) {
+
+      String createTableSQL =
+          "CREATE TABLE IF NOT EXISTS `partition_statistic_meta` ("
+              + "  `table_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'table id 
from table_meta',"
+              + "  `partition_name` VARCHAR(1024) NOT NULL COMMENT 'partition 
name',"
+              + "  `statistic_name` VARCHAR(128) NOT NULL COMMENT 'statistic 
name',"
+              + "  `statistic_value` MEDIUMTEXT NOT NULL COMMENT 'statistic 
value as JSON',"
+              + "  `audit_info` TEXT NOT NULL COMMENT 'audit information as 
JSON',"
+              + "  `created_at` BIGINT(20) UNSIGNED NOT NULL COMMENT 'creation 
timestamp in milliseconds',"
+              + "  `updated_at` BIGINT(20) UNSIGNED NOT NULL COMMENT 'last 
update timestamp in milliseconds',"
+              + "  PRIMARY KEY (`table_id`, `partition_name`(255), 
`statistic_name`),"
+              + "  KEY `idx_table_partition` (`table_id`, 
`partition_name`(255))"
+              + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"
+              + "  COMMENT 'partition statistics metadata'";
+
+      stmt.execute(createTableSQL);
+      LOG.info("Created partition_statistic_meta table");
+    }
+  }
+
+  @Test
+  public void testFullCRUDLifecycle() throws IOException {
+    LOG.info("Testing full CRUD lifecycle");
+
+    // 1. CREATE - Insert statistics for a partition
+    List<PartitionStatisticsUpdate> updates = new ArrayList<>();
+    Map<String, StatisticValue<?>> stats = Maps.newHashMap();
+    stats.put("custom-rowCount", StatisticValues.longValue(1000L));
+    stats.put("custom-sizeBytes", StatisticValues.longValue(5000000L));
+    stats.put("custom-lastModified", 
StatisticValues.stringValue("2026-01-21"));
+
+    updates.add(PartitionStatisticsModification.update("partition_2026_01", 
stats));
+
+    List<MetadataObjectStatisticsUpdate> objectUpdates =
+        Lists.newArrayList(MetadataObjectStatisticsUpdate.of(TEST_TABLE, 
updates));
+
+    storage.updateStatistics(METALAKE, objectUpdates);
+    LOG.info("Created statistics for partition_2026_01");
+
+    // 2. READ - Verify statistics exist
+    List<PersistedPartitionStatistics> result =
+        storage.listStatistics(METALAKE, TEST_TABLE, 
PartitionRange.ALL_PARTITIONS);
+
+    assertEquals(1, result.size());
+    assertEquals("partition_2026_01", result.get(0).partitionName());

Review Comment:
   The partition name 'partition_2026_01' references a future date. This 
assertion should match the corrected partition name in the test setup.



##########
core/src/test/java/org/apache/gravitino/stats/storage/TestMysqlPartitionStatisticStorageIT.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 MysqlPartitionStatisticStorage} 
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 TestMysqlPartitionStatisticStorageIT {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(TestMysqlPartitionStatisticStorageIT.class);
+
+  private static final ContainerSuite containerSuite = 
ContainerSuite.getInstance();
+  private static final TestDatabaseName TEST_DB_NAME = 
TestDatabaseName.MYSQL_MYSQL_ABSTRACT_IT;
+
+  private static MysqlPartitionStatisticStorage 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);
+    mySQLContainer = containerSuite.getMySQLContainer();
+
+    // Create database schema
+    createSchema();
+
+    // Create storage factory with MySQL container connection
+    Map<String, String> properties = Maps.newHashMap();
+    properties.put("jdbc-url", mySQLContainer.getJdbcUrl(TEST_DB_NAME));
+    properties.put("jdbc-user", mySQLContainer.getUsername());
+    properties.put("jdbc-password", mySQLContainer.getPassword());
+    properties.put("jdbc-driver", 
mySQLContainer.getDriverClassName(TEST_DB_NAME));
+
+    MysqlPartitionStatisticStorageFactory factory = new 
MysqlPartitionStatisticStorageFactory();
+    storage = (MysqlPartitionStatisticStorage) factory.create(properties);
+
+    // Mock EntityStore to return a test table entity
+    entityStore = mock(EntityStore.class);
+    TableEntity tableEntity = mock(TableEntity.class);
+    when(entityStore.get(any(), any(), any())).thenReturn(tableEntity);
+    when(tableEntity.id()).thenReturn(100L);
+    FieldUtils.writeField(GravitinoEnv.getInstance(), "entityStore", 
entityStore, true);
+
+    LOG.info("MySQL partition statistics storage initialized successfully");
+  }
+
+  @AfterAll
+  public static void teardown() throws IOException {
+    if (storage != null) {
+      storage.close();
+      LOG.info("MySQL partition statistics storage closed");
+    }
+  }
+
+  /** Creates the partition_statistic_meta table in the test database. */
+  private static void createSchema() throws SQLException {
+    String jdbcUrl = mySQLContainer.getJdbcUrl(TEST_DB_NAME);
+    String username = mySQLContainer.getUsername();
+    String password = mySQLContainer.getPassword();
+
+    try (Connection conn = DriverManager.getConnection(jdbcUrl, username, 
password);
+        Statement stmt = conn.createStatement()) {
+
+      String createTableSQL =
+          "CREATE TABLE IF NOT EXISTS `partition_statistic_meta` ("
+              + "  `table_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'table id 
from table_meta',"
+              + "  `partition_name` VARCHAR(1024) NOT NULL COMMENT 'partition 
name',"
+              + "  `statistic_name` VARCHAR(128) NOT NULL COMMENT 'statistic 
name',"
+              + "  `statistic_value` MEDIUMTEXT NOT NULL COMMENT 'statistic 
value as JSON',"
+              + "  `audit_info` TEXT NOT NULL COMMENT 'audit information as 
JSON',"
+              + "  `created_at` BIGINT(20) UNSIGNED NOT NULL COMMENT 'creation 
timestamp in milliseconds',"
+              + "  `updated_at` BIGINT(20) UNSIGNED NOT NULL COMMENT 'last 
update timestamp in milliseconds',"
+              + "  PRIMARY KEY (`table_id`, `partition_name`(255), 
`statistic_name`),"
+              + "  KEY `idx_table_partition` (`table_id`, 
`partition_name`(255))"
+              + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin"
+              + "  COMMENT 'partition statistics metadata'";
+
+      stmt.execute(createTableSQL);
+      LOG.info("Created partition_statistic_meta table");
+    }
+  }
+
+  @Test
+  public void testFullCRUDLifecycle() throws IOException {
+    LOG.info("Testing full CRUD lifecycle");
+
+    // 1. CREATE - Insert statistics for a partition
+    List<PartitionStatisticsUpdate> updates = new ArrayList<>();
+    Map<String, StatisticValue<?>> stats = Maps.newHashMap();
+    stats.put("custom-rowCount", StatisticValues.longValue(1000L));
+    stats.put("custom-sizeBytes", StatisticValues.longValue(5000000L));
+    stats.put("custom-lastModified", 
StatisticValues.stringValue("2026-01-21"));
+
+    updates.add(PartitionStatisticsModification.update("partition_2026_01", 
stats));

Review Comment:
   The partition name 'partition_2026_01' references a future date (2026). 
Consider using a past or current year like 'partition_2024_01' or 
'partition_2025_01' to avoid confusion in test data.



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