DataWorks provides Azure Blob Storage Reader and Azure Blob Storage Writer for you to read data from and write data to files that are stored in Azure Blob Storage. You can use Azure Blob Storage Reader to access files stored in Azure Blob Storage, parse the data in the files, and then synchronize the data to a destination. You can also use Azure Blob Storage Writer to write data from any source to Azure Blob Storage. This topic describes the capabilities of synchronizing data from and to Azure Blob Storage data sources.
Limitations
The Azure Blob Storage data source supports the following data types.
|
Data type |
Description |
|
STRING |
Text. |
|
LONG |
Integer. |
|
BYTES |
Byte array. The text that is read is converted into a byte array. The encoding format is UTF-8. |
|
BOOL |
Boolean. |
|
DOUBLE |
Floating point. |
|
DATE |
Date and time. The following date and time formats are supported:
|
Add 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.
Develop a data synchronization task
For information about the entry point for and the procedure of configuring a synchronization task, see the following configuration guides.
Configure a batch synchronization task to synchronize data of a single table
-
For the procedure, see Configure a synchronization task in the codeless UI and Configure a synchronization task by using the code editor.
-
For the complete parameters and script demo for the code editor, see Appendix: Script demo and parameter description below.
Appendix: Script demo 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
The following is a code editor configuration example for reading data from Azure Blob Storage. The writer side uses stream as a placeholder. Replace it with the configuration of the actual destination data source.
{
"type": "job",
"version": "2.0",
"steps": [
{
"stepType": "azureblob",
"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 value |
|
datasource |
The data source name. The code editor allows you to add data sources. The value of this parameter must be the same as the name of the data source that you add. |
Yes |
N/A |
|
fileFormat |
The type of the source file. Valid values: |
Yes |
N/A |
|
object |
The file path. This parameter is used when fileFormat is set to csv, text, json, or jsonl. Note
This parameter supports the For example, to synchronize the |
Yes Required when fileFormat is set to csv, text, json, or jsonl. |
None |
|
path |
The file path. This parameter is used when fileFormat is set to parquet or orc. Note
This parameter supports the For example, to synchronize the |
Yes Required when fileFormat is set to parquet or orc. |
None |
|
column |
The list of fields to read. The type parameter specifies the data type of the source data:
By default, you can read all data as the STRING type. Example configuration:
You can specify column field information. Example configuration:
Note
For the column information that you specify, the type field is required. For the CSV/TEXT format, specify either index or value. For the JSON/JSONL format, specify either jsonPath or value. |
Yes |
All data is read as the STRING type. |
|
fieldDelimiter |
The field delimiter used to read data. Note
|
Yes |
, |
|
lineDelimiter |
The line delimiter used to read 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 no compression is applied. Supported compression types are |
No |
No compression |
|
encoding |
The encoding configuration for reading files. |
No |
utf-8 |
|
nullFormat |
Standard strings cannot be used to define null (null pointer) in text files. The data synchronization system provides nullFormat to define which strings can represent null. Examples:
|
No |
N/A |
|
skipHeader |
For CSV files, use skipHeader to specify whether to read the header.
Note
skipHeader is not supported in compressed file mode. |
No |
false |
|
parquetSchema |
This parameter is configured when you read data from Azure Blob Storage in Parquet file format. It takes effect only when fileFormat is set to parquet and specifies the type description 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 the configuration.
|
No |
N/A |
|
csvReaderConfig |
The parameter configuration for reading CSV files. The value is of the Map type. CsvReader is used to read CSV files. If this parameter is not configured, the default values are used. |
No |
N/A |
|
maxRetryTimes |
The maximum number of retries when a file fails to be downloaded. Note
|
No |
0 |
|
retryIntervalSeconds |
The retry interval when a file fails to be downloaded. Unit: seconds. Note
This parameter can be configured only in code editor mode. It is not supported in the codeless UI. |
No |
5 |
Writer script demo
The following example shows a script mode configuration for writing data to Azure Blob Storage. The reader side uses stream as a placeholder. Replace it with the actual source data source configuration.
{
"type": "job",
"version": "2.0",
"steps": [
{
"stepType": "stream",
"parameter": {},
"name": "Reader",
"category": "reader"
},
{
"stepType": "azureblob",
"parameter": {
"datasource": "",
"fileFormat": "csv",
"object": "dir/example.csv",
"fieldDelimiter": ",",
"lineDelimiter": "\n",
"encoding": "UTF-8",
"nullFormat": "null",
"dateFormat": "yyyy-MM-dd",
"writeMode": "truncate",
"maxFileSize": 100,
"writeSingleObject": false
},
"name": "Writer",
"category": "writer"
}
],
"setting": {
"errorLimit": {
"record": "0"
},
"speed": {
"concurrent": 1
}
},
"order": {
"hops": [
{
"from": "Reader",
"to": "Writer"
}
]
}
}
Writer script parameters
|
Parameter |
Description |
Required |
Default value |
|
datasource |
The data source name. Script mode allows you to add data sources. The value of this parameter must be the same as the name of the data source that you add. The data source must be configured with the SAS URL and signature (sig) of the Azure Blob Storage container. |
Yes |
N/A |
|
object |
The name of the file to which Azure Blob Storage Writer writes data, including the path prefix. Directories are simulated by using file names, and the delimiter is a forward slash (/).
|
Yes |
N/A |
|
writeMode |
Specifies how Azure Blob Storage Writer processes existing data before writing:
|
Yes |
None |
|
writeSingleObject |
Specifies whether to write data to a single file:
Note
This parameter does not take effect when you write data in Parquet or ORC format. |
No |
false |
|
fileFormat |
The format in which files are written. Valid values:
|
No |
text |
|
fieldDelimiter |
The field delimiter used for writing. This parameter is valid for the csv and text formats. If you do not specify this parameter, the default delimiter comma (,) is used. If the delimiter is invisible, enter the Unicode encoding, such as |
No |
, |
|
encoding |
The encoding of the output file. |
No |
utf-8 |
|
nullFormat |
Null (empty pointer) cannot be defined by using standard strings in text files. The data synchronization system provides the nullFormat parameter to define which strings can be treated as null. For example, if you configure |
No |
\N |
|
dateFormat |
The format used to format date-type data. |
No |
|
|
header |
The header of the output file. Example: |
No |
N/A |
|
blockSizeInMB |
The size of each block in MB when Block Blob data is uploaded in blocks. Azure Block Blob supports a maximum of 50,000 blocks, and the size of each block ranges from 4 MB to 100 MB. If the number of blocks exceeds the limit, you can increase the block size to support larger file uploads. Note * This parameter is supported only in advanced mode, not in codeless UI mode. * This parameter takes effect only for the text, csv, and jsonl formats. |
No |
64 |
|
parquetSchema |
This parameter is required when data is written in Parquet file format. It describes the structure of the destination file and takes effect only when fileFormat is set to parquet. The format is as follows. The configuration format of parquetSchema is described as follows:
The following example shows a sample configuration.
|
No |
N/A |
|
column |
The destination column information configured when writing data in Parquet or ORC format. Format: |
No |
N/A |
|
compress |
The compression format for writing Parquet or ORC files, such as |
No |
N/A |
|
maxRetryTimes |
The maximum number of retries upon write failures, including uploading blocks, committing block lists, and deleting objects. Set this parameter to 0 to disable retries. Note This parameter is available only in script mode and cannot be configured in codeless UI mode. |
No |
30 |
|
retryIntervalSeconds |
The interval between retries upon write failures. Unit: seconds. This parameter is available only in script mode and cannot be configured in codeless UI mode. |
No |
5 |
|
requestTimeoutSeconds |
The timeout period for a single request. Unit: seconds. This parameter is available only in script mode and cannot be configured in codeless UI mode. |
No |
60 |