All Products
Document Center

Tablestore:Create delivery tasks

Last Updated:May 19, 2022

You can call the CreateDeliveryTask operation to create a delivery task. You can create a delivery task to deliver data from Tablestore to an OSS bucket.


Make sure that Tablestore SDK for Java is installed to support delivery service. For more information about Tablestore SDK for Java, see Tablestore SDK for Java.


  • OSS is activated. A bucket is created in the region where a Tablestore instance is deployed. For more information, see Activate OSS.

  • The Tablestore service linked role (AliyunServiceRoleForOTSDataDelivery) is created in the console. The Alibaba Cloud Resource Name (ARN) of the role is recorded. For more information, see the "Create delivery tasks" section of the Quick start topic.

    You can obtain the ARN of the Tablestore service linked role (AliyunServiceRoleForOTSDataDelivery) in the RAM console. Perform the following operations:

    On the RAM Roles page, search AliyunServiceRoleForOTSDataDelivery, and then click the RAM role name. On the role details page, you can view and copy the ARN information of the role.

  • The OTSClient instance is initialized. For more information, see Initialization.

  • A table is created. Data is written to the table.





The name of the table.


The name of the delivery task.

The name must be 3 to 16 characters in length and can contain only lowercase letters, digits, and hyphens (-). It must start and end with a lowercase letter or digit.


The configurations of the delivery task. Valid values:

  • ossPrefix: the prefix of the folder in the bucket. Data is delivered from Tablestore to the folder. The path of the destination folder supports the following time variables: $yyyy, $MM, $dd, $HH, and $mm.

    • When the path uses time variables for delivery, OSS folders are dynamically generated based on the time when data is written. This way, data is partitioned based on the naming conventions that are followed when Hive partitions data. Objects in OSS are organized, partitioned, and distributed based on time.

    • When the path does not use time variables, all files are delivered to an OSS folder whose name contains a specific prefix.

  • ossBucket: the name of the OSS bucket.

  • ossEndpoint: the endpoint of the region where an OSS bucket is located.

  • ossStsRole: the Alibaba Cloud Resource Name (ARN) of the Tablestore service-linked role.

  • format: the format of the delivered data. The delivered data is stored in the Parquet format. By default, data delivery uses PLAIN to encode data of any type.

  • eventTimeColumn: the event time column. This parameter specifies that data is partitioned based on the time of data in a column. If you do not specify this parameter, data is partitioned based on the time when the data is written to Tablestore.

  • parquetSchema: specifies the column you want to deliver. You must configure the source fields, destination fields, and destination field types to deliver.

    The order in which fields are sorted in Tablestore can be different from the order of fields in the schema. Parquet data stored in OSS is distributed based on the order of fields in the schema.


    The data types must be consistent between the source and destination fields. If the data types between the fields are inconsistent, the fields are discarded as dirty data. For more information about field type mappings, see the "Data type mappings" section of the Quick start topic.


The mode in which to deliver data. Default value: BASE_INC. Valid values:

  • INC: the incremental data delivery mode. Only incremental data is synchronized.

  • BASE: the full data delivery mode. All data in tables is scanned and synchronized.

  • BASE_INC: the differential data delivery mode. After the full data is synchronized, Tablestore synchronizes the incremental data.

    When you synchronize data in incremental mode, you can view the time when data is last delivered and the status of the current delivery task.


private static void createDeliveryTask(SyncClient client) {
    String tableName = "sampleTable";
    String taskName = "sampledeliverytask";
    OSSTaskConfig taskConfig = new OSSTaskConfig();
    taskConfig.setOssStsRole("acs:ram::17 %%%)%%%%*****: role/aliyunserviceroleforotsdatadelivery"); // eventColumn is optional. eventColumn specifies that data is partitioned based on the time of a column. If you do not specify this parameter, data is partitioned based on the time when the data is written to Tablestore.
    EventColumn eventColumn = new EventColumn("PK1", EventTimeFormat.RFC1123);
    taskConfig.addParquetSchema(new ParquetSchema("PK1", "PK1", DataType.UTF8));
    taskConfig.addParquetSchema(new ParquetSchema("PK2", "PK2", DataType.BOOL));
    taskConfig.addParquetSchema(new ParquetSchema("Col1", "Col1", DataType.UTF8));
    CreateDeliveryTaskRequest request = new CreateDeliveryTaskRequest();
    CreateDeliveryTaskResponse response = client.createDeliveryTask(request);
    System.out.println("resquestID: "+ response.getRequestId());
    System.out.println("traceID: " + response.getTraceId());
    System.out.println("create delivery task success");