dengzhhu653 commented on code in PR #5578: URL: https://github.com/apache/hive/pull/5578#discussion_r1924633025
########## standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java: ########## @@ -10330,6 +10330,108 @@ public boolean deletePartitionColumnStatistics(String catName, String dbName, St return ret; } + @Override + public boolean deletePartitionMultiColumnStatistics(String catName, String dbName, String tableName, + String partName, List<String> partVals, List<String> colNames, String engine) + throws NoSuchObjectException, MetaException, InvalidObjectException, InvalidInputException { + boolean ret = false; + Query query = null; + dbName = org.apache.commons.lang3.StringUtils.defaultString(dbName, + Warehouse.DEFAULT_DATABASE_NAME); + catName = normalizeIdentifier(catName); + if (tableName == null) { + throw new InvalidInputException("Table name is null."); + } + try { + openTransaction(); + MTable mTable = getMTable(catName, dbName, tableName); + MPartitionColumnStatistics mStatsObj; + List<MPartitionColumnStatistics> mStatsObjColl; + if (mTable == null) { + throw new NoSuchObjectException("Table " + tableName + + " for which stats deletion is requested doesn't exist"); + } + // Note: this does not verify ACID state; called internally when removing cols/etc. + // Also called via an unused metastore API that checks for ACID tables. + MPartition mPartition = getMPartition(catName, dbName, tableName, partVals, mTable); + if (mPartition == null) { + throw new NoSuchObjectException("Partition " + partName + + " for which stats deletion is requested doesn't exist"); + } + query = pm.newQuery(MPartitionColumnStatistics.class); + String filter; + String parameters; + if (colNames != null) { + filter = "partition.partitionName == t1 && partition.table.database.name == t2 && partition.table.tableName == t3 && " + + "t4.contains(colName) && partition.table.database.catalogName == t5" + (engine != null ? " && engine == t6" : ""); + parameters = "java.lang.String t1, java.lang.String t2, java.lang.String t3, " + + "java.util.Collection t4, java.lang.String t5" + (engine != null ? ", java.lang.String t6" : ""); + } else { + filter = "partition.partitionName == t1 && partition.table.database.name == t2 && partition.table.tableName == t3 && partition.table.database.catalogName == t4" + (engine != null ? " && engine == t5" : ""); + parameters = "java.lang.String t1, java.lang.String t2, java.lang.String t3, java.lang.String t4" + (engine != null ? ", java.lang.String t5" : ""); + } + query.setFilter(filter); + query.declareParameters(parameters); + if (colNames != null) { + query.setUnique(true); + for (String colName : colNames){ + // trim the extra spaces, and change to lowercase + normalizeIdentifier(colName); + } + if (engine != null) { + mStatsObj = + (MPartitionColumnStatistics) query.executeWithArray(partName.trim(), + normalizeIdentifier(dbName), + normalizeIdentifier(tableName), + colNames, + normalizeIdentifier(catName), + engine); + } else { + mStatsObj = + (MPartitionColumnStatistics) query.executeWithArray(partName.trim(), + normalizeIdentifier(dbName), + normalizeIdentifier(tableName), + colNames, + normalizeIdentifier(catName)); + } + pm.retrieve(mStatsObj); + if (mStatsObj != null) { + pm.deletePersistent(mStatsObj); + } else { + throw new NoSuchObjectException("Column stats doesn't exist for table=" + + TableName.getQualified(catName, dbName, tableName) + + " partition=" + partName + " col=" + String.join(", ", colNames)); + } + } else { Review Comment: The difference between the two conditions is the input parameters of the `Query`, we can use a list to collect all parameters and then push it to `query.executeWithArray(...`, example: ``` List parameters = new ArrayList(); parameters.add(normalizeIdentifier(tableName)); parameters.add(normalizeIdentifier(dbName)); parameters.add(normalizeIdentifier(catName)); if (colNames != null && !colNames.isEmpty()) { parameters.add(colNames); } if (engine != null) { parameters.add(engine); } mStatsObjColl = (List<MTableColumnStatistics>) query.executeWithArray(parameters.toArray()); ... ``` -- 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: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org