bowenli86 commented on a change in pull request #8636: 
[FLINK-12237][hive]Support Hive table stats related operations in HiveCatalog
URL: https://github.com/apache/flink/pull/8636#discussion_r293934316
 
 

 ##########
 File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/HiveCatalog.java
 ##########
 @@ -1060,21 +1061,73 @@ private static Function 
instantiateHiveFunction(ObjectPath functionPath, HiveCat
                );
        }
 
+       private boolean isTablePartitioned(Table hiveTable) {
+               return hiveTable.getPartitionKeysSize() != 0;
+       }
+
        // ------ stats ------
 
        @Override
        public void alterTableStatistics(ObjectPath tablePath, 
CatalogTableStatistics tableStatistics, boolean ignoreIfNotExists) throws 
TableNotExistException, CatalogException {
-
+               try {
+                       Table hiveTable = getHiveTable(tablePath);
+                       // Set table stats
+                       if (needToUpdateStatistics(tableStatistics, 
hiveTable.getParameters())) {
+                               updateStatisticsParameters(tableStatistics, 
hiveTable.getParameters());
+                               client.alter_table(tablePath.getDatabaseName(), 
tablePath.getObjectName(), hiveTable);
+                       }
+               } catch (TableNotExistException e) {
+                       if (!ignoreIfNotExists) {
+                               throw e;
+                       }
+               } catch (TException e) {
+                       throw new CatalogException(String.format("Failed to 
alter table stats of table %s", tablePath.getFullName()), e);
+               }
        }
 
        @Override
        public void alterTableColumnStatistics(ObjectPath tablePath, 
CatalogColumnStatistics columnStatistics, boolean ignoreIfNotExists) throws 
TableNotExistException, CatalogException {
 
        }
 
+       private static boolean needToUpdateStatistics(CatalogTableStatistics 
statistics, Map<String, String> oldParameters) {
+               String oldRowCount = 
oldParameters.getOrDefault(StatsSetupConst.ROW_COUNT, "0");
 
 Review comment:
   These are basically setting default values for all types of Hive table 
stats. How about moving the `0`s to `HiveStatsUtil` and define them as `public 
static final` vars to make it easier to find and access across hive catalog 
code base?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to