From 74f18fbbf5e6d218efb78cb7c7c222ec043f6217 Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 10 Sep 2024 08:48:08 +0100 Subject: [PATCH] DBZ-8224 allow field name without topic qualifier --- .../jdbc/filter/FieldFilterFactory.java | 3 ++ .../jdbc/filter/FieldFilterFactoryTest.java | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/test/java/io/debezium/connector/jdbc/filter/FieldFilterFactoryTest.java diff --git a/src/main/java/io/debezium/connector/jdbc/filter/FieldFilterFactory.java b/src/main/java/io/debezium/connector/jdbc/filter/FieldFilterFactory.java index f53a5f38..687a527b 100644 --- a/src/main/java/io/debezium/connector/jdbc/filter/FieldFilterFactory.java +++ b/src/main/java/io/debezium/connector/jdbc/filter/FieldFilterFactory.java @@ -32,6 +32,9 @@ private static FieldNameFilter createFilter(String fieldList, boolean include) { if (parts.length == 2 && parts[0].equals(topicName) && parts[1].equals(fieldName)) { return include; } + if (parts.length == 1 && parts[0].equals(fieldName)) { + return include; + } } return !include; }; diff --git a/src/test/java/io/debezium/connector/jdbc/filter/FieldFilterFactoryTest.java b/src/test/java/io/debezium/connector/jdbc/filter/FieldFilterFactoryTest.java new file mode 100644 index 00000000..cb259de9 --- /dev/null +++ b/src/test/java/io/debezium/connector/jdbc/filter/FieldFilterFactoryTest.java @@ -0,0 +1,30 @@ +package io.debezium.connector.jdbc.filter; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +import io.debezium.connector.jdbc.filter.FieldFilterFactory.FieldNameFilter; +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class FieldFilterFactoryTest { + + @Test + public void testFullyQualifiedFilter() { + FieldNameFilter filter = FieldFilterFactory.createFieldFilter("mytopic:myfield,mytopic2:myfield2", null); + assertTrue(filter.matches("mytopic", "myfield"), "matchees first item"); + assertTrue(filter.matches("mytopic2", "myfield2"), "matchees second item"); + assertFalse(filter.matches("mytopic3", "myfield"), "doesnt match when topic is different"); + assertFalse(filter.matches("mytopic", "myfield3"), "doesnt match when field is different"); + } + + @Test + public void testUnqualifiedFilter() { + FieldNameFilter filter = FieldFilterFactory.createFieldFilter("myfield,myfield2", null); + assertTrue(filter.matches("mytopic", "myfield"), "matchees first item"); + assertTrue(filter.matches("mytopic3", "myfield"), "matches first field in another topic"); + assertTrue(filter.matches("mytopic2", "myfield2"), "matchees second item"); + assertFalse(filter.matches("mytopic", "myfield3"), "doesnt match when field is different"); + } + +}