Skip to content
Web

Datamodels

Inserting From Datamodels

In this example, we will show how to insert data from one datasource to another by using the Datamodel. Here the Country table exists in a datasource called WORLD. We want to take this table and create a copy of it in AMI datasource. To create a copy of the Country table, we need the schema which we get using the DESCRIBE clause.

1
2
3
4
5
6
7
8
9
{
  CREATE TABLE Country AS USE  EXECUTE SELECT * FROM `Country` WHERE ${WHERE};
  string s = SELECT SQL from DESCRIBE TABLE Country;
  s = strReplace(s, "CREATE TABLE", "CREATE PUBLIC TABLE IF NOT EXISTS");
  // session.log(s);
  USE ds="AMI" LIMIT = -1 EXECUTE ${s};
  // USE ds="AMI" EXECUTE DELETE FROM Country;
  USE ds="AMI" INSERT INTO Country FROM SELECT * FROM Country;
}

Firstly, create a Datamodel that is attached to the WORLD Datasource. Copy and paste the above script and run.

This will now give you the Country table in the AMI datasource.

Realtime Datamodels

We can have our data model subscribe to a real time feed to make it a real time data model.
Let's say we have a real time feed transaction(TransactionID Long,sym String,price Double)

  1. create a data model called realtimeDM and subscribe to real time feed transaction

  2. You could also configure queries to construct derived tables

    In this example, we created another table showing the top3 symbol with the most total price.

    Additionally, you could also configure the conflate time parameter to control how frequently you want your data model to rerun and refresh.

    In this example, it is set to 10 seconds, which means the data model will rerun 10 seconds per time.

  3. Create real time visualization panel off of the real time data model that we just created

    In this example, we created a real time heatmap off of the top3sym table.

  4. Final Heatmap

Note that you can press space on the heatmap to zoom in/out.