Forward data to a Tablestore wide table model
Device metadata, such as tags, properties, and statuses, requires high-concurrency updates with low latency, multi-dimensional retrieval, geospatial retrieval, and real-time analysis. The Tablestore wide table engine is a distributed data table suited for storing and updating this metadata. This topic uses a Thing Specification Language (TSL) model data submission topic as an example to show how to forward device data to a Tablestore wide table model.
How it works
The data forwarding feature forwards device topic messages to a data table in a Tablestore instance that uses the wide table engine.
The preceding figure shows the following components:
-
Data source: For information about supported topic message types, see Data format (for products and devices that are not cloud gateways), Custom topics (for MQTT cloud gateways), Message forwarding topics (for GB/T 32960 cloud gateways), Message forwarding topics (for JT/T 808 cloud gateways), and Message forwarding topics (for SL 651 cloud gateways).
-
Data destination: A data table in the Tablestore instance that receives device data.
-
Resolver script: Configure the
writeTableStore(destinationId, data, flowType)function to forward topic data to the Tablestore data table.The
dataparameter accepts only Map data, where each key maps to a column name and each value maps to the column value. For more information about the function, see Function list.
Limits
-
Both the new and previous versions of the data forwarding feature support forwarding data to Tablestore. For an example of how to use the previous version, see Forward data to Tablestore (Previous version).
-
Only IoT Platform instances in certain regions support forwarding data to a Tablestore wide table model. For the supported regions, see Features available in different regions.
-
For the limits on forwarding device messages from an IoT Platform instance, see Limits.
Scenarios
This feature applies to IoT scenarios such as Internet of Vehicles (IoV), smart homes, and industrial IoT. For more information, see Application scenarios of IoTstore.
Prerequisites
-
A data source for the device topic is added. For example, you can create a data source named DataSource and add a TSL model data submission topic for a specific device. For more information, see Add a data source.
-
You have created a Tablestore instance and a data table. For more information, see the Tablestore documentation.
ImportantIf you use an Enterprise Edition instance of IoT Platform, the Tablestore instance must be in the same region as your IoT Platform instance.
Background information
The Tablestore wide table model is similar to the Bigtable or HBase model and suits metadata and big data scenarios. It supports data versions, lifecycle management, auto-increment primary key columns, conditional updates, local transactions, atomic counters, and filters. For more information, see Wide table model.
For more information about how to forward device-reported data from IoT Platform to Tablestore, see IoTstore.
Create a data destination
-
Log on to the IoT Platform console.
-
On the Instance Overview tab, find the instance that you want to manage under All Environments and click the instance card.
-
In the left-side navigation pane, choose .
-
On the Data Forwarding page, click Go to New Version in the upper-right corner.
NoteIf you have performed this operation before, you are automatically redirected to the new version of the Data Forwarding page.
-
Click the Data destination tab, and then click Create data destination.
-
In the Create Data Destination dialog box, enter a name for the data destination, such as DataPurpose. Configure the parameters as described in the following table and click OK.
NoteOnly data in the JSON format can be forwarded.

Parameter
Description
Select Operation
Select Store Data to Tablestore.
Region
Select the region where your Tablestore instance is located.
Instance
Select a Tablestore instance.
You can click Create Instance to go to the Tablestore console and create an instance. For more information, see the Tablestore documentation.
Storage Class
Select Wide table model.
Data Table
Select the Tablestore data table to receive the data.
You can click Create Data Table to go to the Tablestore console and create a data table.
Role
Select a RAM role that grants IoT Platform permissions to write data to Tablestore.
If no RAM role exists, click Create RAM Role to create a RAM role and authorization policy in the RAM console. Create a RAM role.
Configure and start a parser
Create a parser, such as DataParser. For more information, see Step 1: Create a parser.
On the Resolver Details page, associate the data source.
In the configuration wizard, under Data Source, click Associate Data Source.
In the dialog box, select DataSource from the Data Source drop-down list and click OK.
On the Resolver Details page, you can associate data destinations.
In the configuration wizard, click Data Destination. Then, in the upper-right corner of the Data Destination list, click Associate Data Destination.
In the dialog box that appears, from the Data Destination drop-down list, select DataPurpose and click OK.
In the data destination list, find the Data Destination ID and record it. For example, 1000.
You will need this Data Destination ID in the parsing script.
-
On the parser details page, click the Parser Script tab.
-
In the script editor, enter a parser script.
The parser script uses a JavaScript-like syntax. For more information, see Script syntax.
For more information about function parameters, see Function list.
// Use the payload() function to obtain the message that is reported by the device and convert the message to the JSON format. var data = payload("json"); // Obtain the values of the reported properties. var h = data.items.Humidity.value; var t = data.items.Temperature.value; // Add the primary keys deviceName and id to the table. In the writeTableStore method, you can write the temperature and humidity values to the corresponding columns in the column:value format. writeTableStore(1000, {"deviceName":deviceName(), "id":timestamp(), "temperature":t, "humidity":h}); -
Click Test. Select a product and a device, and then enter the topic and payload data as prompted to test the script.
The following figure shows sample parameters:

The following output indicates that the script ran successfully.

-
Click Publish.
Return to the Resolver tab on the Data Forwarding page and click Start for the DataParser resolver.
What to do next
-
In the IoT Platform console, click the destination Enterprise instance to view the device status and message forwarding logs. For more information, see IoT Platform logs.
-
After the data is pushed, go to the Data Management tab of the receiving data table in Tablestore to verify that the data is received.

Operation example
References
-
For information about how to connect a device to IoT Platform and report data, see Device connection guide.
-
On the instance details page, check the available message forwarding transactions per second (TPS) to ensure that device messages can be forwarded to Tablestore. For more information, see View instance information and runtime data. If the available resources are insufficient, upgrade the instance. For more information, see Upgrade an instance.
-
For the limits and FAQ of Tablestore, see General FAQ about Tablestore.