S3File 是一个用于管理 Amazon S3(Simple Storage Service)的 Python 模块。当前,Apache SeaTunnel 已经支持 S3File Sink Connector,为了更好地使用这个 Connector,有必要看一下这篇使用文档指南。

描述

将数据输出到 AWS S3 文件系统。

提示:

如果您使用的是 Spark/Flink,在使用此连接器之前,必须确保您的 Spark/Flink 集群已经集成了 Hadoop。Hadoop 2.x 版本已通过测试。

如果您使用的是 SeaTunnel Engine,它会在您下载和安装 SeaTunnel Engine 时自动集成 Hadoop JAR 包。您可以在 ${SEATUNNEL_HOME}/lib 目录下确认这个 JAR 包是否存在。

主要特性

默认情况下,我们使用 2PC 提交来确保 "仅一次语义"。

  • 文件格式类型

    • 文本 (text)
    • CSV
    • Parquet
    • ORC
    • JSON
    • Excel

选项

名称 类型 必需 默认值 备注
path string -
bucket string -
fs.s3a.endpoint string -
fs.s3a.aws.credentials.provider string com.amazonaws.auth.InstanceProfileCredentialsProvider
access_key string - 仅在 fs.s3a.aws.credentials.provider = org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider 时使用
access_secret string - 仅在 fs.s3a.aws.credentials.provider = org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider 时使用
custom_filename boolean false 是否需要自定义文件名
file_name_expression string "${transactionId}" 仅在 custom_filename 为 true 时使用
filename_time_format string "yyyy.MM.dd" 仅在 custom_filename 为 true 时使用
file_format_type string "csv"
field_delimiter string '\001' 仅在 file_format 为 text 时使用
row_delimiter string "\n" 仅在 file_format 为 text 时使用
have_partition boolean false 是否需要处理分区
partition_by array - 仅在 have_partition 为 true 时使用
partition_dir_expression string "${k0}=${v0}/${k1}=${v1}/.../${kn}=${vn}/" 仅在 have_partition 为 true 时使用
is_partition_field_write_in_file boolean false 仅在 have_partition 为 true 时使用
sink_columns array 当此参数为空时,将写入所有从 "Transform" 或 "Source" 获取的字段
is_enable_transaction boolean true
batch_size int 1000000
compress_codec string none
common-options object -
max_rows_in_memory int - 仅在 file_format 为 Excel 时使用
sheet_name string Sheet$ 仅在 file_format 为 Excel 时使用

path [string]

目标目录路径是必需的。

bucket [string]

S3 文件系统的bucket地址,例如:s3n://seatunnel-test,如果您使用的是 s3a 协议,此参数应为 s3a://seatunnel-test

fs.s3a.endpoint [string]

fs s3a 端点

fs.s3a.aws.credentials.provider [string]

认证 s3a 的方式。目前我们仅支持 org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvidercom.amazonaws.auth.InstanceProfileCredentialsProvider

关于凭证提供程序的更多信息,您可以参考 Hadoop AWS 文档

access_key [string]

S3 文件系统的访问密钥。如果未设置此参数,请确认凭证提供程序链可以正确验证,可参考 hadoop-aws

access_secret [string]

S3 文件系统的访问密钥。如果未设置此参数,请确认凭证提供程序链可以正确验证,可参考 hadoop-aws

hadoop_s3_properties [map]

如果需要添加其他选项,可以在这里添加并参考此 链接

hadoop_s3_properties {
"fs.s3a.buffer.dir" = "/data/st_test/s3a"
"fs.s3a.fast.upload.buffer" = "disk"
}

custom_filename [boolean]

是否自定义文件名。

file_name_expression [string]

仅在 custom_filenametrue 时使用

file_name_expression 描述了将创建到 path 中的文件表达式。我们可以在 file_name_expression 中添加变量 ${now} ${uuid},例如 test_${uuid}_${now}

${now} 代表当前时间,其格式可以通过指定选项 filename_time_format 来定义。

请注意,如果 is_enable_transactiontrue,我们将在文件名的开头自动添加${transactionId}_

filename_time_format [string]

仅在 custom_filenametrue 时使用

file_name_expression 参数中的格式为 xxxx-${now} 时,filename_time_format 可以指定路径的时间格式,默认值为 yyyy.MM.dd。常用的时间格式列于下表中:

符号 描述
y
M
d 月中的天数
H 一天中的小时 (0-23)
m 小时中的分钟
s 分钟中的秒数

file_format_type [string]

我们支持以下文件类型:

  • 文本 (text)
  • JSON
  • CSV
  • ORC
  • Parquet
  • Excel

请注意,最终文件名将以文件格式的后缀结尾,文本文件的后缀是 txt

field_delimiter [string]

数据行中列之间的分隔符。仅在 file_format 为 text 时需要。

row_delimiter [string]

文件中行之间的分隔符。仅在 file_format 为 text 时需要。

have_partition [boolean]

是否需要处理分区。

partition_by [array]

仅在 have_partitiontrue 时使用。

基于选定字段对分区数据进行分区。

partition_dir_expression [string]

仅在 have_partitiontrue 时使用。

如果指定了 partition_by,我们将根据分区信息生成相应的分区目录,并将最终文件放在分区目录中。

默认的 partition_dir_expression${k0}=${v0}/${k1}=${v1}/.../${kn}=${vn}/k0 是第一个分区字段,v0 是第一个分区字段的值。

is_partition_field_write_in_file [boolean]

仅在 have_partitiontrue 时使用。

如果 is_partition_field_write_in_filetrue,分区字段及其值将写入数据文件中。

例如,如果您想要写入 Hive 数据文件,其值应为 false

sink_columns [array]

需要写入文件的哪些列,默认值为从 "Transform" 或 "Source" 获取的所有列。

字段的顺序决定了实际写入文件的顺序。

is_enable_transaction [boolean]

如果 is_enable_transaction 为 true,我们将确保在写入目标目录时数据不会丢失或重复。

请注意,如果 is_enable_transactiontrue,我们将在文件头部自动添加 ${transactionId}_

目前仅支持 true

batch_size [int]

文件中的最大行数。对于 SeaTunnel Engine,文件中的行数由 batch_sizecheckpoint.interval 共同决定。如果 checkpoint.interval 的值足够大,当文件中的行数大于 batch_size 时,写入器将写入文件。如果 checkpoint.interval 较小,则在新的检查点触发时,写入器将创建一个新文件。

compress_codec [string]

文件的压缩编解码器及其支持的详细信息如下:

  • txt: lzo none
  • JSON: lzo none
  • CSV: lzo none
  • ORC: lzo snappy lz4 zlib none
  • Parquet: lzo snappy lz4 gzip brotli zstd none

提示:Excel 类型不支持任何压缩格式。

常见选项

请参考 Sink Common Options 获取 Sink 插件的常见参数详细信息。

max_rows_in_memory [int]

当文件格式为 Excel 时,可以缓存在内存中的数据项的最大数量。

sheet_name [string]

工作簿的工作表名称。

示例

对于文本文件格式,具有 have_partitioncustom_filenamesink_columnscom.amazonaws.auth.InstanceProfileCredentialsProvider 的配置示例:

  S3File {
bucket = "s3a://seatunnel-test"
tmp_path = "/tmp/seatunnel"
path="/seatunnel/text"
fs.s3a.endpoint="s3.cn-north-1.amazonaws.com.cn"
fs.s3a.aws.credentials.provider="com.amazonaws.auth.InstanceProfileCredentialsProvider"
file_format_type = "text"
field_delimiter = "\t"
row_delimiter = "\n"
have_partition = true
partition_by = ["age"]
partition_dir_expression = "${k0}=${v0}"
is_partition_field_write_in_file = true
custom_filename = true
file_name_expression = "${transactionId}_${now}"
filename_time_format = "yyyy.MM.dd"
sink_columns = ["name","age"]
is_enable_transaction=true
hadoop_s3_properties {
"fs.s3a.buffer.dir" = "/data/st_test/s3a"
"fs.s3a.fast.upload.buffer" = "disk"
}
}

对于 Parquet 文件格式,仅需用 org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider进行配置:

  S3File {
bucket = "s3a://seatunnel-test"
tmp_path = "/tmp/seatunnel"
path="/seatunnel/parquet"
fs.s3a.endpoint="s3.cn-north-1.amazonaws.com.cn"
fs.s3a.aws.credentials.provider="org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider"
access_key = "xxxxxxxxxxxxxxxxx"
secret_key = "xxxxxxxxxxxxxxxxx"
file_format_type = "parquet"
hadoop_s3_properties {
"fs.s3a.buffer.dir" = "/data/st_test/s3a"
"fs.s3a.fast.upload.buffer" = "disk"
}
}

对于 orc 文件仅需配置 org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider

  S3File {
bucket = "s3a://seatunnel-test"
tmp_path = "/tmp/seatunnel"
path="/seatunnel/orc"
fs.s3a.endpoint="s3.cn-north-1.amazonaws.com.cn"
fs.s3a.aws.credentials.provider="org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider"
access_key = "xxxxxxxxxxxxxxxxx"
secret_key = "xxxxxxxxxxxxxxxxx"
file_format_type = "orc"
}

更新日志

2.3.0-beta 2022-10-20

  • 添加 S3File Sink 连接器

2.3.0 2022-12-30

  • Bug修复

    • 修复了以下导致数据写入文件失败的错误:

      • 当上游字段为空时会抛出 NullPointerException
      • Sink 列映射失败
      • 从状态中恢复写入器时直接获取事务失败 (3258)
  • 功能
    • 支持 S3A 协议 (3632)

      • 允许用户添加额外的 Hadoop-S3 参数
      • 允许使用 S3A 协议
      • 解耦 Hadoop-AWS 依赖
    • 支持设置每个文件的批处理大小 (3625)
    • 设置 S3 AK 为可选项 (3688)

下一版本

本文由 白鲸开源 提供发布支持!

必看!S3File Sink Connector 使用文档的更多相关文章

  1. 看云&gitbook 写帮助文档 | 专注于文档在线创作、协作和托管

    看云 写帮助文档 | 专注于文档在线创作.协作和托管 https://www.kancloud.cn/manual/thinkphp/1678 https://www.gitbook.com/

  2. 看淘宝营销api 文档有感

    total: use appkey & secrect variance naming rule 提供沙箱环境 使用api gateway 使用rest(但返回结果包裹了 isp.thread ...

  3. 苹果Xcode帮助文档阅读指南

    文档导读 https://developer.apple.com/legacy/library/navigation/ 前面我们讲Xcode的文档结构是在介绍如何能够快速定位到你要找的内容.但是很多人 ...

  4. 转:苹果Xcode帮助文档阅读指南

    一直想写这么一个东西,长期以来我发现很多初学者的问题在于不掌握学习的方法,所以,Xcode那么好的SDK文档摆在那里,对他们也起不到什么太大的作用.从论坛.微博等等地方看到的初学者提出的问题,也暴露出 ...

  5. apidoc接口文档的快速生成

    官方文档连接:http://apidocjs.com/#demo apidoc是一个轻量级的在线REST接口文档生成系统,支持多种主流语言,包括Java.C.C#.PHP和Javascript等.使用 ...

  6. 【命令】man命令帮助文档详解

    前言:Linux命令分为内建命令和外部命令:内建命令是shell本身自带的,外部命令是是一个可执行程序 我们在使用命令帮助的时候需要钱哦区分命令是内建命令还是外部命令 一.查看一个命令是内建命令还是外 ...

  7. ABP文档 :Overall - Module System

    模块介绍 ABP提供了构建模块并将这些模块组合起来创建应用的基础设施.一个模块可以依赖另一个模块.一般来说,一个程序集可以认为是一个模块.如果应用中有多个程序集,建议为每个程序集创建一个模块定义.模块 ...

  8. Web API 自动生成帮助文档并使用Web API Test Client 测试

    之前在项目中有用到webapi对外提供接口,发现在项目中有根据webapi的方法和注释自动生成帮助文档,还可以测试webapi方法,功能很是强大,现拿出来与大家分享一下. 先看一下生成的webapi文 ...

  9. webAPI 自动生成帮助文档

    之前在项目中有用到webapi对外提供接口,发现在项目中有根据webapi的方法和注释自动生成帮助文档,还可以测试webapi方法,功能很是强大,现拿出来与大家分享一下. 先看一下生成的webapi文 ...

  10. asp.net webAPI 自动生成帮助文档并测试

    之前在项目中有用到webapi对外提供接口,发现在项目中有根据webapi的方法和注释自动生成帮助文档,还可以测试webapi方法,功能很是强大,现拿出来与大家分享一下. 先看一下生成的webapi文 ...

随机推荐

  1. springboot拦截器@resource注解注入为null解决方案 拦截适配配置

    springboot拦截器@resource注解注入为null解决方案  拦截适配配置 为什么@resource注入为nullinteceptor在springcontext之前加载,注入必然是nul ...

  2. python写文件,过滤空行,根据某一行打上标记

    import shutil import os ###第一步写文件 ''' with open('test.txt', 'w',encoding='utf-8') as f: f.write(&quo ...

  3. python 使用pandas修改数据到excel,报“SettingwithCopyWarning A value is trying to be set on a copy of a slice from a DataFrame”的解决方法

    场景: 通过pandas模块,将测试数据回写到excel,测试数据有写到excel文件,但控制台输出警告信息如下 警告: SettingwithCopyWarning A value is tryin ...

  4. vim 中代码的折叠和打开

    # vim 中代码的折叠和打开 reference: vim中代码的折叠和打开(有删改) https://www.cnblogs.com/xuxm2007/archive/2011/11/10/224 ...

  5. 【路径规划】OSQP曲线平滑 公式及代码

    参考与前言 apollo 代码:https://github.com/ApolloAuto/apollo/tree/master/modules/planning/math/smoothing_spl ...

  6. RK3568J“麒麟”+“翼辉”国产系统正式发布,“鸿蒙”也正在路上!

    RK3568J "麒麟" + "翼辉"国产系统正式发布 近期,创龙科技RK3568J全国产平台(国产化率100%,提供报告)已正式适配两大国产系统:银河麒麟嵌入 ...

  7. P9212 题解

    显然,我们维护的答案具有 可差分 性,所以转换为 \([1,r]\) 上的查询. 首先,对于 \(x,y,a_i\) 先对 \(m\) 取模不影响结果. 下面为了方便令 \(v = a_i\). 如果 ...

  8. Java子类是否能继承父类上的注解

    子类可以继承到父类上的注解吗? 在编写自定义注解时,可以通过指定@Inherited注解,申明自定义注解是否可以被继承:@Inherited只能实现类上的注解继承. 实现情况可细分为以下几种 未申明@ ...

  9. 推荐常用的Idea插件

    Idea常用快捷键 删除所有空行 使用替换 Ctrl + R 点亮后面的魔法图标启用正则表达式,输入:^\s*\n,然后选择替换全部 查询指定类或方法在哪里被引用 光标点中需要查找的类名和方法名,然后 ...

  10. Mybatis-Plus最优化持久层开发

    Mybatis-plus:最优化持久层开发 一:Mybatis-plus快速入门: 1.1:简介: Mybatis-plus(简称MP)是一个Mybatis的增强工具,在mybatis的基础上只做增强 ...