From e93bf7024f3763a7b447484abf490cae5bca90ea Mon Sep 17 00:00:00 2001 From: sonika-shah <58761340+sonika-shah@users.noreply.github.com> Date: Sat, 27 Jul 2024 20:52:06 +0530 Subject: [PATCH] Fix isParent method to correctly identify FQN parent-child relationships (#17208) --- .../org/openmetadata/service/util/FullyQualifiedName.java | 4 +++- .../org/openmetadata/service/util/FullyQualifiedNameTest.java | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/FullyQualifiedName.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/FullyQualifiedName.java index 630054a1177..448bf828357 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/FullyQualifiedName.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/FullyQualifiedName.java @@ -117,7 +117,9 @@ public class FullyQualifiedName { public static boolean isParent(String childFqn, String parentFqn) { // Returns true if the childFqn is indeed the child of parentFqn - return childFqn.startsWith(parentFqn) && childFqn.length() > parentFqn.length(); + // Adding "." ensures that we are checking for a true parent-child relationship + // For example, "a.b.c" should be a child of "a.b" but "a.b c" should not be a child of "a.b" + return childFqn.startsWith(parentFqn + ".") && childFqn.length() > parentFqn.length(); } private static class SplitListener extends FqnBaseListener { diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/util/FullyQualifiedNameTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/util/FullyQualifiedNameTest.java index b7066159f02..ff9b035692d 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/util/FullyQualifiedNameTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/util/FullyQualifiedNameTest.java @@ -103,5 +103,6 @@ class FullyQualifiedNameTest { assertFalse(FullyQualifiedName.isParent("a", "a.b.c")); assertFalse(FullyQualifiedName.isParent("a.b", "a.b.c")); assertFalse(FullyQualifiedName.isParent("a.b.c", "a.b.c")); + assertFalse(FullyQualifiedName.isParent("a.b c", "a.b")); } }