dengzhhu653 commented on code in PR #6198:
URL: https://github.com/apache/hive/pull/6198#discussion_r2694745500


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetaStoreDirectSql.java:
##########
@@ -3304,6 +3307,192 @@ public List<Void> run(List<String> input) throws 
Exception {
     return true;
   }
 
+  // a helper function which will firstly get the current 
COLUMN_STATS_ACCURATE parameter on table level
+  // secondly convert the JSON String into map, and update the information in 
it, and convert it back to JSON
+  // thirdly update the COLUMN_STATS_ACCURATE parameter with the new value on 
table level using directSql
+  public long updateColumnStatsAccurateForTable(Table table, List<String> 
droppedCols) throws MetaException {
+    String currentValue = table.getParameters().get("COLUMN_STATS_ACCURATE");
+    if (currentValue == null) return 0;
+
+    try {
+      ObjectMapper mapper = new ObjectMapper();
+
+      // Deserialize the JSON into a map
+      Map<String, Object> statsMap = mapper.readValue(currentValue, new 
TypeReference<Map<String, Object>>() {});
+
+      // Get the COLUMN_STATS object if it exists
+      Object columnStatsObj = statsMap.get("COLUMN_STATS");
+
+      if (columnStatsObj instanceof Map) {
+        Map<String, String> columnStats = (Map<String, String>) columnStatsObj;
+
+        boolean removeAll = (droppedCols == null || droppedCols.isEmpty());
+
+        if (removeAll) {
+          // Remove entire column stats
+          statsMap.remove("COLUMN_STATS");
+        } else {
+          // Remove only the dropped columns
+          for (String col : droppedCols) {
+            if (col != null) {
+              columnStats.remove(col.toLowerCase());
+            }
+          }
+          if (columnStats.isEmpty()) {
+            statsMap.remove("COLUMN_STATS");
+          }
+        }
+      }
+
+      // Serialize the map into a new JSON string
+      String updatedValue = mapper.writeValueAsString(statsMap);

Review Comment:
   use `StatsSetupConst.removeColumnStatsState`?



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to