Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add kafka_default_offsets when no partiotion specify .support read kafka partition from start #1642

Merged
merged 5 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@
示例:

"kafka_partitions" = "0,1,2,3",
"kafka_offsets" = "101,0,OFFSET_BEGINNING,OFFSET_END"

"kafka_offsets" = "101,0,OFFSET_BEGINNING,OFFSET_END"
4. property

指定自定义kafka参数。
Expand All @@ -170,7 +169,7 @@
"property.client.id" = "12345",
"property.ssl.ca.location" = "FILE:ca.pem"

使用 SSL 连接 Kafka 时,需要指定以下参数:
1.使用 SSL 连接 Kafka 时,需要指定以下参数:

"property.security.protocol" = "ssl",
"property.ssl.ca.location" = "FILE:ca.pem",
Expand All @@ -189,6 +188,14 @@

分别用于指定 client 的 public key,private key 以及 private key 的密码。


2.指定kafka partition的默认起始offset
如果没有指定kafka_partitions/kafka_offsets,默认消费所有分区,此时可以指定kafka_default_offsets指定起始 offset。默认为 OFFSET_END,即从末尾开始订阅。
值为
1) OFFSET_BEGINNING: 从有数据的位置开始订阅。
2) OFFSET_END: 从末尾开始订阅。
示例:
"property.kafka_default_offsets" = "OFFSET_BEGINNING"

7. 导入数据格式样例

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public class CreateRoutineLoadStmt extends DdlStmt {
// optional
public static final String KAFKA_PARTITIONS_PROPERTY = "kafka_partitions";
public static final String KAFKA_OFFSETS_PROPERTY = "kafka_offsets";
public static final String KAFKA_DEFAULT_OFFSETS = "kafka_default_offsets";

private static final String NAME_TYPE = "ROUTINE LOAD NAME";
private static final String ENDPOINT_REGEX = "[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]";
Expand Down Expand Up @@ -136,6 +137,8 @@ public class CreateRoutineLoadStmt extends DdlStmt {
private String kafkaTopic;
// pair<partition id, offset>
private List<Pair<Integer, Long>> kafkaPartitionOffsets = Lists.newArrayList();


//custom kafka property map<key, value>
private Map<String, String> customKafkaProperties = Maps.newHashMap();

Expand Down Expand Up @@ -212,6 +215,7 @@ public Map<String, String> getCustomKafkaProperties() {
return customKafkaProperties;
}


@Override
public void analyze(Analyzer analyzer) throws UserException {
super.analyze(analyzer);
Expand Down Expand Up @@ -401,7 +405,6 @@ private void checkKafkaProperties() throws AnalysisException {
}
}
}

// check custom kafka property
for (Map.Entry<String, String> dataSourceProperty : dataSourceProperties.entrySet()) {
if (dataSourceProperty.getKey().startsWith("property.")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import java.util.Map;
import java.util.UUID;

import static org.apache.doris.analysis.CreateRoutineLoadStmt.KAFKA_DEFAULT_OFFSETS;

/**
* KafkaRoutineLoadJob is a kind of RoutineLoadJob which fetch data from kafka.
* The progress which is super class property is seems like "{"partition1": offset1, "partition2": offset2}"
Expand All @@ -71,6 +73,8 @@ public class KafkaRoutineLoadJob extends RoutineLoadJob {
private List<Integer> customKafkaPartitions = Lists.newArrayList();
// current kafka partitions is the actually partition which will be fetched
private List<Integer> currentKafkaPartitions = Lists.newArrayList();
// optional, user want to set default offset when new partiton add or offset not set.
private String kafkaDefaultOffSet = "";
// kafka properties ,property prefix will be mapped to kafka custom parameters, which can be extended in the future
private Map<String, String> customProperties = Maps.newHashMap();
private Map<String, String> convertedCustomProperties = Maps.newHashMap();
Expand Down Expand Up @@ -128,6 +132,9 @@ private void convertCustomProperties() throws DdlException {
convertedCustomProperties.put(entry.getKey(), entry.getValue());
}
}
if (convertedCustomProperties.containsKey(KAFKA_DEFAULT_OFFSETS)) {
kafkaDefaultOffSet = convertedCustomProperties.get(KAFKA_DEFAULT_OFFSETS);
wkhappy1 marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Override
Expand Down Expand Up @@ -368,11 +375,21 @@ private void updateNewPartitionProgress() {
for (Integer kafkaPartition : currentKafkaPartitions) {
if (!((KafkaProgress) progress).containsPartition(kafkaPartition)) {
// if offset is not assigned, start from OFFSET_END
((KafkaProgress) progress).addPartitionOffset(Pair.create(kafkaPartition, KafkaProgress.OFFSET_END_VAL));
long beginOffSet = KafkaProgress.OFFSET_END_VAL;
if (!kafkaDefaultOffSet.isEmpty()) {
if (kafkaDefaultOffSet.equalsIgnoreCase(KafkaProgress.OFFSET_BEGINNING)) {
beginOffSet = KafkaProgress.OFFSET_BEGINNING_VAL;
} else if (kafkaDefaultOffSet.equalsIgnoreCase(KafkaProgress.OFFSET_END)) {
beginOffSet = KafkaProgress.OFFSET_END_VAL;
} else {
beginOffSet = KafkaProgress.OFFSET_END_VAL;
}
}
((KafkaProgress) progress).addPartitionOffset(Pair.create(kafkaPartition, beginOffSet));
if (LOG.isDebugEnabled()) {
LOG.debug(new LogBuilder(LogKey.ROUTINE_LOAD_JOB, id)
.add("kafka_partition_id", kafkaPartition)
.add("begin_offset", KafkaProgress.OFFSET_END)
.add("begin_offset", beginOffSet)
.add("msg", "The new partition has been added in job"));
}
}
Expand Down Expand Up @@ -402,7 +419,6 @@ private void setCustomKafkaPartitions(List<Pair<Integer, Long>> kafkaPartitionOf
private void setCustomKafkaProperties(Map<String, String> kafkaProperties) {
this.customProperties = kafkaProperties;
}

@Override
protected String dataSourcePropertiesJsonToString() {
Map<String, String> dataSourceProperties = Maps.newHashMap();
Expand Down