|
14 | 14 | PropertyValueClass,
|
15 | 15 | StructuredPropertyDefinitionClass,
|
16 | 16 | )
|
17 |
| -from datahub.metadata.urns import StructuredPropertyUrn, Urn |
| 17 | +from datahub.metadata.urns import DataTypeUrn, StructuredPropertyUrn, Urn |
18 | 18 | from datahub.utilities.urns._urn_base import URN_TYPES
|
19 | 19 |
|
20 | 20 | logging.basicConfig(level=logging.INFO)
|
@@ -86,19 +86,31 @@ class StructuredProperties(ConfigModel):
|
86 | 86 |
|
87 | 87 | @validator("type")
|
88 | 88 | def validate_type(cls, v: str) -> str:
|
89 |
| - # Convert to lowercase if needed |
90 |
| - if not v.islower(): |
| 89 | + # This logic is somewhat hacky, since we need to deal with |
| 90 | + # 1. fully qualified urns |
| 91 | + # 2. raw data types, that need to get the datahub namespace prefix |
| 92 | + # While keeping the user-facing interface and error messages clean. |
| 93 | + |
| 94 | + if not v.startswith("urn:li:") and not v.islower(): |
| 95 | + # Convert to lowercase if needed |
| 96 | + v = v.lower() |
91 | 97 | logger.warning(
|
92 |
| - f"Structured property type should be lowercase. Updated to {v.lower()}" |
| 98 | + f"Structured property type should be lowercase. Updated to {v}" |
93 | 99 | )
|
94 |
| - v = v.lower() |
| 100 | + |
| 101 | + urn = Urn.make_data_type_urn(v) |
95 | 102 |
|
96 | 103 | # Check if type is allowed
|
97 |
| - if not AllowedTypes.check_allowed_type(v): |
| 104 | + data_type_urn = DataTypeUrn.from_string(urn) |
| 105 | + unqualified_data_type = data_type_urn.id |
| 106 | + if unqualified_data_type.startswith("datahub."): |
| 107 | + unqualified_data_type = unqualified_data_type[len("datahub.") :] |
| 108 | + if not AllowedTypes.check_allowed_type(unqualified_data_type): |
98 | 109 | raise ValueError(
|
99 |
| - f"Type {v} is not allowed. Allowed types are {AllowedTypes.values()}" |
| 110 | + f"Type {unqualified_data_type} is not allowed. Allowed types are {AllowedTypes.values()}" |
100 | 111 | )
|
101 |
| - return v |
| 112 | + |
| 113 | + return urn |
102 | 114 |
|
103 | 115 | @property
|
104 | 116 | def fqn(self) -> str:
|
|
0 commit comments