跳到主要内容
版本:Next

S3File

S3 File Source Connector

Support Those Engines

Spark
Flink
SeaTunnel Zeta

Key Features

Read all the data in a split in a pollNext call. What splits are read will be saved in snapshot.

Description

Read data from aws s3 file system.

Supported DataSource Info

DatasourceSupported versions
S3current

Dependency

If you use spark/flink, In order to use this connector, You must ensure your spark/flink cluster already integrated hadoop. The tested hadoop version is 2.x.

If you use SeaTunnel Zeta, It automatically integrated the hadoop jar when you download and install SeaTunnel Zeta. You can check the jar package under ${SEATUNNEL_HOME}/lib to confirm this.
To use this connector you need put hadoop-aws-3.1.4.jar and aws-java-sdk-bundle-1.12.692.jar in ${SEATUNNEL_HOME}/lib dir.

Data Type Mapping

Data type mapping is related to the type of file being read, We supported as the following file types:

text csv parquet orc json excel xml

JSON File Type

If you assign file type to json, you should also assign schema option to tell connector how to parse data to the row you want.

For example:

upstream data is the following:


{"code": 200, "data": "get success", "success": true}

You can also save multiple pieces of data in one file and split them by newline:


{"code": 200, "data": "get success", "success": true}
{"code": 300, "data": "get failed", "success": false}

you should assign schema as the following:


schema {
fields {
code = int
data = string
success = boolean
}
}

connector will generate data as the following:

codedatasuccess
200get successtrue

Text Or CSV File Type

If you set the file_format_type to text,excel,csv,xml. Then it's required to set the schema field to tell connector how to parse data to the row.

If you set the schema field, you should also set the option field_delimiter, except the file_format_type is csv, xml, excel

you can set schema and delimiter as the following:


field_delimiter = "#"
schema {
fields {
name = string
age = int
gender = string
}
}

connector will generate data as the following:

nameagegender
tyrantlucifer26male

Orc File Type

If you assign file type to parquet orc, schema option not required, connector can find the schema of upstream data automatically.

Orc Data typeSeaTunnel Data type
BOOLEANBOOLEAN
INTINT
BYTEBYTE
SHORTSHORT
LONGLONG
FLOATFLOAT
DOUBLEDOUBLE
BINARYBINARY
STRING
VARCHAR
CHAR
STRING
DATELOCAL_DATE_TYPE
TIMESTAMPLOCAL_DATE_TIME_TYPE
DECIMALDECIMAL
LIST(STRING)STRING_ARRAY_TYPE
LIST(BOOLEAN)BOOLEAN_ARRAY_TYPE
LIST(TINYINT)BYTE_ARRAY_TYPE
LIST(SMALLINT)SHORT_ARRAY_TYPE
LIST(INT)INT_ARRAY_TYPE
LIST(BIGINT)LONG_ARRAY_TYPE
LIST(FLOAT)FLOAT_ARRAY_TYPE
LIST(DOUBLE)DOUBLE_ARRAY_TYPE
Map<K,V>MapType, This type of K and V will transform to SeaTunnel type
STRUCTSeaTunnelRowType

Parquet File Type

If you assign file type to parquet orc, schema option not required, connector can find the schema of upstream data automatically.

Parquet Data typeSeaTunnel Data type
INT_8BYTE
INT_16SHORT
DATEDATE
TIMESTAMP_MILLISTIMESTAMP
INT64LONG
INT96TIMESTAMP
BINARYBYTES
FLOATFLOAT
DOUBLEDOUBLE
BOOLEANBOOLEAN
FIXED_LEN_BYTE_ARRAYTIMESTAMP
DECIMAL
DECIMALDECIMAL
LIST(STRING)STRING_ARRAY_TYPE
LIST(BOOLEAN)BOOLEAN_ARRAY_TYPE
LIST(TINYINT)BYTE_ARRAY_TYPE
LIST(SMALLINT)SHORT_ARRAY_TYPE
LIST(INT)INT_ARRAY_TYPE
LIST(BIGINT)LONG_ARRAY_TYPE
LIST(FLOAT)FLOAT_ARRAY_TYPE
LIST(DOUBLE)DOUBLE_ARRAY_TYPE
Map<K,V>MapType, This type of K and V will transform to SeaTunnel type
STRUCTSeaTunnelRowType

Options

nametyperequireddefault valueDescription
pathstringyes-The s3 path that needs to be read can have sub paths, but the sub paths need to meet certain format requirements. Specific requirements can be referred to "parse_partition_from_path" option
file_format_typestringyes-File type, supported as the following file types: text csv parquet orc json excel xml binary
bucketstringyes-The bucket address of s3 file system, for example: s3n://seatunnel-test, if you use s3a protocol, this parameter should be s3a://seatunnel-test.
fs.s3a.endpointstringyes-fs s3a endpoint
fs.s3a.aws.credentials.providerstringyescom.amazonaws.auth.InstanceProfileCredentialsProviderThe way to authenticate s3a. We only support org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider and com.amazonaws.auth.InstanceProfileCredentialsProvider now. More information about the credential provider you can see Hadoop AWS Document
read_columnslistno-The read column list of the data source, user can use it to implement field projection. The file type supported column projection as the following shown: text csv parquet orc json excel xml . If the user wants to use this feature when reading text json csv files, the "schema" option must be configured.
access_keystringno-Only used when fs.s3a.aws.credentials.provider = org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider
access_secretstringno-Only used when fs.s3a.aws.credentials.provider = org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider
hadoop_s3_propertiesmapno-If you need to add other option, you could add it here and refer to this link
delimiter/field_delimiterstringno\001Field delimiter, used to tell connector how to slice and dice fields when reading text files. Default \001, the same as hive's default delimiter.
parse_partition_from_pathbooleannotrueControl whether parse the partition keys and values from file path. For example if you read a file from path s3n://hadoop-cluster/tmp/seatunnel/parquet/name=tyrantlucifer/age=26. Every record data from file will be added these two fields: name="tyrantlucifer", age=16
date_formatstringnoyyyy-MM-ddDate type format, used to tell connector how to convert string to date, supported as the following formats:yyyy-MM-dd yyyy.MM.dd yyyy/MM/dd. default yyyy-MM-dd
datetime_formatstringnoyyyy-MM-dd HH:mm:ssDatetime type format, used to tell connector how to convert string to datetime, supported as the following formats:yyyy-MM-dd HH:mm:ss yyyy.MM.dd HH:mm:ss yyyy/MM/dd HH:mm:ss yyyyMMddHHmmss
time_formatstringnoHH:mm:ssTime type format, used to tell connector how to convert string to time, supported as the following formats:HH:mm:ss HH:mm:ss.SSS
skip_header_row_numberlongno0Skip the first few lines, but only for the txt and csv. For example, set like following:skip_header_row_number = 2. Then SeaTunnel will skip the first 2 lines from source files
schemaconfigno-The schema of upstream data.
sheet_namestringno-Reader the sheet of the workbook,Only used when file_format is excel.
xml_row_tagstringno-Specifies the tag name of the data rows within the XML file, only valid for XML files.
xml_use_attr_formatbooleanno-Specifies whether to process data using the tag attribute format, only valid for XML files.
compress_codecstringnonone
archive_compress_codecstringnonone
encodingstringnoUTF-8
null_formatstringno-Only used when file_format_type is text. null_format to define which strings can be represented as null. e.g: \N
file_filter_patternstringnoFilter pattern, which used for filtering files.
filename_extensionstringno-Filter filename extension, which used for filtering files with specific extension. Example: csv .txt json .xml.
common-optionsno-Source plugin common parameters, please refer to Source Common Options for details.

delimiter/field_delimiter [string]

delimiter parameter will deprecate after version 2.3.5, please use field_delimiter instead.

file_filter_pattern [string]

Filter pattern, which used for filtering files.

The pattern follows standard regular expressions. For details, please refer to https://en.wikipedia.org/wiki/Regular_expression. There are some examples.

File Structure Example:

/data/seatunnel/20241001/report.txt
/data/seatunnel/20241007/abch202410.csv
/data/seatunnel/20241002/abcg202410.csv
/data/seatunnel/20241005/old_data.csv
/data/seatunnel/20241012/logo.png

Matching Rules Example:

Example 1: Match all .txt files,Regular Expression:

/data/seatunnel/20241001/.*\.txt

The result of this example matching is:

/data/seatunnel/20241001/report.txt

Example 2: Match all file starting with abc,Regular Expression:

/data/seatunnel/20241002/abc.*

The result of this example matching is:

/data/seatunnel/20241007/abch202410.csv
/data/seatunnel/20241002/abcg202410.csv

Example 3: Match all file starting with abc,And the fourth character is either h or g, the Regular Expression:

/data/seatunnel/20241007/abc[h,g].*

The result of this example matching is:

/data/seatunnel/20241007/abch202410.csv

Example 4: Match third level folders starting with 202410 and files ending with .csv, the Regular Expression:

/data/seatunnel/202410\d*/.*\.csv

The result of this example matching is:

/data/seatunnel/20241007/abch202410.csv
/data/seatunnel/20241002/abcg202410.csv
/data/seatunnel/20241005/old_data.csv

compress_codec [string]

The compress codec of files and the details that supported as the following shown:

  • txt: lzo none
  • json: lzo none
  • csv: lzo none
  • orc/parquet:
    automatically recognizes the compression type, no additional settings required.

archive_compress_codec [string]

The compress codec of archive files and the details that supported as the following shown:

archive_compress_codecfile_formatarchive_compress_suffix
ZIPtxt,json,excel,xml.zip
TARtxt,json,excel,xml.tar
TAR_GZtxt,json,excel,xml.tar.gz
GZtxt,json,excel,xml.gz
NONEall.*

Note: gz compressed excel file needs to compress the original file or specify the file suffix, such as e2e.xls ->e2e_test.xls.gz

encoding [string]

Only used when file_format_type is json,text,csv,xml. The encoding of the file to read. This param will be parsed by Charset.forName(encoding).

Example

  1. In this example, We read data from s3 path s3a://seatunnel-test/seatunnel/text and the file type is orc in this path. We use org.apache.hadoop.fs.s3a.SimpleAWSCredentialsProvider to authentication so access_key and secret_key is required. All columns in the file will be read and send to sink.
# Defining the runtime environment
env {
parallelism = 1
job.mode = "BATCH"
}

source {
S3File {
path = "/seatunnel/text"
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"
bucket = "s3a://seatunnel-test"
file_format_type = "orc"
}
}

transform {
# If you would like to get more information about how to configure seatunnel and see full list of transform plugins,
# please go to https://seatunnel.apache.org/docs/category/transform-v2
}

sink {
Console {}
}
  1. Use InstanceProfileCredentialsProvider to authentication The file type in S3 is json, so need config schema option.

S3File {
path = "/seatunnel/json"
bucket = "s3a://seatunnel-test"
fs.s3a.endpoint="s3.cn-north-1.amazonaws.com.cn"
fs.s3a.aws.credentials.provider="com.amazonaws.auth.InstanceProfileCredentialsProvider"
file_format_type = "json"
schema {
fields {
id = int
name = string
}
}
}

  1. Use InstanceProfileCredentialsProvider to authentication The file type in S3 is json and has five fields (id, name, age, sex, type), so need config schema option. In this job, we only need send id and name column to mysql.
# Defining the runtime environment
env {
parallelism = 1
job.mode = "BATCH"
}

source {
S3File {
path = "/seatunnel/json"
bucket = "s3a://seatunnel-test"
fs.s3a.endpoint="s3.cn-north-1.amazonaws.com.cn"
fs.s3a.aws.credentials.provider="com.amazonaws.auth.InstanceProfileCredentialsProvider"
file_format_type = "json"
read_columns = ["id", "name"]
schema {
fields {
id = int
name = string
age = int
sex = int
type = string
}
}
}
}

transform {
# If you would like to get more information about how to configure seatunnel and see full list of transform plugins,
# please go to https://seatunnel.apache.org/docs/category/transform-v2
}

sink {
Console {}
}

Filter File

env {
parallelism = 1
job.mode = "BATCH"
}

source {
S3File {
path = "/seatunnel/json"
bucket = "s3a://seatunnel-test"
fs.s3a.endpoint="s3.cn-north-1.amazonaws.com.cn"
fs.s3a.aws.credentials.provider="com.amazonaws.auth.InstanceProfileCredentialsProvider"
file_format_type = "json"
read_columns = ["id", "name"]
// file example abcD2024.csv
file_filter_pattern = "abc[DX]*.*"
}
}

sink {
Console {
}
}

Changelog

2.3.0-beta 2022-10-20

  • Add S3File Source Connector

Next version

  • [Feature] Support S3A protocol (3632)
    • Allow user to add additional hadoop-s3 parameters
    • Allow the use of the s3a protocol
    • Decouple hadoop-aws dependencies
  • [Feature]Set S3 AK to optional (3688)

Changelog

Change Log
ChangeCommitVersion
[Fix][Connector-V2] Fixed incorrectly setting s3 key in some cases (#8885)https://github.com/apache/seatunnel/commit/cf4bab5be2dev
[Feature][Connector-V2] Add filename_extension parameter for read/write file (#8769)https://github.com/apache/seatunnel/commit/78b23c0ef5dev
[Improve] restruct connector common options (#8634)https://github.com/apache/seatunnel/commit/f3499a6eebdev
[improve] update S3File connector config option (#8615)https://github.com/apache/seatunnel/commit/80cc9fa6ffdev
[Feature][Connector-V2] Support create emtpy file when no data (#8543)https://github.com/apache/seatunnel/commit/275db78918dev
[Feature][Connector-V2] Support single file mode in file sink (#8518)https://github.com/apache/seatunnel/commit/e893deed50dev
[Feature][File] Support config null format for text file read (#8109)https://github.com/apache/seatunnel/commit/2dbf02df472.3.9
[Hotfix][Zeta] Fix the dependency conflict between the guava in hadoop-aws and hive-exec (#7986)https://github.com/apache/seatunnel/commit/a7837f1f192.3.9
[Feature][Restapi] Allow metrics information to be associated to logical plan nodes (#7786)https://github.com/apache/seatunnel/commit/6b7c53d03c2.3.9
[Improve][Connector-V2] Support read archive compress file (#7633)https://github.com/apache/seatunnel/commit/3f98cd8a162.3.8
[Improve] Refactor S3FileCatalog and it's factory (#7457)https://github.com/apache/seatunnel/commit/d928e8b1132.3.8
[Improve][Connector] Add multi-table sink option check (#7360)https://github.com/apache/seatunnel/commit/2489f6446b2.3.7
[Feature][Core] Support using upstream table placeholders in sink options and auto replacement (#7131)https://github.com/apache/seatunnel/commit/c4ca74122c2.3.6
[Improve][Files] Support write fixed/timestamp as int96 of parquet (#6971)https://github.com/apache/seatunnel/commit/1a48a9c4932.3.6
[Feature][S3 File] Make S3 File Connector support multiple table write (#6698)https://github.com/apache/seatunnel/commit/8f2049b2f12.3.6
[Improve][Connector-v2] The hive connector support multiple filesystem (#6648)https://github.com/apache/seatunnel/commit/8a4c01fe352.3.6
[bigfix][S3 File]:Change the [SCHEMA] attribute of the [S3CONF class] to be non-static to avoid being reassigned after deserialization (#6717)https://github.com/apache/seatunnel/commit/79bb70101a2.3.6
[Fix][Connector-V2] Fix connector support SPI but without no args constructor (#6551)https://github.com/apache/seatunnel/commit/5f3c9c36a52.3.5
Add support for XML file type to various file connectors such as SFTP, FTP, LocalFile, HdfsFile, and more. (#6327)https://github.com/apache/seatunnel/commit/ec533ecd9a2.3.5
[Test][E2E] Add thread leak check for connector (#5773)https://github.com/apache/seatunnel/commit/1f2f3fc5f02.3.4
[Feature][Connector]add s3file save mode function (#6131)https://github.com/apache/seatunnel/commit/81c51073bf2.3.4
[Refactor][File Connector] Put Multiple Table File API to File Base Module (#6033)https://github.com/apache/seatunnel/commit/c324d663b42.3.4
Support using multiple hadoop account (#5903)https://github.com/apache/seatunnel/commit/d69d88d1aa2.3.4
[Improve][Common] Introduce new error define rule (#5793)https://github.com/apache/seatunnel/commit/9d1b2582b22.3.4
[Improve][connector-file] unifiy option between file source/sink and update document (#5680)https://github.com/apache/seatunnel/commit/8d87cf8fc42.3.4
[Feature] Support LZO compress on File Read (#5083)https://github.com/apache/seatunnel/commit/a4a19010962.3.4
[Feature][Connector-V2][File] Support read empty directory (#5591)https://github.com/apache/seatunnel/commit/1f58f224a02.3.4
Support config column/primaryKey/constraintKey in schema (#5564)https://github.com/apache/seatunnel/commit/eac76b4e502.3.4
[Feature][File Connector]optionrule FILE_FORMAT_TYPE is text/csv ,add parameter BaseSinkConfig.ENABLE_HEADER_WRITE: #5566 (#5567)https://github.com/apache/seatunnel/commit/0e02db768d2.3.4
[Feature][Connector V2][File] Add config of 'file_filter_pattern', which used for filtering files. (#5153)https://github.com/apache/seatunnel/commit/a3c13e59eb2.3.3
[chore] delete unavailable S3 & Kafka Catalogs (#4477)https://github.com/apache/seatunnel/commit/e0aec5ecec2.3.2
[Feature][ConnectorV2]add file excel sink and source (#4164)https://github.com/apache/seatunnel/commit/e3b97ae5d22.3.2
Change file type to file_format_type in file source/sink (#4249)https://github.com/apache/seatunnel/commit/973a2fae3c2.3.1
[Chore] Upgrade guava to 27.0-jre (#4238)https://github.com/apache/seatunnel/commit/4851bee5752.3.1
Add redshift datatype convertor (#4245)https://github.com/apache/seatunnel/commit/b19011517f2.3.1
Merge branch 'dev' into merge/cdchttps://github.com/apache/seatunnel/commit/4324ee19122.3.1
[Improve][Project] Code format with spotless plugin.https://github.com/apache/seatunnel/commit/423b5830382.3.1
[improve][api] Refactoring schema parse (#4157)https://github.com/apache/seatunnel/commit/b2f573a13e2.3.1
[Improve][build] Give the maven module a human readable name (#4114)https://github.com/apache/seatunnel/commit/d7cd6010512.3.1
Add S3Catalog (#4121)https://github.com/apache/seatunnel/commit/7d7f5065472.3.1
[Improve][Project] Code format with spotless plugin. (#4101)https://github.com/apache/seatunnel/commit/a2ab1665612.3.1
[Feature][Connector-V2][File] Support compress (#3899)https://github.com/apache/seatunnel/commit/55602f6b1c2.3.1
[Feature][Connector] add get source method to all source connector (#3846)https://github.com/apache/seatunnel/commit/417178fb842.3.1
[Improve][Connector-V2][File] Improve file connector option rule and document (#3812)https://github.com/apache/seatunnel/commit/bd760776692.3.1
[Feature][Shade] Add seatunnel hadoop3 uber (#3755)https://github.com/apache/seatunnel/commit/5a024bdf8f2.3.0
[Engine][Checkpoint]Unified naming style (#3714)https://github.com/apache/seatunnel/commit/bc0bd3bec32.3.0
[Connector][File-S3]Set AK is not required (#3713)https://github.com/apache/seatunnel/commit/da3c5261722.3.0
[Connector&Engine]Set S3 AK to optional (#3688)https://github.com/apache/seatunnel/commit/4710918b022.3.0
[Connector][S3]Support s3a protocol (#3632)https://github.com/apache/seatunnel/commit/ae4cc9c1ec2.3.0
[Hotfix][OptionRule] Fix option rule about all connectors (#3592)https://github.com/apache/seatunnel/commit/226dc6a1192.3.0
[Improve][Connector-V2][File] Unified excetion for file source & sink connectors (#3525)https://github.com/apache/seatunnel/commit/031e8e263c2.3.0
[Feature][Connector-V2][File] Add option and factory for file connectors (#3375)https://github.com/apache/seatunnel/commit/db286e86312.3.0
[Improve][Connector-V2][File] Improve code structure (#3238)https://github.com/apache/seatunnel/commit/dd5c3538812.3.0
[Connector-V2][ElasticSearch] Add ElasticSearch Source/Sink Factory (#3325)https://github.com/apache/seatunnel/commit/38254e3f262.3.0
[Feature][Connector-V2][S3] Add S3 file source & sink connector (#3119)https://github.com/apache/seatunnel/commit/f27d68ca9c2.3.0-beta