跳转至

S3 Writer

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

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

配置样例

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

{
  "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 int 100000 单个 object 的大小,单位为 MB
encoding string utf-8 文件编码格式
writeMode string append 写入模式,详见 hdfswriter 中相关描述
pathStyleAccessEnabled bool false 是否使用path access方式访问
sslEnabled bool true 是否使用ssl方式访问
fileType string text 文件类型 text, orc ,parquet
compress string orc 默认NONE parquet 默认 UNCOMPRESSED orc或parquet文件的压缩方式,默认不压缩

object

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

类型转换

Addax 内部类型 S3 数据类型
Long int, tinyint, smallint, mediumint, int, bigint
Double float, double, decimal
String varchar, char, tinytext, text, mediumtext, longtext, year,xml
Date date, datetime, timestamp, time
Boolean bit, bool
Bytes tinyblob, mediumblob, blob, longblob, varbinary