Skip to content

TQL

Reading and transforming data sent by sensors into the format you want, or delivering values stored in the database to other systems in the format they require, calls for a dedicated tool. TQL is the Machbase transformation language that lets you process such data easily and flexibly.

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 to transform data easily. This chapter shows how to process data into various formats without developing additional applications.

Iris Demo

The Iris data examples below give a brief idea of what TQL is used for.

  • Average values of each class
 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