datahub.protobuf.visitors.dataset.KafkaTopicPropertyVisitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of datahub-protobuf Show documentation
Show all versions of datahub-protobuf Show documentation
DataHub integration with Protobuf schemas for metadata
package datahub.protobuf.visitors.dataset;
import com.linkedin.data.template.StringMap;
import com.linkedin.dataset.DatasetProperties;
import datahub.protobuf.visitors.ProtobufModelVisitor;
import datahub.protobuf.visitors.VisitContext;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;
public class KafkaTopicPropertyVisitor implements ProtobufModelVisitor {
@Override
public Stream visitGraph(VisitContext context) {
return getKafkaTopic(context.root().comment()).stream().map(kafkaTopic ->
new DatasetProperties()
.setCustomProperties(new StringMap(Map.of("kafka_topic", kafkaTopic)))
);
}
private static final Pattern TOPIC_NAME_REGEX = Pattern.compile("(?si).*kafka.+topic.+[`]([a-z._-]+)[`].*");
private static Optional getKafkaTopic(String text) {
Matcher m = TOPIC_NAME_REGEX.matcher(text);
return m.matches() ? Optional.of(m.group(1)) : Optional.empty();
}
}