Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
package org.openmetadata.it.tests;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openmetadata.it.util.SearchDocs.awaitDocAsserted;

import com.fasterxml.jackson.databind.JsonNode;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openmetadata.it.bootstrap.SharedEntities;
import org.openmetadata.it.util.SdkClients;
import org.openmetadata.it.util.TestNamespace;
import org.openmetadata.it.util.TestNamespaceExtension;
import org.openmetadata.schema.api.VoteRequest;
import org.openmetadata.schema.api.data.CreateDatabase;
import org.openmetadata.schema.api.data.CreateDatabaseSchema;
import org.openmetadata.schema.api.data.CreateTable;
import org.openmetadata.schema.entity.data.Database;
import org.openmetadata.schema.entity.data.DatabaseSchema;
import org.openmetadata.schema.entity.data.Table;
import org.openmetadata.schema.type.ChangeEvent;
import org.openmetadata.schema.type.Column;
import org.openmetadata.schema.type.ColumnDataType;
import org.openmetadata.schema.type.EntityReference;
import org.openmetadata.schema.type.TagLabel;
import org.openmetadata.sdk.client.OpenMetadataClient;
import org.openmetadata.sdk.network.HttpMethod;

/**
* A PUT carries only what its sender owns, and a PATCH only what it changes. The entity those
* updates indexed kept neither the tags a PUT merges in, nor followers and votes, nor what the
* entity inherits, so search lost them on every such update. Each check waits for a marker of the
* update, then asserts what survived that same write.
*/
@Execution(ExecutionMode.CONCURRENT)
@ExtendWith(TestNamespaceExtension.class)
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class EntityUpdateSearchDocIT {

private static final String TABLE_INDEX = "table_search_index";
private static final String TIER1 = "Tier.Tier1";
private static final String CHANGED_DESCRIPTION = "changed by a later PUT";

@Test
void put_withoutTags_keepsTableAndColumnTagsInSearchDoc(TestNamespace ns) {
Table table =
createTable(
createSchema(ns, false, null),
List.of(SharedEntities.get().PERSONAL_DATA_TAG_LABEL, classificationLabel(TIER1)),
List.of(SharedEntities.get().PII_SENSITIVE_TAG_LABEL),
List.of());
awaitDocAsserted(TABLE_INDEX, table.getId(), EntityUpdateSearchDocIT::assertTagsAndTier);

SdkClients.adminClient().tables().createOrUpdate(changedDescriptionPut(table));

awaitDocAsserted(
TABLE_INDEX,
table.getId(),
doc -> {
assertEquals(CHANGED_DESCRIPTION, doc.path("description").asText());
assertTagsAndTier(doc);
});
}

@Test
void put_keepsFollowersAndVotesInSearchDoc(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
Table table = createTable(createSchema(ns, false, null), List.of(), List.of(), List.of());
UUID follower = SharedEntities.get().USER1.getId();
client
.getHttpClient()
.execute(
HttpMethod.PUT,
"/v1/tables/" + table.getId() + "/vote",
new VoteRequest().withUpdatedVoteType(VoteRequest.VoteType.VOTED_UP),
ChangeEvent.class);
client
.getHttpClient()
.execute(
HttpMethod.PUT,
"/v1/tables/" + table.getId() + "/followers",
follower,
ChangeEvent.class);
awaitDocAsserted(TABLE_INDEX, table.getId(), doc -> assertFollowerAndVote(doc, follower));

client.tables().createOrUpdate(changedDescriptionPut(table));

awaitDocAsserted(
TABLE_INDEX,
table.getId(),
doc -> {
assertEquals(CHANGED_DESCRIPTION, doc.path("description").asText());
assertFollowerAndVote(doc, follower);
});
}

@Test
void put_keepsInheritedDomainInSearchDoc(TestNamespace ns) {
Table table = createTable(createSchema(ns, true, null), List.of(), List.of(), List.of());
awaitDocAsserted(TABLE_INDEX, table.getId(), EntityUpdateSearchDocIT::assertSharedDomain);

SdkClients.adminClient().tables().createOrUpdate(changedDescriptionPut(table));

awaitDocAsserted(
TABLE_INDEX,
table.getId(),
doc -> {
assertEquals(CHANGED_DESCRIPTION, doc.path("description").asText());
assertSharedDomain(doc);
});
}

@Test
void patch_removingDirectOwner_indexesInheritedOwner(TestNamespace ns) {
OpenMetadataClient client = SdkClients.adminClient();
EntityReference schemaOwner = SharedEntities.get().USER1_REF;
EntityReference directOwner = SharedEntities.get().USER2_REF;
Table table =
createTable(
createSchema(ns, false, schemaOwner), List.of(), List.of(), List.of(directOwner));
awaitDocAsserted(TABLE_INDEX, table.getId(), doc -> assertOwner(doc, directOwner));

Table withoutOwner = client.tables().get(table.getId().toString(), "owners");
withoutOwner.setOwners(List.of());
client.tables().update(table.getId().toString(), withoutOwner);

awaitDocAsserted(TABLE_INDEX, table.getId(), doc -> assertOwner(doc, schemaOwner));
}

/**
* A schema in its own database. With {@code inDomain} the database carries the shared domain for
* its tables to inherit; a non-null {@code owner} owns the schema for the same purpose.
*/
private static DatabaseSchema createSchema(
TestNamespace ns, boolean inDomain, EntityReference owner) {
OpenMetadataClient client = SdkClients.adminClient();
CreateDatabase createDatabase =
new CreateDatabase()
.withName(ns.prefix("db"))
.withService(SharedEntities.get().MYSQL_SERVICE.getFullyQualifiedName());
if (inDomain) {
createDatabase.withDomains(List.of(sharedDomainFqn()));
}
Database database = client.databases().create(createDatabase);
CreateDatabaseSchema createSchema =
new CreateDatabaseSchema()
.withName(ns.prefix("schema"))
.withDatabase(database.getFullyQualifiedName());
if (owner != null) {
createSchema.withOwners(List.of(owner));
}
return client.databaseSchemas().create(createSchema);
}

private static Table createTable(
DatabaseSchema schema,
List<TagLabel> tags,
List<TagLabel> columnTags,
List<EntityReference> owners) {
return SdkClients.adminClient()
.tables()
.create(
new CreateTable()
.withName(schema.getName() + "_table")
.withDatabaseSchema(schema.getFullyQualifiedName())
.withColumns(List.of(idColumn().withTags(columnTags)))
.withTags(tags)
.withOwners(owners));
}

/** What an ingestion re-run sends: the table's identity and columns, nothing it doesn't own. */
private static CreateTable changedDescriptionPut(Table table) {
return new CreateTable()
.withName(table.getName())
.withDatabaseSchema(table.getDatabaseSchema().getFullyQualifiedName())
.withColumns(List.of(idColumn()))
.withDescription(CHANGED_DESCRIPTION);
}

private static Column idColumn() {
return new Column().withName("id").withDataType(ColumnDataType.BIGINT);
}

private static TagLabel classificationLabel(String tagFqn) {
return new TagLabel()
.withTagFQN(tagFqn)
.withSource(TagLabel.TagSource.CLASSIFICATION)
.withLabelType(TagLabel.LabelType.MANUAL);
}

private static void assertTagsAndTier(JsonNode doc) {
Set<String> tagFqns = new HashSet<>();
doc.path("tags").forEach(tag -> tagFqns.add(tag.path("tagFQN").asText()));
assertAll(
() ->
assertTrue(
tagFqns.contains(SharedEntities.get().PERSONAL_DATA_TAG_LABEL.getTagFQN()),
"entity tags: " + tagFqns),
() ->
assertTrue(
tagFqns.contains(SharedEntities.get().PII_SENSITIVE_TAG_LABEL.getTagFQN()),
"column tags merged into the table's: " + tagFqns),
() -> assertEquals(TIER1, doc.path("tier").path("tagFQN").asText()));
}

private static void assertFollowerAndVote(JsonNode doc, UUID follower) {
assertAll(
() -> assertEquals(follower.toString(), doc.path("followers").path(0).asText()),
() -> assertEquals(1, doc.path("totalVotes").asInt()));
}

private static void assertOwner(JsonNode doc, EntityReference owner) {
assertEquals(owner.getId().toString(), doc.path("owners").path(0).path("id").asText());
}

private static void assertSharedDomain(JsonNode doc) {
assertEquals(
sharedDomainFqn(), doc.path("domains").path(0).path("fullyQualifiedName").asText());
}

private static String sharedDomainFqn() {
return SharedEntities.get().DOMAIN.getFullyQualifiedName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import org.openmetadata.it.util.TestNamespace;
import org.openmetadata.it.util.TestNamespaceExtension;
import org.openmetadata.schema.api.data.CreateGlossaryTerm;
import org.openmetadata.schema.api.data.CreateQuery;
import org.openmetadata.schema.api.data.CreateTable;
import org.openmetadata.schema.api.domains.CreateDataProduct;
import org.openmetadata.schema.api.domains.CreateDomain;
import org.openmetadata.schema.api.teams.CreateUser;
import org.openmetadata.schema.entity.data.GlossaryTerm;
import org.openmetadata.schema.entity.data.Query;
import org.openmetadata.schema.entity.data.Table;
import org.openmetadata.schema.entity.domains.DataProduct;
import org.openmetadata.schema.entity.domains.Domain;
Expand Down Expand Up @@ -55,6 +57,34 @@
private static final String DOMAIN_INDEX = "domain_search_index";
private static final String DATA_PRODUCT_INDEX = "data_product_search_index";
private static final String GLOSSARY_TERM_INDEX = "glossary_term_search_index";
private static final String QUERY_INDEX = "query_search_index";

@Test
void domainDisplayName_reachesSubdomainParent(TestNamespace ns) {
Domain parent = TeamHierarchyTestFactory.domain(ns, "parent");
Domain child =
client()
.domains()
.create(
new CreateDomain()
.withName(ns.prefix("child"))
.withDomainType(CreateDomain.DomainType.AGGREGATE)
.withDescription("Child domain")
.withParent(parent.getFullyQualifiedName()));
awaitDoc(
DOMAIN_INDEX,
child.getId(),
doc -> parent.getId().toString().equals(doc.path("parent").path("id").asText()));

Domain edited = client().domains().get(parent.getId().toString());
edited.setDisplayName("Renamed parent label");
client().domains().update(parent.getId().toString(), edited);

awaitDoc(

Check failure on line 83 in openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/ReferenceLabelSearchIT.java

View workflow job for this annotation

GitHub Actions / Integration Test Lane (parallel)

ReferenceLabelSearchIT.domainDisplayName_reachesSubdomainParent(TestNamespace)

Condition with alias 'domain_search_index doc 56e9d45a-0dab-464c-89e6-dd705e3edeec' didn't complete within 1 minutes because org.openmetadata.it.util.SearchDocs$$Lambda/0x00007f33cb0cdd80 expected the predicate to return <true> but it returned <false> for input of <{"id":"56e9d45a-0dab-464c-89e6-dd705e3edeec","domainType":"Aggregate","name":"child__969ac4a7c422429683643f3316de27cc__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","fullyQualifiedName":"parentdomain__969ac4a7c422429683643f3316de27cc__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent.child__969ac4a7c422429683643f3316de27cc__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","description":"Child domain","version":0.1,"updatedAt":1793023123934,"updatedBy":"admin","parent":{"id":"9ba974e6-f36f-4a5c-84f3-dfe9fddf50e6","type":"domain","name":"parentdomain__969ac4a7c422429683643f3316de27cc__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","fullyQualifiedName":"parentdomain__969ac4a7c422429683643f3316de27cc__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","description":"Domain inherited through the team hierarchy","displayName":"parentdomain__969ac4a7c422429683643f3316de27cc__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","deleted":false},"owners":[],"experts":[],"entityStatus":"Unprocessed","displayName":"child__969ac4a7c422429683643f3316de27cc__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","entityType":"domain","ownerDisplayName":[],"ownerName":[],"domains":[],"reviewers":[],"followers":[],"totalVotes":0,"descriptionStatus":"COMPLETE","descriptionSources":{"Ingested":1},"tagSources":{},"tierSources":{},"fqnParts":["parentdomain__969ac4a7c422429683643f3316de27cc__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","parentdomain__969ac4a7c422429683643f3316de27cc__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent.child__969ac4a7c422429683643f3316de27cc__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent"],"deleted":false,"customPropertiesTyped":[],"tags":[],"classificationTags":[],"glossaryTags":[],"upstreamLineage":[],"fqnHash":"f0d868ac6a5ef4fd70f8480b2e430746.6e38ad90e9aaa6a80b681e5f3f96ecdd"}>.

Check failure on line 83 in openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/ReferenceLabelSearchIT.java

View workflow job for this annotation

GitHub Actions / Integration Test Lane (parallel)

ReferenceLabelSearchIT.domainDisplayName_reachesSubdomainParent(TestNamespace)

Condition with alias 'domain_search_index doc c37a3565-695b-4119-bd5d-ce7e6b06dc16' didn't complete within 1 minutes because org.openmetadata.it.util.SearchDocs$$Lambda/0x00007f178f189200 expected the predicate to return <true> but it returned <false> for input of <{"id":"c37a3565-695b-4119-bd5d-ce7e6b06dc16","domainType":"Aggregate","name":"child__efabfc5a8fe64f88a879f6f2adeda03a__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","fullyQualifiedName":"parentdomain__efabfc5a8fe64f88a879f6f2adeda03a__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent.child__efabfc5a8fe64f88a879f6f2adeda03a__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","description":"Child domain","version":0.1,"updatedAt":1793023326504,"updatedBy":"admin","parent":{"id":"21d76fc8-e67f-4b59-af27-39f24c1d93fc","type":"domain","name":"parentdomain__efabfc5a8fe64f88a879f6f2adeda03a__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","fullyQualifiedName":"parentdomain__efabfc5a8fe64f88a879f6f2adeda03a__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","description":"Domain inherited through the team hierarchy","displayName":"parentdomain__efabfc5a8fe64f88a879f6f2adeda03a__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","deleted":false},"owners":[],"experts":[],"entityStatus":"Unprocessed","displayName":"child__efabfc5a8fe64f88a879f6f2adeda03a__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","entityType":"domain","ownerDisplayName":[],"ownerName":[],"domains":[],"reviewers":[],"followers":[],"totalVotes":0,"descriptionStatus":"COMPLETE","descriptionSources":{"Ingested":1},"tagSources":{},"tierSources":{},"fqnParts":["parentdomain__efabfc5a8fe64f88a879f6f2adeda03a__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent","parentdomain__efabfc5a8fe64f88a879f6f2adeda03a__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent.child__efabfc5a8fe64f88a879f6f2adeda03a__ReferenceLabelSearchIT__domainDisplayName_reachesSubdomainParent"],"deleted":false,"customPropertiesTyped":[],"tags":[],"classificationTags":[],"glossaryTags":[],"upstreamLineage":[],"fqnHash":"259520bdec482c7de7fec3b5dd161813.6f3196c074f17048bdf6d7c9b121ab86"}>.
DOMAIN_INDEX,
child.getId(),
doc -> "Renamed parent label".equals(doc.path("parent").path("displayName").asText()));
}

@Test
void userDisplayName_reachesOwnerReviewerAndExpertCopies(TestNamespace ns) {
Expand Down Expand Up @@ -96,6 +126,28 @@
() -> awaitLabel(DOMAIN_INDEX, domain.getId(), "experts", user.getId(), "Shown Owner"));
}

@Test
void userDisplayName_reachesQueryUserCopies(TestNamespace ns) {
User user = UserTestFactory.createUser(ns, "querier");
DatabaseService service = DatabaseServiceTestFactory.createPostgres(ns);
// query_entity is unique on the SQL text, so the statement carries the namespace.
Query query =
client()
.queries()
.create(
new CreateQuery()
.withQuery("SELECT 1 AS " + ns.shortPrefix("ran_by"))
.withService(service.getFullyQualifiedName())
.withUsers(List.of(user.getName())));
awaitReference(QUERY_INDEX, query.getId(), "users", user.getId());

User edited = client().users().get(user.getId().toString());
edited.setDisplayName("Shown Querier");
client().users().update(user.getId().toString(), edited);

awaitLabel(QUERY_INDEX, query.getId(), "users", user.getId(), "Shown Querier");
}

@Test
void teamDisplayName_reachesOwnerMemberAndChildTeamCopies(TestNamespace ns) {
Team department = TeamHierarchyTestFactory.departmentUnderDivision(ns, "lbl", null);
Expand Down
Loading
Loading