From 5403b5522f4449cf24a01a265ffb155b1088a06c Mon Sep 17 00:00:00 2001
From: Alberto Miorin <32617+amiorin@users.noreply.github.com>
Date: Tue, 16 Nov 2021 00:11:23 +0100
Subject: [PATCH] Bug fix for location findEntityReferenceById. getName was not
returning the FQN.
---
.../openmetadata/catalog/jdbi3/TableRepository.java | 12 +++++-------
.../org/openmetadata/catalog/util/TestUtils.java | 5 +----
2 files changed, 6 insertions(+), 11 deletions(-)
diff --git a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TableRepository.java b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TableRepository.java
index 3d399fa6303..cc6dce54633 100644
--- a/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TableRepository.java
+++ b/catalog-rest-service/src/main/java/org/openmetadata/catalog/jdbi3/TableRepository.java
@@ -102,7 +102,7 @@ public class TableRepository extends EntityRepository
{
table.setSampleData(fields.contains("sampleData") ? getSampleData(table) : null);
table.setViewDefinition(fields.contains("viewDefinition") ? table.getViewDefinition() : null);
table.setTableProfile(fields.contains("tableProfile") ? getTableProfile(table) : null);
- table.setLocation(fields.contains("location") ? getLocation(table): null);
+ table.setLocation(fields.contains("location") ? getLocation(table.getId()): null);
table.setTableQueries(fields.contains("tableQueries") ? getQueries(table): null);
return table;
}
@@ -374,13 +374,11 @@ public class TableRepository extends EntityRepository {
return dao.databaseDAO().findEntityReferenceById(UUID.fromString(result.get(0)));
}
- private EntityReference getLocation(Table table) throws IOException {
- // Find database for the table
- String id = table.getId().toString();
- List result = dao.relationshipDAO().findTo(id, Relationship.HAS.ordinal(), Entity.LOCATION);
+ private EntityReference getLocation(UUID tableId) throws IOException {
+ // Find the location of the table
+ List result = dao.relationshipDAO().findTo(tableId.toString(), Relationship.HAS.ordinal(), Entity.LOCATION);
if (result.size() == 1) {
- Location location = dao.locationDAO().findEntityById(UUID.fromString(result.get(0)));
- return new EntityReference().withName(location.getName()).withId(location.getId()).withType("location");
+ return dao.locationDAO().findEntityReferenceById(UUID.fromString(result.get(0)));
} else {
return null;
}
diff --git a/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/TestUtils.java b/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/TestUtils.java
index b59d2e4157c..0c270fc08be 100644
--- a/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/TestUtils.java
+++ b/catalog-rest-service/src/test/java/org/openmetadata/catalog/util/TestUtils.java
@@ -222,14 +222,11 @@ public final class TestUtils {
assertNotNull(ref.getName());
assertNotNull(ref.getType());
// Ensure data entities use fully qualified name
- if (List.of("table", "database", "metrics", "dashboard", "pipeline", "report", "topic", "chart")
+ if (List.of("table", "database", "metrics", "dashboard", "pipeline", "report", "topic", "chart", "location")
.contains(ref.getType())) {
// FullyQualifiedName has "." as separator
assertTrue(ref.getName().contains("."), "entity name is not fully qualified - " + ref.getName());
}
- if (List.of("location").contains(ref.getName())) {
- ref.getName().contains(":/"); // FullyQualifiedName has ":/" as separator
- }
}
public static void validateEntityReference(List list) {