jerryshao commented on code in PR #14953:
URL: https://github.com/apache/gravitino/pull/14953#discussion_r4560244184


##########
core/src/main/java/org/apache/gravitino/catalog/SemanticModelValidator.java:
##########
@@ -100,22 +116,53 @@ private static void validateSource(NameIdentifier source, 
String path) {
     }
   }
 
-  private static void validateFields(@Nullable Field[] fields, String path) {
+  private static Set<String> validateFields(@Nullable Field[] fields, String 
path) {
+    Set<String> fieldNames = new HashSet<>();
     if (fields == null) {
-      return;
+      return fieldNames;
     }
 
-    Map<String, String> fieldNames = new HashMap<>();
+    Map<String, String> uniqueNames = new HashMap<>();
     for (int index = 0; index < fields.length; index++) {
       String fieldPath = path + "[" + index + "]";
       Field field = fields[index];
       String namePath = fieldPath + ".name";
-      validateUniqueName(field.name(), namePath, "field", fieldNames);
+      // Key and relationship references resolve field names 
case-insensitively, so two
+      // declared names equal ignoring case would make every reference to them 
ambiguous.
+      validateUniqueName(normalizeFieldName(field.name()), namePath, "field", 
uniqueNames);

Review Comment:
   Case-insensitive uniqueness now rejects datasets that previously held names 
differing only by case, such as Id and ID. Is this required by the Ossie Name 
Resolution spec, and could already-persisted models be affected when they are 
altered?



##########
core/src/main/java/org/apache/gravitino/catalog/ManagedSemanticModelOperations.java:
##########
@@ -243,9 +243,17 @@ public SemanticModel alterSemanticModel(
           oldEntity -> {
             SemanticModelEntity candidate = applyChanges(oldEntity, 
sourceUpdate, changes);
             if (validateForWrite) {
-              writeValidator.accept(
-                  NameIdentifier.of(candidate.namespace(), candidate.name()),
-                  candidate.definition());
+              NameIdentifier candidateIdent =
+                  NameIdentifier.of(candidate.namespace(), candidate.name());
+              // Every replacement is validated, even when a later change 
replaces the
+              // definition again before the update is persisted.
+              for (SemanticModelChange change : changes) {
+                if (change instanceof SemanticModelChange.ReplaceDefinition) {
+                  writeValidator.accept(
+                      candidateIdent,

Review Comment:
   Intermediate replacements are validated, but the final candidate definition 
no longer goes through the write validator directly. Consider also validating 
the candidate definition so the merged result is always checked.



##########
core/src/main/java/org/apache/gravitino/catalog/SemanticModelValidator.java:
##########
@@ -86,11 +97,16 @@ private static void validateRootCustomExtensions(@Nullable 
CustomExtension[] ext
   }
 
   private static void validateDataset(
-      Dataset dataset, String path, Map<String, String> datasetNames) {
+      Dataset dataset,
+      String path,
+      Map<String, String> datasetNames,
+      Map<String, Set<String>> datasetFields) {
     String namePath = path + ".name";
     validateUniqueName(dataset.name(), namePath, "dataset", datasetNames);
     validateSource(dataset.source(), path + ".source");
-    validateFields(dataset.fields(), path + ".fields");
+    Set<String> fieldNames = validateFields(dataset.fields(), path + 
".fields");
+    validateKeys(dataset, path, fieldNames);

Review Comment:
   Any dataset with keys or relationship columns but no declared fields is now 
rejected, so existing stored models (and API clients) that reference source 
columns will fail on their next definition write. Please confirm this break is 
intended, and either add a migration or compatibility path, or document it 
clearly as a breaking change.



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