Skip to content

Commit da651e6

Browse files
committed
kafka 改造优化
1 parent 41f7201 commit da651e6

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
119
package com.dtstack.flink.sql.format;
220

321
/**
22+
* indicate source table input data format type
423
* company: www.dtstack.com
524
* author: toutian
625
* create: 2019/12/24
726
*/
827
public enum FormatType {
9-
DT_NEST, JSON, AVRO, CSV
28+
//Indicates that the data is in nest json format(default)
29+
DT_NEST,
30+
//Indicates that the data is in json format
31+
JSON,
32+
//Indicates that the data is in avro format
33+
AVRO,
34+
//Indicates that the data is in csv format
35+
CSV
1036
}

core/src/main/java/com/dtstack/flink/sql/outputformat/DtRichOutputFormat.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.flink.metrics.MeterView;
2727

2828
/**
29+
* extend RichOutputFormat with metric 'dtNumRecordsOut', 'dtNumDirtyRecordsOut', 'dtNumRecordsOutRate'
2930
* Created by sishu.yss on 2018/11/28.
3031
*/
3132
public abstract class DtRichOutputFormat extends RichOutputFormat<Tuple2>{

kafka-base/kafka-base-sink/src/main/java/com/dtstack/flink/sql/sink/kafka/AbstractKafkaProducerFactory.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,23 @@
3434
import java.util.Properties;
3535

3636
/**
37+
* 抽象的kafka producer 的工厂类
38+
* 包括序统一的序列化工具的构造
3739
* company: www.dtstack.com
38-
*
3940
* @author: toutian
4041
* create: 2019/12/26
4142
*/
4243
public abstract class AbstractKafkaProducerFactory {
4344

45+
/**
46+
* 获取具体的KafkaProducer
47+
* eg create KafkaProducer010
48+
* @param kafkaSinkTableInfo
49+
* @param typeInformation
50+
* @param properties
51+
* @param partitioner
52+
* @return
53+
*/
4454
public abstract RichSinkFunction<Row> createKafkaProducer(KafkaSinkTableInfo kafkaSinkTableInfo, TypeInformation<Row> typeInformation, Properties properties, Optional<FlinkKafkaPartitioner<Row>> partitioner);
4555

4656
protected SerializationMetricWrapper createSerializationMetricWrapper(KafkaSinkTableInfo kafkaSinkTableInfo, TypeInformation<Row> typeInformation) {
@@ -50,30 +60,39 @@ protected SerializationMetricWrapper createSerializationMetricWrapper(KafkaSinkT
5060
private SerializationSchema<Row> createSerializationSchema(KafkaSinkTableInfo kafkaSinkTableInfo, TypeInformation<Row> typeInformation) {
5161
SerializationSchema<Row> serializationSchema = null;
5262
if (FormatType.JSON.name().equalsIgnoreCase(kafkaSinkTableInfo.getSinkDataType())) {
63+
5364
if (StringUtils.isNotBlank(kafkaSinkTableInfo.getSchemaString())) {
5465
serializationSchema = new JsonRowSerializationSchema(kafkaSinkTableInfo.getSchemaString());
5566
} else if (typeInformation != null && typeInformation.getArity() != 0) {
5667
serializationSchema = new JsonRowSerializationSchema(typeInformation);
5768
} else {
5869
throw new IllegalArgumentException("sinkDataType:" + FormatType.JSON.name() + " must set schemaString(JSON Schema)or TypeInformation<Row>");
5970
}
71+
6072
} else if (FormatType.CSV.name().equalsIgnoreCase(kafkaSinkTableInfo.getSinkDataType())) {
73+
6174
if (StringUtils.isBlank(kafkaSinkTableInfo.getFieldDelimiter())) {
6275
throw new IllegalArgumentException("sinkDataType:" + FormatType.CSV.name() + " must set fieldDelimiter");
6376
}
77+
6478
final CsvRowSerializationSchema.Builder serSchemaBuilder = new CsvRowSerializationSchema.Builder(typeInformation);
6579
serSchemaBuilder.setFieldDelimiter(kafkaSinkTableInfo.getFieldDelimiter().toCharArray()[0]);
6680
serializationSchema = serSchemaBuilder.build();
81+
6782
} else if (FormatType.AVRO.name().equalsIgnoreCase(kafkaSinkTableInfo.getSinkDataType())) {
83+
6884
if (StringUtils.isBlank(kafkaSinkTableInfo.getSchemaString())) {
6985
throw new IllegalArgumentException("sinkDataType:" + FormatType.AVRO.name() + " must set schemaString");
7086
}
87+
7188
serializationSchema = new AvroRowSerializationSchema(kafkaSinkTableInfo.getSchemaString());
89+
7290
}
7391

7492
if (null == serializationSchema) {
7593
throw new UnsupportedOperationException("FormatType:" + kafkaSinkTableInfo.getSinkDataType());
7694
}
95+
7796
return serializationSchema;
7897
}
7998

0 commit comments

Comments
 (0)