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
18 changes: 9 additions & 9 deletions src/main/java/com/snowflake/kafka/connector/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ private static GeneratedName generateValidNameFromMap(
public static Map<String, String> parseTopicToTableMap(String input) {
Map<String, String> topic2Table = new HashMap<>();
boolean isInvalid = false;
String errorMessage = "";
for (String str : input.split(",")) {
String[] tt = str.split(":");

Expand All @@ -589,32 +590,31 @@ public static Map<String, String> parseTopicToTableMap(String input) {
String table = tt[1].trim();

if (!isValidSnowflakeTableName(table)) {
LOGGER.error(
"table name {} should have at least 2 "
+ "characters, start with _a-zA-Z, and only contains "
+ "_$a-zA-z0-9",
table);
errorMessage = "Table name " + table + " should have at least 2 characters, " +
"start with _a-zA-Z, and only contains _$a-zA-z0-9";
LOGGER.error(errorMessage);
isInvalid = true;
}

if (topic2Table.containsKey(topic)) {
LOGGER.error("topic name {} is duplicated", topic);
errorMessage = "Topic name " + topic + " is duplicated";
LOGGER.error(errorMessage);
isInvalid = true;
}

// check that regexes don't overlap
for (String parsedTopic : topic2Table.keySet()) {
if (parsedTopic.matches(topic) || topic.matches(parsedTopic)) {
LOGGER.error(
"topic regexes cannot overlap. overlapping regexes: {}, {}", parsedTopic, topic);
errorMessage = "Topic regexes cannot overlap. overlapping regexes: " + parsedTopic + ", " + topic;
LOGGER.error(errorMessage);
isInvalid = true;
}
}

topic2Table.put(tt[0].trim(), tt[1].trim());
}
if (isInvalid) {
throw SnowflakeErrors.ERROR_0021.getException();
throw SnowflakeErrors.ERROR_0021.getException(errorMessage, null, errorMessage);
}
return topic2Table;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void ensureValid(String name, Object value) {
}
} catch (SnowflakeKafkaConnectorException e) {
throw new ConfigException(
name, value, "Format: <topic-1>:<table-1>,<topic-2>:<table-2>,...");
name, value, e.getExceptionUserMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ public void testInvalidTopicToTableConfigValues() {
Map<String, String> config = getCorrectConfig();

String[] invalidValues = {
"topic1:t1;topic2:t2", // invalid separator
"topic1:table1,topic1:table2", // duplicate topic
"topic1:!@#@!#!@", // invalid table name
"topic1:a", // too short table name
Expand Down