-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4475c9
commit 6157773
Showing
21 changed files
with
529 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
.../src/main/java/io/aiven/kafka/connect/common/config/enums/ObjectDistributionStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2025 Aiven Oy | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.aiven.kafka.connect.common.config.enums; | ||
|
||
import java.util.Arrays; | ||
import java.util.Objects; | ||
|
||
import org.apache.kafka.common.config.ConfigException; | ||
|
||
public enum ObjectDistributionStrategy { | ||
|
||
OBJECT_HASH("object_hash"), PARTITION_IN_FILENAME("partition_in_filename"), PARTITION_IN_FILEPATH( | ||
"partition_in_filepath"); | ||
|
||
private final String name; | ||
|
||
public String value() { | ||
return name; | ||
} | ||
|
||
ObjectDistributionStrategy(final String name) { | ||
this.name = name; | ||
} | ||
|
||
public static ObjectDistributionStrategy forName(final String name) { | ||
Objects.requireNonNull(name, "name cannot be null"); | ||
for (final ObjectDistributionStrategy objectDistributionStrategy : ObjectDistributionStrategy.values()) { | ||
if (objectDistributionStrategy.name.equalsIgnoreCase(name)) { | ||
return objectDistributionStrategy; | ||
} | ||
} | ||
throw new ConfigException(String.format("Unknown object.distribution.strategy type: %s, allowed values %s ", | ||
name, Arrays.toString(ObjectDistributionStrategy.values()))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...rc/main/java/io/aiven/kafka/connect/common/source/input/utils/FileExtractionPatterns.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2025 Aiven Oy | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.aiven.kafka.connect.common.source.input.utils; | ||
public class FileExtractionPatterns { | ||
public static final String PATTERN_PARTITION_KEY = "partition"; | ||
public static final String PATTERN_TOPIC_KEY = "topic"; | ||
public static final String START_OFFSET_PATTERN = "{{start_offset}}"; | ||
public static final String TIMESTAMP_PATTERN = "{{timestamp}}"; | ||
public static final String PARTITION_PATTERN = "{{" + PATTERN_PARTITION_KEY + "}}"; | ||
public static final String TOPIC_PATTERN = "{{" + PATTERN_TOPIC_KEY + "}}"; | ||
|
||
// Use a named group to return the partition in a complex string to always get the correct information for the | ||
// partition number. | ||
public static final String PARTITION_NAMED_GROUP_REGEX_PATTERN = "(?<" + PATTERN_PARTITION_KEY + ">\\d+)"; | ||
public static final String NUMBER_REGEX_PATTERN = "(?:\\d+)"; | ||
public static final String TOPIC_NAMED_GROUP_REGEX_PATTERN = "(?<" + PATTERN_TOPIC_KEY + ">[a-zA-Z0-9\\-_.]+)"; | ||
public static final String DEFAULT_PREFIX_FILE_PATH_PATTERN = "topics/{{" + PATTERN_TOPIC_KEY + "}}/partition={{" | ||
+ PATTERN_PARTITION_KEY + "}}/"; | ||
public static final String ANY_FILENAME_PATTERN = ".*$"; | ||
} |
57 changes: 57 additions & 0 deletions
57
commons/src/main/java/io/aiven/kafka/connect/common/source/input/utils/FilePatternUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2025 Aiven Oy | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.aiven.kafka.connect.common.source.input.utils; | ||
|
||
import static io.aiven.kafka.connect.common.source.input.utils.FileExtractionPatterns.NUMBER_REGEX_PATTERN; | ||
import static io.aiven.kafka.connect.common.source.input.utils.FileExtractionPatterns.PARTITION_NAMED_GROUP_REGEX_PATTERN; | ||
import static io.aiven.kafka.connect.common.source.input.utils.FileExtractionPatterns.PARTITION_PATTERN; | ||
import static io.aiven.kafka.connect.common.source.input.utils.FileExtractionPatterns.START_OFFSET_PATTERN; | ||
import static io.aiven.kafka.connect.common.source.input.utils.FileExtractionPatterns.TIMESTAMP_PATTERN; | ||
import static io.aiven.kafka.connect.common.source.input.utils.FileExtractionPatterns.TOPIC_NAMED_GROUP_REGEX_PATTERN; | ||
import static io.aiven.kafka.connect.common.source.input.utils.FileExtractionPatterns.TOPIC_PATTERN; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
import org.apache.kafka.common.config.ConfigException; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public final class FilePatternUtils { | ||
|
||
private FilePatternUtils() { | ||
// hidden | ||
} | ||
public static Pattern configurePattern(final String expectedSourceNameFormat) { | ||
if (expectedSourceNameFormat == null || !expectedSourceNameFormat.contains(PARTITION_PATTERN)) { | ||
throw new ConfigException(String.format( | ||
"Source name format %s missing partition pattern {{partition}} please configure the expected source to include the partition pattern.", | ||
expectedSourceNameFormat)); | ||
} | ||
// Build REGEX Matcher | ||
String regexString = StringUtils.replace(expectedSourceNameFormat, START_OFFSET_PATTERN, NUMBER_REGEX_PATTERN); | ||
regexString = StringUtils.replace(regexString, TIMESTAMP_PATTERN, NUMBER_REGEX_PATTERN); | ||
regexString = StringUtils.replace(regexString, TOPIC_PATTERN, TOPIC_NAMED_GROUP_REGEX_PATTERN); | ||
regexString = StringUtils.replace(regexString, PARTITION_PATTERN, PARTITION_NAMED_GROUP_REGEX_PATTERN); | ||
try { | ||
return Pattern.compile(regexString); | ||
} catch (IllegalArgumentException iae) { | ||
throw new ConfigException( | ||
String.format("Unable to compile the regex pattern %s to retrieve the partition id.", regexString), | ||
iae); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.