COS data source
The COS data source connector reads files from Tencent Cloud Object Storage (COS), parses their contents, and syncs the data to any supported destination in DataWorks.
Data types
COS data sources support the following data types.
|
Type |
Description |
|
STRING |
Text. |
|
LONG |
Integer. |
|
BYTES |
Byte array. Text content is converted to a UTF-8 encoded byte array. |
|
BOOL |
Boolean. |
|
DOUBLE |
Floating-point number. |
|
DATE |
Date and time type. Supported formats include |
Create a data source
Before you develop a data sync task, create a data source in DataWorks. For the procedure, see Data Source Management. Tooltips in the configuration UI provide detailed descriptions for each parameter.
Key parameters:
|
Parameter |
Description |
|
Data Source Name |
A custom name for the data source, unique within the workspace. The name can contain letters, numbers, and underscores (_) but cannot start with a number or underscore. |
|
Region |
The region where the bucket is located. Specify the region ID. For more information, see Regions and access domains. |
|
Bucket |
The name of the COS bucket. |
|
Endpoint |
The COS endpoint. For more information, see Regions and access domains. |
|
AccessKey ID |
This is the |
|
AccessKey Secret |
This is the |
Develop a data sync task
For the general procedure and configuration details, see the following sections.
Single-table offline sync task
For the procedure, see Configure in codeless UI and Configure in code editor. For a full list of parameters and a script example for the code editor, see the appendix.
Appendix: Script demo and parameters
Offline sync task script
When using the code editor to configure an offline sync task, format the script parameters as required. For more information, see Configure in code editor. The following sections describe the reader parameters for this data source.
Reader script demo
{
"type": "job",
"version": "2.0",
"steps": [
{
"stepType": "cos",
"parameter": {
"datasource": "",
"object": ["f/z/1.csv"],
"fileFormat": "csv",
"encoding": "utf8/gbk/...",
"fieldDelimiter": ",",
"useMultiCharDelimiter": true,
"lineDelimiter": "\n",
"skipHeader": true,
"compress": "zip/gzip",
"column": [
{
"index": 0,
"type": "long"
},
{
"index": 1,
"type": "boolean"
},
{
"index": 2,
"type": "double"
},
{
"index": 3,
"type": "string"
},
{
"index": 4,
"type": "date"
}
]
},
"name": "Reader",
"category": "reader"
},
{
"stepType": "stream",
"parameter": {},
"name": "Writer",
"category": "writer"
}
],
"setting": {
"errorLimit": {
"record": "0"
},
"speed": {
"concurrent": 1
}
},
"order": {
"hops": [
{
"from": "Reader",
"to": "Writer"
}
]
}
}
Reader script parameters
|
Parameter |
Description |
Required |
Default |
|
datasource |
The data source name. This value must match the name of the data source you created in DataWorks. |
Yes |
None |
|
fileFormat |
The source file format. Supported formats: |
Yes |
None |
|
object |
The file path. Supports the asterisk ( For example, to sync |
Yes |
None |
|
column |
The list of fields to read. To read all columns as STRING, use the following configuration.
To specify individual columns:
Note
Each column definition must include the |
Yes |
All columns are read as the STRING type. |
|
fieldDelimiter |
The field separator used when reading data. You must specify a separator; if omitted, a comma (,) is used by default and is pre-filled in the UI. For invisible characters, enter the Unicode encoding, for example: |
Yes |
, |
|
lineDelimiter |
The line delimiter. This parameter is valid only when |
No |
None |
|
compress |
The compression type. By default, no compression is applied. Supported types: |
No |
Uncompressed |
|
encoding |
The character encoding of the source files. |
No |
utf-8 |
|
nullFormat |
A string in the source file to interpret as a null value. For example:
|
No |
None |
|
skipHeader |
For CSV files, specifies whether to skip the first line (the header row).
Note
The skipHeader parameter is not supported for compressed files. |
No |
false |
|
parquetSchema |
The schema for reading Parquet files. Required only when fileFormat is set to parquet. The general format is:
Example:
|
No |
None |
|
csvReaderConfig |
Advanced parameters for the CSV reader. If not specified, default values are used. |
No |
None |