mchades commented on code in PR #14953:
URL: https://github.com/apache/gravitino/pull/14953#discussion_r4559048632
##########
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:
It's an upstream choice rather than a spec-mandated rule. The spec's Name
Resolution section doesn't pin down casing, but `validate.py` resolves
references with `casefold()` (`dataset_field_names()` /
`validate_field_references()`), and the expression-language doc states regular
identifiers are case-insensitive. Matching the old source-column lookup (exact
match) would diverge from upstream and reject definitions it accepts, e.g.
`primary_key: [Order_ID]` for a field declared `order_id`. And with field-name
uniqueness now checked on normalized names, the `id`/`ID` ambiguity this could
have created is closed off.
--
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]