Skip to content

TQL

It is required to properly read and transform data that has been sent by sensors. And also read and send data from database to other systems in demanded format.

Generate example ‘signal’ data

First, generate sample data for the examples below.

SCRIPT({
    const m = require('mathx');
    const gen = m.oscillator({
        components: [
            {frequencyHz: 15, amplitude: 1.0},
            {frequencyHz: 24, amplitude: 1.5},
        ],
        timeRange: {from: 'now', to: 'now+10s'},
        sample: "1000Hz",
    });
    gen.forEach((g)=>{ $.yield(g[0], g[1]) });
})
SQL(`insert into example(name,time,value) values('signal',?,?)`, 
    value(0), value(1))

Output format independent

1
2
SQL( `SELECT TIME, VALUE FROM EXAMPLE WHERE NAME='signal' LIMIT 100` )
CSV( timeformat("Default") )

Data source independent

1
2
3
4
5
6
7
8
9
FAKE( json({ 
    [ "A", 1.0 ],
    [ "B", 1.5 ],
    [ "C", 2.0 ],
    [ "D", 2.5 ] }))

MAPVALUE(1, value(1) * 10 )

CSV()

The purpose of TQL is transforming data format. This chapter shows how to do this without developing additional applications.

Iris Demo

The example tql code below gives a brief idea of what is TQL for.

  • avg. values of each classes.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
CSV(file("https://docs.machbase.com/assets/example/iris.csv"))
GROUP( by(value(4), "species"),
    avg(value(0), "Avg. Sepal L."),
    avg(value(1), "Avg. Sepal W."),
    avg(value(2), "Avg. Petal L."),
    avg(value(3), "Avg. Petal W.")
)
CHART(
    chartOption({
        "xAxis":{"type": "category", "data": column(0)},
        "yAxis": {},
        "legend": {"show": true},
        "series": [
            { "type": "bar", "name": "Avg. Sepal L.", "data": column(1)},
            { "type": "bar", "name": "Avg. Sepal W.", "data": column(2)},
            { "type": "bar", "name": "Avg. Petal L.", "data": column(3)},
            { "type": "bar", "name": "Avg. Petal W.", "data": column(4)}
        ]
    })
)

In this chapter

Last updated on