The OSS data source provides read and write access to OSS. This topic describes how DataWorks supports OSS data synchronization.
Supported field types and limitations
Batch data read
The OSS Reader reads data from OSS and converts it into a format that Data Integration can process. As OSS is an unstructured data storage service, the reader supports the following features.
|
Supported |
Not supported |
|
|
-
When you prepare data in OSS, CSV files must conform to the standard CSV format. For example, you must escape any double quotation mark (") in a column by replacing it with two double quotation marks (""), otherwise the file may be incorrectly split. If a file contains multiple delimiters, we recommend that you use the text type.
-
OSS is an unstructured data source that stores file-type data. Before you synchronize data, verify that the field structure of the data to be synchronized meets your expectations. Similarly, if the data structure of an unstructured data source changes, you must re-confirm the field structure in the task configuration. Otherwise, data synchronization errors may occur.
Batch data write
The OSS Writer converts data from the Data Integration protocol into text files in OSS. As OSS is an unstructured data storage service, the writer supports the following features.
|
Supported |
Not supported |
|
|
|
Category |
Data Integration column type |
|
Integer |
LONG |
|
String |
STRING |
|
Floating-point |
DOUBLE |
|
Boolean |
BOOLEAN |
|
Date and time |
DATE |
Real-time write
-
Supports real-time write capabilities.
-
Single-table real-time write to data lakes is supported: Hudi (0.12.x), Paimon, and Iceberg.
Create a data source
Before you develop a synchronization task in DataWorks, you must add the required data source to DataWorks by following the instructions in Data source configuration. You can view parameter descriptions in the DataWorks console to understand the meanings of the parameters when you add a data source.
-
To create an OSS data source across Alibaba Cloud accounts, you must grant the required permissions to the corresponding accounts. For more information, see Use bucket policies to grant cross-account access to OSS.
-
If you use the RAM role-based authorization mode to configure an OSS data source, see RAM role-based authorization: Configure a data source for more information.
-
To create an OSS data source across regions, we recommend that you use the public endpoint. For more information, see Access domains and network connectivity.
Data synchronization task development
For information about the entry point for and the procedure of configuring a synchronization task, see the following configuration guides.
Single-table batch synchronization task configuration guide
-
For the procedure, see Codeless UI configuration and Script mode configuration.
-
For all parameters and script demos available in script mode, see Appendix: script demos and parameter description below.
Single-table real-time synchronization task configuration guide
For the procedure, see Single-table real-time synchronization task configuration.
Full-database synchronization configuration guide
For the procedure, see Full-Database Batch Synchronization Task Capabilities and Full-Database Real-Time Synchronization Task Capabilities.
FAQ
Is there a file count limit when reading OSS files?
How do I handle dirty data when reading CSV files with multi-character delimiters?
Appendix: Script demos and parameter description
Configure a batch synchronization task by using the code editor
If you want to configure a batch synchronization task by using the code editor, you must configure the related parameters in the script based on the unified script format requirements. For more information, see Script mode configuration. The following information describes the parameters that you must configure for data sources when you configure a batch synchronization task by using the code editor.
Reader script demo: Generic example
The following example shows a generic script for OSS Reader.
{
"type":"job",
"version":"2.0",//The version number.
"steps":[
{
"stepType":"oss",//The plug-in name.
"parameter":{
"nullFormat":"",//The string that represents a null value.
"compress":"",//The text compression type.
"datasource":"",//The data source.
"column":[//The columns.
{
"index":0,//The column index.
"type":"string"//The data type.
},
{
"index":1,
"type":"long"
},
{
"index":2,
"type":"double"
},
{
"index":3,
"type":"boolean"
},
{
"format":"yyyy-MM-dd HH:mm:ss", //The time format.
"index":4,
"type":"date"
}
],
"skipHeader":"",//CSV-like files may contain a header row. Set this parameter to skip the header.
"encoding":"",//The encoding format.
"fieldDelimiter":",",//The field delimiter.
"fileFormat": "",//The text type.
"object":[]//The object prefix.
},
"name":"Reader",
"category":"reader"
},
{
"stepType":"stream",
"parameter":{},
"name":"Writer",
"category":"writer"
}
],
"setting":{
"errorLimit":{
"record":""//The maximum number of error records allowed.
},
"speed":{
"throttle":true,//If throttle is set to false, the mbps parameter does not take effect, which means throttling is disabled. If throttle is set to true, throttling is enabled.
"concurrent":1 //The number of concurrent threads.
"mbps":"12",//The throttling rate. 1 mbps = 1 MB/s.
}
},
"order":{
"hops":[
{
"from":"Reader",
"to":"Writer"
}
]
}
}
Reader script demo: Read ORC or Parquet files from OSS
OSS Reader reads ORC or Parquet files from OSS by reusing HDFS Reader. In addition to the existing OSS Reader parameters, the following extended parameters are added: Path (ORC) and FileFormat (ORC, Parquet) .
-
The following example shows how to read ORC files from OSS.
{ "stepType": "oss", "parameter": { "datasource": "", "fileFormat": "orc", "path": "/tests/case61/orc__691b6815_9260_4037_9899_****", "column": [ { "index": 0, "type": "long" }, { "index": "1", "type": "string" }, { "index": "2", "type": "string" } ] } } -
The following example shows how to read Parquet files from OSS.
{ "type":"job", "version":"2.0", "steps":[ { "stepType":"oss", "parameter":{ "nullFormat":"", "compress":"", "fileFormat":"parquet", "path":"/*", "parquetSchema":"message m { optional BINARY registration_dttm (UTF8); optional Int64 id; optional BINARY first_name (UTF8); optional BINARY last_name (UTF8); optional BINARY email (UTF8); optional BINARY gender (UTF8); optional BINARY ip_address (UTF8); optional BINARY cc (UTF8); optional BINARY country (UTF8); optional BINARY birthdate (UTF8); optional DOUBLE salary; optional BINARY title (UTF8); optional BINARY comments (UTF8); }", "column":[ { "index":"0", "type":"string" }, { "index":"1", "type":"long" }, { "index":"2", "type":"string" }, { "index":"3", "type":"string" }, { "index":"4", "type":"string" }, { "index":"5", "type":"string" }, { "index":"6", "type":"string" }, { "index":"7", "type":"string" }, { "index":"8", "type":"string" }, { "index":"9", "type":"string" }, { "index":"10", "type":"double" }, { "index":"11", "type":"string" }, { "index":"12", "type":"string" } ], "skipHeader":"false", "encoding":"UTF-8", "fieldDelimiter":",", "fieldDelimiterOrigin":",", "datasource":"wpw_demotest_oss", "envType":0, "object":[ "wpw_demo/userdata1.parquet" ] }, "name":"Reader", "category":"reader" }, { "stepType":"odps", "parameter":{ "partition":"dt=${bizdate}", "truncate":true, "datasource":"0_odps_wpw_demotest", "envType":0, "column":[ "id" ], "emptyAsNull":false, "table":"wpw_0827" }, "name":"Writer", "category":"writer" } ], "setting":{ "errorLimit":{ "record":"" }, "locale":"zh_CN", "speed":{ "throttle":false, "concurrent":2 } }, "order":{ "hops":[ { "from":"Reader", "to":"Writer" } ] } }
Reader script demo: Read JSONLine files from OSS, parse the JSON data, and write the data to the destination
The following example shows how to read JSONLine data from OSS, parse the JSON data, vectorize specific fields in the JSON data, and then write the data to Milvus:
{
"type": "job",
"version": "2.0",
"steps": [
{
"stepType": "oss",
"parameter": {
"datasource": "${OSS data source name}",
"column": [
{
"name": "chunk_text",
"index": 0,
"type": "string"
}
],
"fieldDelimiter": ",",
"encoding": "UTF-8",
"fileFormat": "jsonl",
"object": [
"embedding/chunk1.jsonl"
]
},
"name": "Reader",
"category": "reader"
},
{
"stepType": "json-extracting",
"parameter": {
"column": [
{
"name": "text",
"fromColumn": "chunk_text",
"jsonPath": "$.text",
"type": "STRING",
"nullOrInvalidDataAction": "DIRTY_DATA"
}
]
},
"name": "jsonextract",
"category": "flatmap"
},
{
"stepType": "embedding-transformer",
"parameter": {
"modelProvider": "bailian",
"modelName": "text-embedding-v4",
"apiKey": "${the AccessKey that you want to use}",
"embeddingColumns": {
"sourceColumnNames": [
"text"
],
"embeddingColumnName": "my_vector"
},
"batchSize": 8,
"dimension": 1024
},
"name": "embedding",
"category": "flatmap"
},
{
"stepType": "milvus",
"parameter": {
"schemaCreateMode": "ignore",
"enableDynamicSchema": true,
"datasource": "${Milvus data source name}",
"column": [
{
"name": "my_vector",
"type": "FloatVector",
"dimension": "1024",
"elementType": "None",
"maxLength": "65535"
},
{
"name": "text",
"type": "VarChar",
"elementType": "None",
"maxLength": "65535"
}
],
"collection": "yunshi_vector_07171130",
"writeMode": "insert",
"batchSize": 1024,
"columnMapping": [
{
"sourceColName": "my_vector",
"dstColName": "my_vector"
},
{
"sourceColName": "text",
"dstColName": "text"
}
]
},
"name": "Writer",
"category": "writer"
}
],
"setting": {
"errorLimit": {
"record": "0"
},
"speed": {
"concurrent": 1
}
}
}
Reader script parameters
|
Parameter |
Description |
Required |
Default value |
|
datasource |
The name of the data source. Script mode supports adding data sources. The value of this parameter must be the same as the name of the added data source. |
Yes |
N/A |
|
Object |
This parameter specifies one or more objects to synchronize from OSS. Three configuration methods are supported: explicit paths, wildcard paths, and dynamic parameter paths. 1. Configuration methods
Important
2. Concurrent read mechanism and performance The configuration method directly determines the concurrency performance of data extraction:
|
Yes |
None |
|
parquetSchema |
This parameter is used when you read OSS data in Parquet file format. It takes effect only when fileFormat is set to parquet, and specifies the type definition of the Parquet storage. Make sure that the overall configuration conforms to JSON syntax after you specify parquetSchema.
The configuration format of parquetSchema is described as follows:
The following example shows a sample configuration.
|
No |
None |
|
column |
The list of fields to read. type specifies the data type of the source data, index specifies the column number (zero-based) in the text file that the current column corresponds to, and value specifies that the current column is a constant. Instead of reading data from the source file, the system automatically generates the column based on the specified value. By default, you can read all data as the STRING type. The configuration is as follows.
You can specify column field information. The configuration is as follows.
Note
For the column information you specify, the type parameter is required, and you must specify either index or value. |
Yes |
All data is read as the STRING type. |
|
fileFormat |
The file type. The file type of the source OSS objects. Valid values: csv, text, parquet, orc, json, and jsonl. Both csv and text formats support custom delimiters. |
Yes |
csv |
|
fieldDelimiter |
The field delimiter for reading data. Note
When the OSS Reader reads data, you must specify a field delimiter. If you do not specify one, a comma (,) is used by default. The comma (,) is also the default value in the console configuration. If the delimiter is invisible, enter its Unicode encoding. For example, \u001b or \u007c. |
Yes |
, |
|
lineDelimiter |
The line delimiter for reading data. Note
This parameter takes effect only when fileFormat is set to text. |
No |
N/A |
|
compress |
The compression type for text files. By default, this parameter is left empty, which indicates that the data is not compressed. Valid values: gzip, bzip2, and zip. |
No |
No compression |
|
encoding |
The encoding used to read files. |
No |
utf-8 |
|
nullFormat |
Standard strings cannot be used to define null (null pointer) in text files. Data Integration provides the nullFormat parameter to define which strings can represent null. Examples:
|
No |
None |
|
skipHeader |
CSV-like files may contain a header row with column titles that needs to be skipped. By default, the header is not skipped. skipHeader is not supported in compressed file mode. |
No |
false |
|
csvReaderConfig |
The configuration for reading CSV-like files. This parameter is of the MAP type. The CsvReader is used to read CSV-like files and supports various configurations. If this parameter is not specified, the default values are used. |
No |
None |
|
successOnNoObject |
Specifies whether the task ends as successful when no objects exist in the specified read path. If this parameter is set to false, the task fails. If this parameter is set to true, the task ends as successful without writing any data. This parameter is applicable to periodic synchronization scenarios where the source path may be empty. In codeless UI mode, this parameter corresponds to "Allow Missing Source Files" and is displayed only when fileFormat is set to csv or text. |
No |
false |
|
minLastModified |
Specifies that only files whose last modified time is equal to or later than the specified time are synchronized. The format is |
No |
N/A |
|
maxLastModified |
Synchronizes only files whose last modified time is earlier than the specified time. The format is |
No |
N/A |
Writer script demo: General example
The following is a general script example for OSS Writer.
{
"type":"job",
"version":"2.0",
"steps":[
{
"stepType":"stream",
"parameter":{},
"name":"Reader",
"category":"reader"
},
{
"stepType":"oss",// The plug-in name.
"parameter":{
"nullFormat":"",// The null format provided by Data Integration, which defines what strings can represent null.
"dateFormat":"",// The date format.
"datasource":"",// The data source.
"writeMode":"",// The write mode.
"writeSingleObject":"false", // Specifies whether to write synchronized data to a single OSS file.
"encoding":"",// The encoding format.
"fieldDelimiter":","// The field delimiter.
"fileFormat":"",// The file format.
"object":""// The object prefix.
},
"name":"Writer",
"category":"writer"
}
],
"setting":{
"errorLimit":{
"record":"0"// The maximum number of error records allowed.
},
"speed":{
"throttle":true,// If throttle is set to false, the mbps parameter does not take effect and bandwidth is not throttled. If throttle is set to true, bandwidth is throttled.
"concurrent":1, // The number of concurrent threads.
"mbps":"12"// The throttling rate. 1 mbps = 1 MB/s.
}
},
"order":{
"hops":[
{
"from":"Reader",
"to":"Writer"
}
]
}
}
Writer script demo: Writing ORC or Parquet files to OSS
OSS supports writing ORC or Parquet files by reusing HDFS Writer. In addition to the existing OSS Writer parameters, extended configuration parameters such as Path and FileFormat are added. For information about these parameters, see HDFS Writer.
The following is an example of writing ORC or Parquet files to OSS:
The following is only an example. Modify the parameters based on your actual column names and types. Do not copy and use the example directly.
-
Write ORC files to OSS
To write ORC files, only the script mode is supported. You must switch to the script mode for configuration. Set fileFormat to
orc, set path to the path of the file to write, and configure column in the format of{"name":"your column name","type": "your column type"}.The following ORC types are supported for writing:
Field type
Batch write to OSS (ORC format)
TINYINT
Supported
SMALLINT
Supported
INT
Supported
BIGINT
Supported
FLOAT
Supported
DOUBLE
Supported
TIMESTAMP
Supported
DATE
Supported
VARCHAR
Supported
STRING
Supported
CHAR
Supported
BOOLEAN
Supported
DECIMAL
Supported
BINARY
Supported
{ "stepType": "oss", "parameter": { "datasource": "", "fileFormat": "orc", "path": "/tests/case61", "fileName": "orc", "writeMode": "append", "column": [ { "name": "col1", "type": "BIGINT" }, { "name": "col2", "type": "DOUBLE" }, { "name": "col3", "type": "STRING" } ], "writeMode": "append", "fieldDelimiter": "\t", "compress": "NONE", "encoding": "UTF-8" } } -
Write to OSS in Parquet format
{ "stepType": "oss", "parameter": { "datasource": "", "fileFormat": "parquet", "path": "/tests/case61", "fileName": "test", "writeMode": "append", "fieldDelimiter": "\t", "compress": "SNAPPY", "encoding": "UTF-8", "parquetSchema": "message test { required int64 int64_col;\n required binary str_col (UTF8);\nrequired group params (MAP) {\nrepeated group key_value {\nrequired binary key (UTF8);\nrequired binary value (UTF8);\n}\n}\nrequired group params_arr (LIST) {\nrepeated group list {\nrequired binary element (UTF8);\n}\n}\nrequired group params_struct {\nrequired int64 id;\n required binary name (UTF8);\n }\nrequired group params_arr_complex (LIST) {\nrepeated group list {\nrequired group element {\n required int64 id;\n required binary name (UTF8);\n}\n}\n}\nrequired group params_complex (MAP) {\nrepeated group key_value {\nrequired binary key (UTF8);\nrequired group value {\nrequired int64 id;\n required binary name (UTF8);\n}\n}\n}\nrequired group params_struct_complex {\nrequired int64 id;\n required group detail {\nrequired int64 id;\n required binary name (UTF8);\n}\n}\n}", "dataxParquetMode": "fields" } }
Writer script parameters
|
Parameter |
Description |
Required |
Default value |
|
datasource |
The name of the data source. You can add a data source in script mode. The value of this parameter must be the same as the name of the data source that you add. |
Yes |
N/A |
|
object |
The name of the file that OSS Writer writes to. OSS uses file names to simulate a directory structure. OSS imposes the following limits on object names:
If you do not want a random UUID suffix, we recommend that you set |
Yes |
N/A |
|
ossBlockSize |
The block size for OSS multipart uploads. The default block size is 16 MB. When the file format is parquet or ORC, you can configure this parameter at the same level as the object parameter. OSS multipart uploads support a maximum of 10,000 parts. With the default block size, the maximum file size is 160 GB. If the number of parts exceeds the limit, you can increase the block size to support larger file uploads. |
No |
16 |
|
writeMode |
Specifies how OSS Writer handles existing data before writing:
|
Yes |
None |
|
writeSingleObject |
Specifies whether to write data to a single file when writing data to OSS:
Note
|
No |
false |
|
fileFormat |
The format of the output file. The following formats are supported:
|
No |
text |
|
compress |
The compression format of the data files written to OSS. You must configure this parameter in the script mode. Important
Compression is not supported for CSV and TEXT formats. Parquet and ORC files support only SNAPPY compression. |
No |
None |
|
fieldDelimiter |
The field delimiter for writing. |
No |
, |
|
encoding |
The encoding configuration for the output file. |
No |
utf-8 |
|
parquetSchema |
Required when writing to OSS in Parquet file format. This parameter describes the schema of the destination file and takes effect only when fileFormat is set to parquet. The format is as follows.
The configuration items are described as follows:
Note
Each column definition must end with a semicolon, including the last line. Example:
|
No |
None |
|
nullFormat |
Standard strings cannot be used to define null (null pointer) in text files. The data synchronization system provides nullFormat to define a string that represents null. For example, if you set |
No |
None |
|
header |
The header row when writing to OSS. Example: |
No |
None |
|
maxFileSize (advanced configuration, not supported in codeless UI) |
The maximum size of a single object file written to OSS. The default value is 10,000 × 10 MB. This is similar to controlling log file sizes when printing log4j logs. During OSS multipart upload, each part is 10 MB (which is also the minimum granularity for log rotation, meaning any maxFileSize value less than 10 MB is treated as 10 MB). Each OSS InitiateMultipartUploadRequest supports a maximum of 10,000 parts. When rotation occurs, the object name is generated by appending suffixes such as _1,_2,_3 to the original object prefix with a UUID-based random string. Note
|
No |
100,000 |
|
suffix (advanced configuration, not supported in codeless UI) |
The suffix appended to the file name generated during data synchronization write. For example, if you set suffix to .csv, the final file name is fileName****.csv. |
No |
None |
Appendix: Type conversion strategies for Parquet data
If you do not configure parquetSchema, DataWorks converts source field types to Parquet data types based on the following strategies.
|
Converted data type |
Parquet type |
Parquet logical type |
|
CHAR / VARCHAR / STRING |
BINARY |
UTF8 |
|
BOOLEAN |
BOOLEAN |
N/A |
|
BINARY / VARBINARY |
BINARY |
N/A |
|
DECIMAL |
FIXED_LEN_BYTE_ARRAY |
DECIMAL |
|
TINYINT |
INT32 |
INT_8 |
|
SMALLINT |
INT32 |
INT_16 |
|
INT/INTEGER |
INT32 |
N/A |
|
BIGINT |
INT64 |
N/A |
|
FLOAT |
FLOAT |
N/A |
|
DOUBLE |
DOUBLE |
N/A |
|
DATE |
INT32 |
DATE |
|
TIME |
INT32 |
TIME_MILLIS |
|
TIMESTAMP/DATETIME |
INT96 |
N/A |