deniskuzZ commented on code in PR #5976:
URL: https://github.com/apache/hive/pull/5976#discussion_r2210484236


##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/utils/MetaStoreServerUtils.java:
##########
@@ -1636,27 +1638,42 @@ public static String getPartitionName(Path tablePath, 
Path partitionPath, Set<St
     return result;
   }
 
-  public static String getNormalisedPartitionValue(String partitionValue, 
String type) {
-
-    if (!NumberUtils.isParsable(partitionValue)) {
+  public static String getNormalisedPartitionValue(String partitionValue, 
String type,
+      Configuration conf) {
+    if ((!NumberUtils.isParsable(partitionValue) && !Objects.equals(type, 
ColumnType.STRING_TYPE_NAME)

Review Comment:
   I see it like
   ````
   public static String getNormalisedPartitionValue(String partitionValue, 
String type, Configuration conf) {
     // 1. Handle simple exit cases first.
     if (type == null) {
         return partitionValue;
     }
   
     if (Objects.equals(partitionValue, MetastoreConf.getVar(conf, 
MetastoreConf.ConfVars.DEFAULTPARTITIONNAME))) {
         // This is the special partition name for NULL values. It should never 
be parsed.
         return partitionValue;
     }
   
     // 2. If the type is not numeric, no normalization is needed.
     String colType = ColumnType.getTypeName(type);
     if (!ColumnType.numericTypes.contains(colType)) {
         return partitionValue;
     }
   
     // 3. At this point, we have a numeric type that needs normalization.
   LOG.debug("Normalizing partition value '{}' for type '{}'.", partitionValue, 
type);
     try {
         switch (colType) {
             case ColumnType.TINYINT_TYPE_NAME:
             case ColumnType.SMALLINT_TYPE_NAME:
             case ColumnType.INT_TYPE_NAME:
                 return Integer.toString(Integer.parseInt(partitionValue));
             case ColumnType.BIGINT_TYPE_NAME:
                 return Long.toString(Long.parseLong(partitionValue));
             case ColumnType.FLOAT_TYPE_NAME:
                 return Float.toString(Float.parseFloat(partitionValue));
             case ColumnType.DOUBLE_TYPE_NAME:
                 return Double.toString(Double.parseDouble(partitionValue));
             case ColumnType.DECIMAL_TYPE_NAME:
                 // Removes trailing zeros (e.g., 1.200 -> 1.2)
                 return new 
BigDecimal(partitionValue).stripTrailingZeros().toPlainString();
             default:
                 // This case should not be reachable due to the NUMERIC_TYPES 
check, but acts as a safeguard.
                 break;
         }
     } catch (NumberFormatException e) {
         // 4. Handle cases where the value cannot be parsed as the expected 
number type.
         String validationMode = MetastoreConf.getVar(conf, 
MetastoreConf.ConfVars.MSCK_PATH_VALIDATION);
   
         if ("throw".equals(validationMode)) {
             LOG.error("Invalid partition value: Cannot parse '{}' as type 
'{}'. Failing MSCK. " +
                     "Set hive.msck.path.validation=skip to ignore invalid 
partitions.", partitionValue, type);
             throw e;
         } else if ("skip".equals(validationMode)) {
             LOG.warn("Skipping invalid partition value '{}' for type '{}' due 
to parsing error.", partitionValue, type);
             return null; // Signals the caller to skip this partition.
         }
     }
     return partitionValue;
   }
   ````



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

Reply via email to