本文为您介绍使用数据摄入CDC YAML作业将日志数据写入阿里云数据湖构建的最佳实践。
Kafka日志数据入湖
Apache Kafka是一款开源的分布式消息队列系统,广泛用于高性能数据处理、流式分析、数据集成等大数据领域。通过简单的YAML作业的编写,用户可以使用Flink CDC数据摄入快速完成日志数据的实时入湖,自动帮助用户完成Schema推导,提供Schema Evolution能力。
假设Kafka的inventory Topic中存储了一张日志表的数据,且数据格式为JSON。以下示例作业可将这张表的数据同步到DLF对应的目标表:
source:
type: kafka
name: Kafka Source
# Kafka broker地址
properties.bootstrap.servers: ${kafka.bootstrap.servers}
# 设置消费的Topic
topic: inventory
# 指定从最早的位点开始消费
scan.startup.mode: earliest-offset
# 设置Kafka消息Value部分格式
value.format: json
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# (可选)递归式地展开JSON中的嵌套列
json.infer-schema.flatten-nested-columns.enable: true
# (可选)跳过前 100 次出现的解析异常;若超过 100 次则作业失败。
ingestion.ignore-errors: true
ingestion.error-tolerance.max-count: 100
sink:
type: paimon
# Metastore类型,固定为rest
catalog.properties.metastore: rest
# Token提供方,固定为dlf
catalog.properties.token.provider: dlf
# 访问DLF Rest Catalog Server的URI,格式为http://[region-id]-vpc.dlf.aliyuncs.com,如http://cn-hangzhou-vpc.dlf.aliyuncs.com
catalog.properties.uri: dlf_uri
# DLF Catalog名称。
catalog.properties.warehouse: your_warehouse
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
# 为表添加主键信息
transform:
- source-table: \.*.\.*
projection: \*
primary-keys: id
# 将 inventory topic 中所有的数据都写入到 test_database.inventory 表中
route:
- source-table: inventory
sink-table: test_database.inventory
pipeline:
# (可选)将会导致处理异常的脏数据记录到日志中
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger假设Kafka的inventory Topic中存储了多张日志表的数据,数据格式为JSON,且在JSON内容中的databaseName、tableName字段中提供了库名、表名信息。以下示例作业可将这个Topic中的多张表的数据同步到DLF对应的目标表:
source:
type: kafka
name: Kafka Source
properties.bootstrap.servers: ${kafka.bootstrap.servers}
topic: inventory
scan.startup.mode: earliest-offset
value.format: json
# (可选)递归式地展开JSON中的嵌套列
json.infer-schema.flatten-nested-columns.enable: true
# 使用 databaseName 字段中的值作为库名,使用 tableName 字段中的值作为表名
json.decode.parser-table-id.fields: databaseName,tableName
# (可选)跳过前 100 次出现的解析异常;若超过 100 次则作业失败。
ingestion.ignore-errors: true
ingestion.error-tolerance.max-count: 100
sink:
type: paimon
# Metastore类型,固定为rest
catalog.properties.metastore: rest
# Token提供方,固定为dlf
catalog.properties.token.provider: dlf
# 访问DLF Rest Catalog Server的URI,格式为http://[region-id]-vpc.dlf.aliyuncs.com,如http://cn-hangzhou-vpc.dlf.aliyuncs.com
catalog.properties.uri: dlf_uri
# DLF Catalog名称。
catalog.properties.warehouse: your_warehouse
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
# 为表添加主键信息
transform:
- source-table: \.*.\.*
projection: \*
primary-keys: id
# 将 ods.inventory、ods.customer,ods.user 中的数据分别写入到 test_database.inventory,test_database.customer,test_database.user 表中
route:
- source-table: ods.inventory
sink-table: test_database.inventory
- source-table: ods.customer
sink-table: test_database.customer
- source-table: ods.user
sink-table: test_database.user
pipeline:
# (可选)将会导致处理异常的脏数据记录到日志中
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger如果您希望了解更多JSON格式的Kafka源表的表结构推导与演进策略,可以参考Kafka SQL连接器说明。
典型使用场景
数据摄入Kafka连接器有较多可选择的配置项,下面将介绍一些典型场景下该如何配置作业,更详细的配置请参见数据摄入Kafka连接器。
解决字段名称冲突
Kafka消息包含Key和Value两个部分,用户可以分别设置key.format和value.format定义两者的格式,最终Schema由这两个部分的全部字段合并组成。
如果Key和Value两个部分存在字段名称冲突,可以通过key.fields-prefix和value.fields-prefix为字段名称添加对应前缀解决。
例如Kafka消息中Key部分包含id和name两个字段,Value部分包含id和price两个字段,如下作业得到的Schema包含的字段为key_id,key_name,val_id和val_price。
source:
type: kafka
properties.bootstrap.servers: localhost:9092
topic: test_topic
properties.group.id: test_group
scan.startup.mode: earliest-offset
value.format: json
key.format: json
# 为Key中字段名称添加前缀
key.fields-prefix: key_
# 为Value中字段名称添加前缀
value.fields-prefix: val_
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
# 将 test_topic topic 中所有的数据都写入到 test_database.test_topic 表中
route:
- source-table: test_topic
sink-table: test_database.test_topic
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger读取元数据
使用metadata.list配置可以读取额外添加的Kafka消息元数据并传递,metadata.list中新增的元数据列可以在transform模块中直接使用,更多支持的元数据请见可用的元数据列。
如下配置会把partition和offset元数据添加到数据中,并在transform模块直接使用这两个元数据,过滤出分区大于1且offset大于100的数据。
source:
type: kafka
name: Kafka source
properties.bootstrap.servers: localhost:9092
topic: test_topic
properties.group.id: test_group
scan.startup.mode: earliest-offset
value.format: json
# 添加元数据列
metadata.list: partition,offset
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
transform:
- source-table: \.*.\.*
filter: '`partition` > 1 and `offset` > 100'
# 将 test_topic topic 中所有的数据都写入到 test_database.test_topic 表中
route:
- source-table: test_topic
sink-table: test_database.test_topic
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger脏数据处理
日志数据可能包含格式不正确的脏数据,这些脏数据会导致作业报错不断重启。Flink CDC数据摄入支持忽略解析报错并将错误数据进行收集,详情请参见脏数据收集。
如下所示的作业,会将解析错误的脏数据统一写入日志文件,并在超过100次解析报错后触发作业失败。
source:
type: kafka
name: Kafka source
properties.bootstrap.servers: localhost:9092
topic: test_topic
properties.group.id: test_group
scan.startup.mode: earliest-offset
value.format: json
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
# 将 test_topic topic 中所有的数据都写入到 test_database.test_topic 表中
route:
- source-table: test_topic
sink-table: test_database.test_topic
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger如果完全不需要收集脏数据信息,并且不希望作业因脏数据而发生失败,可以使用json.ignore-parse-errors,debezium-json.ignore-parse-errors或canal-json.ignore-parse-errors直接忽略解析报错。
指定TableID
Debezium JSON和Canal JSON格式是固定的,格式中有固定的字段存储TableID内容。JSON数据字段无固定格式,默认使用topic名称作为TableID,如果需要指定字段中的数据作为TableID,JSON格式需要配置json.decode.parser-table-id.fields,例如:JSON数据为{"col0":"a", "col1":"b", "col2":"c"},不同配置生成TableID如下:
配置 | tableId |
col0 | a |
col0,col1 | a.b |
col0,col1,col2 | a.b.c |
如下作业配置会将数据中的db和table列拼接作为最终的TableID。
source:
type: kafka
name: Kafka source
properties.bootstrap.servers: localhost:9092
topic: test_topic
properties.group.id: test_group
scan.startup.mode: earliest-offset
value.format: json
# 使用数据中的db和table字段作为table id
json.decode.parser-table-id.fields: db,table
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger数据类型推导
日志数据的类型需要通过解析数据来进行推断,详细的类型推导请参见表结构解析和变更同步策略。下面介绍一些常见场景下,如何调整配置控制类型解析。
(通用)字段类型统一设置成String
如果下游处理和存储不需要关心字段类型,可以开启json.infer-schema.primitive-as-string,debezium-json.infer-schema.primitive-as-string或canal-json.infer-schema.primitive-as-string将字段类型推导跳过并统一设置为String类型。
source:
type: kafka
name: Kafka source
properties.bootstrap.servers: localhost:9092
topic: test_topic
properties.group.id: test_group
scan.startup.mode: earliest-offset
value.format: json
# JSON数据中所有字段类型使用String
json.infer-schema.primitive-as-string: true
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
# 将 test_topic topic 中所有的数据都写入到 test_database.test_topic 表中
route:
- source-table: test_topic
sink-table: test_database.test_topic
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger(通用)指定初始Schema
在某些场景下需要自行指定初始的表结构,例如将 Kafka 的数据写入到一张预先创建的下游表中。这时您可以通过添加scan.value.initial-schemas.ddls参数指定初始的表结构。
source:
type: kafka
name: Kafka source
properties.bootstrap.servers: localhost:9092
topic: test_topic
properties.group.id: test_group
scan.startup.mode: earliest-offset
value.format: json
# 使用数据中的db和table字段作为table id
json.decode.parser-table-id.fields: db,table
# 设置初始表结构
scan.value.initial-schemas.ddls: |
CREATE TABLE db1.t1 (id BIGINT, name VARCHAR(10));
CREATE TABLE db1.t2 (id BIGINT);
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger如上配置为 db1.t1 表指定 id 字段的初始类型为 BIGINT,name 字段的初始类型为 VARCHAR(10) ,为 db1.t2 表指定 id 字段的初始类型为 BIGINT。
(JSON)固定字段类型
JSON数据的字段类型需要通过解析JSON数据节点类型进行推断,有时推断出的类型并不符合用户期望,此时可以通过配置json.infer-schema.fixed-types为某些字段指定类型。
如下的作业配置指定id字段类型为BIGINT,name字段类型为VARCHAR(10)。
source:
type: kafka
name: Kafka source
properties.bootstrap.servers: localhost:9092
topic: test_topic
properties.group.id: test_group
scan.startup.mode: earliest-offset
value.format: json
# 设置特定字段始终为固定类型
json.infer-schema.fixed-types: id BIGINT, name VARCHAR(10)
# 11.5版本及以前版本需要搭配此配置使用
scan.max.pre.fetch.records: 0
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
# 将 test_topic topic 中所有的数据都写入到 test_database.test_topic 表中
route:
- source-table: test_topic
sink-table: test_database.test_topic
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger(Canal JSON)指定推断来源
Canal JSON数据相比JSON数据记录了更多的信息,如果Canal JSON数据中sqlType或mysqlType字段存在,可以通过这两部分的信息解析出更加精确的数据类型。
由sqlType解析Schema
source:
type: kafka
name: Kafka source
properties.bootstrap.servers: localhost:9092
topic: test_topic
properties.group.id: test_group
scan.startup.mode: earliest-offset
value.format: canal-json
# 通过sqlType字段推断Schema
canal-json.infer-schema.strategy: SQL_TYPE
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger由mysqlType解析Schema
source: type: kafka name: Kafka source properties.bootstrap.servers: localhost:9092 topic: test_topic properties.group.id: test_group scan.startup.mode: earliest-offset value.format: canal-json # 通过mysqlType字段推断Schema canal-json.infer-schema.strategy: MYSQL_TYPE # Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更 schema.inference.strategy: continuous # 忽略数据解析过程中的报错 ingestion.ignore-errors: true # 数据解析出现100次报错后,触发作业失败 ingestion.error-tolerance.max-count: 100 sink: type: paimon catalog.properties.metastore: rest catalog.properties.uri: dlf_uri catalog.properties.warehouse: your_warehouse catalog.properties.token.provider: dlf #(可选)开启删除向量,提升读取性能 table.properties.deletion-vectors.enabled: true pipeline: # 开启脏数据收集,脏数据统一写入日志文件 dirty-data.collector: name: Logger Dirty Data Collector type: logger
使用静态Schema
如果Topic中数据的Schema是固定不变的,可以将schema.inference.strategy设置为static,这样配置后数据摄入作业仅会在作业启动时进行一次Schema推导,并且对后续数据也不会再进行Schema解析。
source:
type: kafka
properties.bootstrap.servers: localhost:9092
topic: test_topic
properties.group.id: test_group
scan.startup.mode: earliest-offset
value.format: json
# Schema解析策略设置为static,仅在作业启动时推导一次Schema
schema.inference.strategy: static
# 尝试在每个分区消费20条数据来推导Schema
scan.max.pre.fetch.records: 20
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
# 将 test_topic topic 中所有的数据都写入到 test_database.test_topic 表中
route:
- source-table: test_topic
sink-table: test_database.test_topic
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger此外还可以通过添加scan.value.initial-schemas.ddls参数指定初始表结构,跳过某些表的Schema推导,如下为表db1.t1和db1.t2指定了初始表结构。
source:
type: kafka
name: Kafka source
properties.bootstrap.servers: localhost:9092
topic: test_topic
properties.group.id: test_group
scan.startup.mode: earliest-offset
value.format: json
# 使用数据中的db和table字段作为table id
json.decode.parser-table-id.fields: db,table
# 设置初始表结构
scan.value.initial-schemas.ddls: |
CREATE TABLE db1.t1 (id BIGINT, name VARCHAR(10));
CREATE TABLE db1.t2 (id BIGINT);
# Schema解析策略设置为static,仅在作业启动时推导一次Schema
schema.inference.strategy: static
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: loggerKafka日志数据解析加速
除了通用的Kafka连接器加速配置,针对使用场景的不同,Flink CDC数据摄入作业有一些可以加速解析的配置项。
解析Schema是耗时较多的操作,如果下游只需要String类型,可以开启json.infer-schema.primitive-as-string,debezium-json.infer-schema.primitive-as-string或canal-json.infer-schema.primitive-as-string将字段类型推导跳过并统一设置为String类型来加速解析。
Canal JSON数据可以使用canal-json.database.include和canal-json.table.include来过滤掉不需要的表的数据。
如果可以确定数据Schema不会发生变化,或者不需要进行Schema Evolution,可以将schema.inference.strategy修改为static,只在第一次作业启动时进行Schema推断。
SLS日志数据入湖
SLS日志服务是针对日志类数据的一站式服务,Flink CDC数据摄入支持快速完成SLS日志数据的实时入湖,自动帮助用户完成Schema推导,提供Schema Evolution能力。
source:
type: sls
endpoint: localhost
project: test_pj
logstore: test_log
accessId: access_id
accessKey: access_key
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: loggerTableID:默认会拼接project和logstore作为table id,如上作业得到的table id为test_pj.test_log。
数据类型:SLS连接器默认会将每条日志中的字段类型都推导为String类型。
Schema Evolution:目前仅支持新增列变更,默认会在Schema结尾添加新列。
典型使用场景
下面将介绍一些典型场景下该如何配置作业,更详细的配置请参见数据摄入SLS连接器。
读取元数据
使用metadata.list配置可以读取额外添加的SLS元数据并传递,metadata.list中新增的元数据列可以在transform模块中直接使用,更多支持的元数据请见metadata.list。
需要注意metadata.list添加的列并不会直接放入数据的列中,如果将这部分元数据列写出,需要在transform的projection部分声明出这些列。
如下配置会把__timestamp__和__tag__元数据添加到数据并写入下游,并在transform模块使用这两个元数据,过滤出时间戳大于1772181154且tag为test的数据。
source:
type: sls
endpoint: localhost
project: test_pj
logstore: test_log
accessId: access_id
accessKey: access_key
# 添加元数据列
metadata.list: __timestamp__,__tag__
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
transform:
- source-table: \.*.\.*
projection: \*, __timestamp__ as timestamp_col, __tag__ as tag_col
filter: '`__timestamp__` > 1772181154 and `__tag__` = "test"'
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger脏数据处理
日志数据可能包含格式不正确的脏数据,这些脏数据会导致作业报错不断重启。Flink CDC数据摄入支持忽略解析报错并将错误数据进行收集,详情请参见脏数据收集。
如下所示的作业,会将解析错误的脏数据统一写入日志文件,并在超过100次解析报错后触发作业失败。
source:
type: sls
endpoint: localhost
project: test_pj
logstore: test_log
accessId: access_id
accessKey: access_key
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger指定TableID
如果需要指定字段中的数据作为TableID,需要配置decode.table-id.fields,例如:日志数据为{"col0":"a", "col1":"b", "col2":"c"},不同配置生成TableID如下:
配置 | tableId |
col0 | a |
col0,col1 | a.b |
col0,col1,col2 | a.b.c |
如下作业配置会将数据中的db和table列拼接作为最终的TableID。
source:
type: sls
endpoint: localhost
project: test_pj
logstore: test_log
accessId: access_id
accessKey: access_key
# 使用数据中的db和table字段作为table id
decode.table-id.fields: db,table
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger指定字段类型
数据摄入SLS连接器默认将数据中的全部字段看作String类型, 如果需要指定其中某些字段的类型,可以通过fixed-types配置项指定。
如下作业可以指定id字段类型为BIGINT,name字段类型为VARCHAR(10)。
source:
type: sls
endpoint: localhost
project: test_pj
logstore: test_log
accessId: access_id
accessKey: access_key
# 指定id字段类型为BIGINT,name字段类型为VARCHAR(10)
fixed-types: id BIGINT, name VARCHAR(10)
# Schema解析策略设置为continuous,检测每条消息Schema并同步Schema变更
schema.inference.strategy: continuous
# 忽略数据解析过程中的报错
ingestion.ignore-errors: true
# 数据解析出现100次报错后,触发作业失败
ingestion.error-tolerance.max-count: 100
sink:
type: paimon
catalog.properties.metastore: rest
catalog.properties.uri: dlf_uri
catalog.properties.warehouse: your_warehouse
catalog.properties.token.provider: dlf
#(可选)开启删除向量,提升读取性能
table.properties.deletion-vectors.enabled: true
pipeline:
# 开启脏数据收集,脏数据统一写入日志文件
dirty-data.collector:
name: Logger Dirty Data Collector
type: logger