Skip to content

S3 Writer ​

S3 Writer 插件用于将数据写入 Amazon AWS S3 存储,以及兼容 S3 协议的存储,比如 MinIO。

在实现上,本插件基于 S3 官方的 SDK 2.0 编写。

配置样例 ​

下面的配置用于从内存读取数据,并写入到指定的 S3 bucket 上。

json
{
  "job": {
    "setting": {
      "speed": {
        "byte": -1,
        "channel": 1
      }
    },
    "content": {
      "reader": {
        "name": "streamreader",
        "parameter": {
          "column": [
            {
              "value": "Addax",
              "type": "string"
            },
            {
              "value": 19890604,
              "type": "long"
            },
            {
              "value": "1989-06-04 11:22:33",
              "type": "date"
            },
            {
              "value": true,
              "type": "bool"
            },
            {
              "value": "test",
              "type": "bytes"
            }
          ],
          "sliceRecordCount": 10
        }
      },
      "writer": {
        "name": "s3writer",
        "parameter": {
          "endpoint": "https://s3.amazonaws.com",
          "accessId": "xxxxxxxxxxxx",
          "accessKey": "xxxxxxxxxxxxxxxxxxxxxxx",
          "bucket": "test",
          "object": "upload.csv",
          "region": "ap-northeast-1",
          "encoding": "",
          "fieldDelimiter": ",",
          "writeMode": "truncate"
        }
      }
    }
  }
}

参数说明 ​

配置项是否必须数据类型默认值描述
endpoint是string无S3 Server的 EndPoint地址,例如 s3.xx.amazonaws.com
region是string无S3 Server的 Region 地址,例如 ap-southeast-1
accessId是string无访问 ID
accessKey是string无访问 Key
bucket是string无要写入的 bucket
object是string无要写入的 object,注意事项见下
fieldDelimiter否char','字段的分隔符
nullFormat否char\N当值为空时,用什么字符表示
header否list无写入文件头信息,比如 ["id","title","url"]
maxFileSize否int100000单个 object 的大小,单位为 MB
encoding否stringutf-8文件编码格式
writeMode否stringappend写入模式,详见 hdfswriter 中相关描述
pathStyleAccessEnabled否boolfalse是否使用path access方式访问
sslEnabled否booltrue是否使用ssl方式访问
fileType否stringtext文件类型 text, orc ,parquet
compress否stringorc 默认NONE parquet 默认 UNCOMPRESSEDorc或parquet文件的压缩方式,默认不压缩

object ​

上述配置中的 object 配置的虽然是 upload.csv 文件,实际上在 S3 写入的文件名会在指定的文件名后面加上 uuid 后缀, 类似 upload_c0d2ca7df0444933a6f18ea76718b569.csv。 这是用于在多通道写入的情况下,确保文件名不会重名。

类型转换 ​

Addax 内部类型S3 数据类型
Longint, tinyint, smallint, mediumint, int, bigint
Doublefloat, double, decimal
Stringvarchar, char, tinytext, text, mediumtext, longtext, year,xml
Datedate, datetime, timestamp, time
Booleanbit, bool
Bytestinyblob, mediumblob, blob, longblob, varbinary