jerryshao commented on code in PR #14953:
URL: https://github.com/apache/gravitino/pull/14953#discussion_r4558823476
##########
core/src/main/java/org/apache/gravitino/catalog/SemanticModelValidator.java:
##########
@@ -128,9 +172,47 @@ private static void validateRelationships(
validateUniqueName(relationship.name(), namePath, "relationship",
relationshipNames);
validateEndpoint(relationship.from(), path + ".from", datasetNames);
validateEndpoint(relationship.to(), path + ".to", datasetNames);
+ validateRelationshipColumns(relationship, path, datasetFields);
+ }
+ }
+
+ private static void validateRelationshipColumns(
+ Relationship relationship, String path, Map<String, Set<String>>
datasetFields) {
+ validateColumnReferences(
+ relationship.fromColumns(),
+ path + ".fromColumns",
+ relationship.from(),
+ datasetFields.get(relationship.from()));
+ validateColumnReferences(
+ relationship.toColumns(),
+ path + ".toColumns",
+ relationship.to(),
+ datasetFields.get(relationship.to()));
+ }
+
+ private static void validateColumnReferences(
+ String[] references, String path, String datasetName, @Nullable
Set<String> fieldNames) {
+ if (fieldNames == null) {
+ // The unknown endpoint is already reported by validateEndpoint.
+ return;
+ }
+ for (int index = 0; index < references.length; index++) {
+ validateFieldReference(references[index], path + "[" + index + "]",
datasetName, fieldNames);
}
}
+ private static void validateFieldReference(
+ String reference, String path, String datasetName, Set<String>
fieldNames) {
+ if (!fieldNames.contains(normalizeFieldName(reference))) {
+ throw invalid(
+ path, "'" + reference + "' is not a declared field of dataset '" +
datasetName + "'");
+ }
+ }
+
+ private static String normalizeFieldName(String name) {
Review Comment:
Is case-insensitive matching required by the Ossie Name Resolution rules, or
should it match the case-sensitive source column lookup that was removed?
##########
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()));
Review Comment:
Fields are collected in a lowercase set, but uniqueness is still checked
case-sensitively, so fields 'ID' and 'id' are both accepted and a key reference
becomes ambiguous. Make the duplicate check use the normalized name too.
##########
core/src/main/java/org/apache/gravitino/catalog/SemanticModelValidator.java:
##########
@@ -128,9 +172,47 @@ private static void validateRelationships(
validateUniqueName(relationship.name(), namePath, "relationship",
relationshipNames);
validateEndpoint(relationship.from(), path + ".from", datasetNames);
validateEndpoint(relationship.to(), path + ".to", datasetNames);
+ validateRelationshipColumns(relationship, path, datasetFields);
+ }
+ }
+
+ private static void validateRelationshipColumns(
+ Relationship relationship, String path, Map<String, Set<String>>
datasetFields) {
+ validateColumnReferences(
+ relationship.fromColumns(),
+ path + ".fromColumns",
+ relationship.from(),
+ datasetFields.get(relationship.from()));
+ validateColumnReferences(
+ relationship.toColumns(),
+ path + ".toColumns",
+ relationship.to(),
+ datasetFields.get(relationship.to()));
+ }
+
+ private static void validateColumnReferences(
+ String[] references, String path, String datasetName, @Nullable
Set<String> fieldNames) {
+ if (fieldNames == null) {
+ // The unknown endpoint is already reported by validateEndpoint.
+ return;
+ }
+ for (int index = 0; index < references.length; index++) {
+ validateFieldReference(references[index], path + "[" + index + "]",
datasetName, fieldNames);
}
}
+ private static void validateFieldReference(
Review Comment:
A dataset with no declared fields now rejects every primary key, unique key
and join column, and models stored earlier with source-column names will fail
on their next update. Please confirm this is intended and add a migration or
compatibility note.
--
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]