|
23 | 23 | import com.dtstack.flink.sql.source.IStreamSourceGener; |
24 | 24 | import com.dtstack.flink.sql.source.kafka.table.KafkaSourceTableInfo; |
25 | 25 | import com.dtstack.flink.sql.table.SourceTableInfo; |
| 26 | +import com.dtstack.flink.sql.util.PluginUtil; |
26 | 27 | import org.apache.commons.lang3.StringUtils; |
27 | 28 | import org.apache.flink.api.common.functions.RuntimeContext; |
28 | 29 | import org.apache.flink.api.common.typeinfo.TypeInformation; |
29 | 30 | import org.apache.flink.api.java.typeutils.RowTypeInfo; |
30 | 31 | import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; |
31 | 32 | import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer09; |
| 33 | +import org.apache.flink.streaming.connectors.kafka.internals.KafkaTopicPartition; |
32 | 34 | import org.apache.flink.table.api.Table; |
33 | 35 | import org.apache.flink.table.api.java.StreamTableEnvironment; |
34 | 36 | import org.apache.flink.types.Row; |
35 | 37 |
|
| 38 | +import java.util.HashMap; |
| 39 | +import java.util.Map; |
36 | 40 | import java.util.Properties; |
37 | 41 |
|
38 | 42 | /** |
@@ -76,7 +80,20 @@ public Table genStreamSource(SourceTableInfo sourceTableInfo, StreamExecutionEnv |
76 | 80 | //earliest,latest |
77 | 81 | if("earliest".equalsIgnoreCase(kafka09SourceTableInfo.getOffsetReset())){ |
78 | 82 | kafkaSrc.setStartFromEarliest(); |
79 | | - }else{ |
| 83 | + }else if(kafka09SourceTableInfo.getOffsetReset().startsWith("{")){ |
| 84 | + try { |
| 85 | + // {"0":12312,"1":12321,"2":12312} |
| 86 | + Properties properties = PluginUtil.jsonStrToObject(kafka09SourceTableInfo.getOffsetReset(), Properties.class); |
| 87 | + Map<String, Object> offsetMap = PluginUtil.ObjectToMap(properties); |
| 88 | + Map<KafkaTopicPartition, Long> specificStartupOffsets = new HashMap<>(); |
| 89 | + for(Map.Entry<String,Object> entry:offsetMap.entrySet()){ |
| 90 | + specificStartupOffsets.put(new KafkaTopicPartition(topicName,Integer.valueOf(entry.getKey())),Long.valueOf(entry.getValue().toString())); |
| 91 | + } |
| 92 | + kafkaSrc.setStartFromSpecificOffsets(specificStartupOffsets); |
| 93 | + } catch (Exception e) { |
| 94 | + throw new RuntimeException("not support offsetReset type:" + kafka09SourceTableInfo.getOffsetReset()); |
| 95 | + } |
| 96 | + }else { |
80 | 97 | kafkaSrc.setStartFromLatest(); |
81 | 98 | } |
82 | 99 |
|
|
0 commit comments