Skip to content

Commit 7310b77

Browse files
pghazanfarishirshanka
authored andcommitted
fix(patch-entity-registry): Remove exception for entities with key aspects. (datahub-project#5831)
* fix(patch-entity-registry): Remove exception for entities with key aspects. * test(patch-entity-registry): Fix failing unit test for entities with key aspect * test(patch-entity-registry): Fix checkstyle for PatchEntityRegistryTest.java * fix(patch-entity-registry): Remove duplicate semicolon. Co-authored-by: Parham Ghazanfari <[email protected]>
1 parent 353df40 commit 7310b77

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

entity-registry/src/main/java/com/linkedin/metadata/models/registry/PatchEntityRegistry.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,16 @@ private PatchEntityRegistry(DataSchemaFactory dataSchemaFactory, InputStream con
138138
entity.getAspects().stream().collect(Collectors.joining()));
139139
List<AspectSpec> aspectSpecs = new ArrayList<>();
140140
if (entity.getKeyAspect() != null) {
141-
throw new EntityRegistryException(
142-
"Patch Entities cannot define entities yet. They can only enhance an existing entity with additional (non-key) aspects");
143-
// aspectSpecs.add(getAspectSpec(entity.getKeyAspect(), entitySpecBuilder));
141+
AspectSpec keyAspectSpec = buildAspectSpec(entity.getKeyAspect(), entitySpecBuilder);
142+
log.info("Adding key aspect {} with spec {}", entity.getKeyAspect(), keyAspectSpec);
143+
aspectSpecs.add(keyAspectSpec);
144144
}
145145
entity.getAspects().forEach(aspect -> {
146-
AspectSpec aspectSpec = buildAspectSpec(aspect, entitySpecBuilder);
147-
log.info("Adding aspect {} with spec {}", aspect, aspectSpec);
148-
aspectSpecs.add(aspectSpec);
146+
if (!aspect.equals(entity.getKeyAspect())) {
147+
AspectSpec aspectSpec = buildAspectSpec(aspect, entitySpecBuilder);
148+
log.info("Adding aspect {} with spec {}", aspect, aspectSpec);
149+
aspectSpecs.add(aspectSpec);
150+
}
149151
});
150152

151153
EntitySpec entitySpec =

entity-registry/src/test/java/com/linkedin/metadata/models/registry/PatchEntityRegistryTest.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.linkedin.metadata.models.registry;
22

3+
import com.linkedin.metadata.models.DataSchemaFactory;
34
import com.linkedin.metadata.models.EntitySpec;
45
import com.linkedin.metadata.models.EventSpec;
6+
import java.nio.file.Paths;
57
import java.util.Map;
6-
import org.apache.maven.artifact.versioning.ComparableVersion;
78
import org.testng.annotations.Test;
89

910
import static org.testng.Assert.*;
@@ -14,7 +15,11 @@ public class PatchEntityRegistryTest {
1415
@Test
1516
public void testEntityRegistryLoad() throws Exception, EntityRegistryException {
1617
PatchEntityRegistry patchEntityRegistry = new PatchEntityRegistry(
17-
TestConstants.BASE_DIRECTORY + "/" + TestConstants.TEST_REGISTRY + "/" + TestConstants.TEST_VERSION.toString(),
18+
TestConstants.BASE_DIRECTORY
19+
+ "/"
20+
+ TestConstants.TEST_REGISTRY
21+
+ "/"
22+
+ TestConstants.TEST_VERSION.toString(),
1823
TestConstants.TEST_REGISTRY, TestConstants.TEST_VERSION);
1924

2025
Map<String, EntitySpec> entitySpecs = patchEntityRegistry.getEntitySpecs();
@@ -34,14 +39,28 @@ public void testEntityRegistryLoad() throws Exception, EntityRegistryException {
3439
}
3540

3641
/**
37-
* Validate that patch entity registries cannot have key aspects
42+
* Validate that patch entity registries can have key aspects
3843
* @throws Exception
3944
* @throws EntityRegistryException
4045
*/
4146
@Test
42-
public void testEntityRegistryWithKeyLoad() {
43-
assertThrows(EntityRegistryException.class,
44-
() -> new PatchEntityRegistry("src/test_plugins/mycompany-full-model/0.0.1", "mycompany-full-model",
45-
new ComparableVersion("0.0.1")));
47+
public void testEntityRegistryWithKeyLoad() throws Exception, EntityRegistryException {
48+
DataSchemaFactory dataSchemaFactory = DataSchemaFactory.withCustomClasspath(
49+
Paths.get(TestConstants.BASE_DIRECTORY
50+
+ "/"
51+
+ TestConstants.TEST_REGISTRY
52+
+ "/"
53+
+ TestConstants.TEST_VERSION.toString()));
54+
55+
PatchEntityRegistry patchEntityRegistry = new PatchEntityRegistry(
56+
dataSchemaFactory, Paths.get("src/test_plugins/mycompany-full-model/0.0.1/entity-registry.yaml"),
57+
TestConstants.TEST_REGISTRY, TestConstants.TEST_VERSION);
58+
59+
Map<String, EntitySpec> entitySpecs = patchEntityRegistry.getEntitySpecs();
60+
assertEquals(entitySpecs.values().size(), 1);
61+
EntitySpec newThingSpec = patchEntityRegistry.getEntitySpec("newThing");
62+
assertNotNull(newThingSpec);
63+
assertNotNull(newThingSpec.getKeyAspectSpec());
64+
assertNotNull(newThingSpec.getAspectSpec(TestConstants.TEST_ASPECT_NAME));
4665
}
4766
}

entity-registry/src/test_plugins/mycompany-full-model/0.0.1/entity-registry.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
id: mycompany-full-model
44
entities:
55
- name: newThing
6-
keyAspect: ownership
6+
keyAspect: testDataQualityRules
77
aspects:
8-
- ownership
8+
- testDataQualityRules

0 commit comments

Comments
 (0)