jerqi commented on code in PR #9779: URL: https://github.com/apache/gravitino/pull/9779#discussion_r2750469456
########## 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";` MySQL and PostgreSQL will use different SQL. -- 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]
