Copilot commented on code in PR #14953:
URL: https://github.com/apache/gravitino/pull/14953#discussion_r4550047692
##########
core/src/main/java/org/apache/gravitino/catalog/SemanticModelValidator.java:
##########
@@ -100,22 +115,51 @@ 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);
+ validateUniqueName(field.name(), namePath, "field", uniqueNames);
+ fieldNames.add(normalizeFieldName(field.name()));
+ }
+ return fieldNames;
+ }
Review Comment:
Field references are now resolved case-insensitively, but field-name
uniqueness is still only validated case-sensitively
(`validateUniqueName(field.name(), ...)`). With fields like `id` and `ID`,
`fieldNames` collapses them to the same normalized name and references become
ambiguous (and effectively point to an arbitrary one). To match the stated
Ossie name-resolution rules, validation should reject datasets that declare two
fields that are equal ignoring case (e.g., track
`normalizeFieldName(field.name())` in a map to report a duplicate with a useful
first-declared path).
##########
web-v2/web/src/lib/utils/semanticModel.js:
##########
@@ -38,6 +38,24 @@ export const semanticDataTypes = [
const isNonBlankString = value => typeof value === 'string' && value.trim()
!== ''
+const normalizeFieldName = name => name.toLowerCase()
+
+const declaredFieldNames = dataset =>
+ new Set(
+ (Array.isArray(dataset?.fields) ? dataset.fields : [])
+ .map(field => field?.name)
+ .filter(isNonBlankString)
+ .map(normalizeFieldName)
+ )
+
Review Comment:
The validator resolves key/join references case-insensitively via
`declaredFieldNames`, but it does not *reject* datasets that declare multiple
fields differing only by case (e.g., `id` and `ID`). Because
`declaredFieldNames` normalizes into a `Set`, those duplicates are silently
collapsed, making resolution ambiguous and potentially inconsistent with the
server-side contract. Consider adding an explicit case-insensitive uniqueness
check during dataset field validation (and surfacing an error tied to the
offending `datasets[i].fields[j].name` paths).
--
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]