hudi-agent commented on code in PR #19289:
URL: https://github.com/apache/hudi/pull/19289#discussion_r3586378894


##########
hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/util/HiveSchemaUtil.java:
##########
@@ -336,30 +338,62 @@ public static String generateSchemaString(HoodieSchema 
storageSchema, List<Strin
   }
 
   public static String generateSchemaString(HoodieSchema storageSchema, 
List<String> colsToSkip, boolean supportTimestamp) throws IOException {
+    return generateSchemaString(storageSchema, colsToSkip, supportTimestamp, 
Collections.emptyMap());
+  }
+
+  public static String generateSchemaString(HoodieSchema storageSchema, 
List<String> colsToSkip, boolean supportTimestamp,
+                                            Map<String, String> fieldDocs) 
throws IOException {
     Map<String, String> hiveSchema = convertSchemaToHiveSchema(storageSchema, 
supportTimestamp);
     StringBuilder columns = new StringBuilder();
     for (Map.Entry<String, String> hiveSchemaEntry : hiveSchema.entrySet()) {
-      if 
(!colsToSkip.contains(removeSurroundingTick(hiveSchemaEntry.getKey()))) {
+      String fieldName = removeSurroundingTick(hiveSchemaEntry.getKey());
+      if (!colsToSkip.contains(fieldName)) {
         columns.append(hiveSchemaEntry.getKey()).append(" ");
-        columns.append(hiveSchemaEntry.getValue()).append(", ");
+        columns.append(hiveSchemaEntry.getValue());
+        String doc = fieldDocs.get(fieldName.toLowerCase(Locale.ROOT));
+        if (doc != null) {
+          columns.append(" COMMENT 
'").append(escapeSqlComment(doc)).append("'");
+        }
+        columns.append(", ");
       }
     }
     // Remove the last ", "
     columns.delete(columns.length() - 2, columns.length());
     return columns.toString();
   }
 
+  private static String escapeSqlComment(String doc) {

Review Comment:
   🤖 nit: could you rename this to `stripSqlComment` (or `sanitizeSqlComment`)? 
In SQL, "escaping" a single quote conventionally means doubling it (`'` → 
`''`), so a future reader who sees `escapeSqlComment` may expect that behavior 
and be surprised to find the character is silently dropped instead.
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
hudi-sync/hudi-hive-sync/src/main/java/org/apache/hudi/hive/ddl/HMSDDLExecutor.java:
##########
@@ -282,6 +288,24 @@ public void updateTableComments(String tableName, 
Map<String, Pair<String, Strin
     }
   }
 
+  private static void setFieldComments(List<FieldSchema> fields, Map<String, 
Pair<String, String>> alterSchema) {
+    for (FieldSchema fieldSchema : fields) {
+      if (alterSchema.containsKey(fieldSchema.getName())) {
+        String comment = alterSchema.get(fieldSchema.getName()).getRight();
+        fieldSchema.setComment(comment);
+      }
+    }
+  }
+
+  private static void applyFieldDocs(List<FieldSchema> fields, Map<String, 
String> fieldDocs) {

Review Comment:
   🤖 nit: `applyFieldDocs` and `setFieldComments` (line 291) do structurally 
the same thing — iterate fields and call `fieldSchema.setComment(...)` — but 
they're named with different verbs (`apply` vs `set`) and different nouns 
(`Docs` vs `Comments`). Have you considered aligning them, e.g. 
`applyFieldComments` for the schema-comment case as well, so the pairing is 
obvious?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



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

Reply via email to