cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Data Storage in ThingWorx

spatel-21
1-Newbie

Data Storage in ThingWorx

Data storage in ThingWorx can take place three (3) manners :

  1. Data Tables
  2. Streams
  3. Value Streams

Before beginning with above three topics one must also understand concept of :

  1. InfoTable
  2. DataShape


What is InfoTable ?


An InfoTable is zero indexed, ordered array of javaScript objects which expose  same properties. Since an InfoTable is an Array of Objects, it can also be thought of as a table where the array entries are rows and the object properties of each object in the array are the columns.


For example :

var people = [

      {

           “name” : “Ravi”,

           “city” : “Mumbai”

      },

      {

           “name” : “Mohit”,
           “city” : “New Delhi”

      }

];


As you can see InfoTables only contains the same type of object.This is achieved using another ThingWorx specific mechanism called Data Shape


What is Data Shape ?

A DataShape is a specification of the required property names and return types each property of a JavaScript “Object” must have to be added to an InfoTable.

DataShapes also contain other metadata about a property that is useful for formatting and displaying the InfoTable in a tabular format or Grid.

They are essentially a schema mechanism for defining the required fields of a Thing in ThingWorx.


datashape.jpg

Now that we have covered InfoTables and DataShapes, let us move towards core concepts of data storage

1. Data Tables

A ThingWorx Data Table Thing is similar to a standard relational database table. However, a Data Shape defines the columns of a Data Table. Data Tables can be used to store data in a ThingWorx application.


configureKeys.jpg


The Configuration tab for a Data Table allows you to define additional table indexes. This is similar to a relational database table, where in addition to the primary key (the primary key is defined in the Data Shape), you need to query the table based on other fields. You should create an index for each set of filter criteria commonly used. This will have a significant impact on query performance.


2. Streams

Streams represent time series data. Therefore, each Stream has a timestamp plus additional fields. A ThingWorx Stream is a list of activities from Things or data associated with Things.

A stream can be thought of as a table structure with certain predefined fields and any number of user-defined fields. User-defined fields are defined using DataShape.


3. Value Streams

ThingWorx Value Streams also provide time series information about a Thing’s property values.

Value streams are similar to streams in terms of their end results however there is some noteworthy difference between Stream and Value Stream in manner in which data gets written and returned.

Streams are independent data stores and can access data continuously:

- Querying single column value returns entire row

- Remain most beneficial for non-Thing-driven models

- Scipts are required to write data to Streams


For example : You can set up a timer and subscribe to the timer event and every time timer emits the event we can log data in stream.

Value Streams store data from associated Thing’s property :

- Querying Thing’s property data only returns values for that property

- Scripts not required to write Thing property data to its Value Stream

- Most useful for Thing-driven models


assigning_valuestram.png


logging_property.png


Note : Data gets stored in the configured persistence provider.

3 REPLIES 3

Good Work Siddarath.

Could we add some information to this article? That would be that Infotables are by default in-memory objects, that don't resist a server restart if they are not persisted, and all the other options (DataTable, Stream and ValueStream) are objects which store the data on disk.

By not storing the data in-memory if you make a query on a DataTable / Stream / VS this will access the disk, while this won't happen for an Infotable.

This information should be considered in the initial stages when you are doing application development.

jebeck
6-Contributor
(To:spatel-21)

Great write up Siddarath.

There is also a great guide on the Developer Portal called "Data Storage Guide" that I've found helpful.

Top Tags