SINK Functions
All tql scripts must end with one of the sink functions.
The basic SINK function might be INSERT()
which write the incoming records onto machbase-neo database. CHART_XXX()
familiy functions render charts with incoming records. JSON()
and CSV()
encode incoming data into proper formats.
INSERT()
Syntax: INSERT( [bridge(),] columns..., table(), tag() )
INSERT()
stores incoming records into specified databse table by an ‘INSERT’ statement for each record.
bridge()
bridge(’name’)columns
stringtable()
table(’name’)tag()
tag(’name’)
Example)
- Insert records into machbase
INSERT("time", "value", table("example"), tag('temperature'))
- Insert records into bridged database
INSERT(bridge("sqlite"), "company", "employee", "created_on", table("example"))
APPEND()
Syntax: APPEND( table() )
APPEND() stores incoming records into specified databse table via the ‘append’ method of machbase-neo.
table()
table(string) specify destination table
CSV()
Syntax: CSV( [tz(), timeformat(), precision(), rownum(), heading(), delimiter(), substituteNull() ] )
Makes the records of the result in CSV format. The values of the records become the fields of the CSV lines.
For example, if a record was {key: k, value:[v1,v2]}
, it generates an CSV records as v1,v2
.
tz
tz(name) time zone, default istz('UTC')
timeformat
timeformat(string) specify the format how represents datetime fields, default istimeformat('ns')
rownum
rownum(boolean) adds rownum columnprecision
precision(int) specify precision of float fields,precision(-1)
means no restriction,precision(0)
converts to integerheading
heading(boolean) add fields names as the first rowdelimiter
delimiter(string) specify fields separator other than the default comma(,
).substituteNull
substitute(string) specify sustitution string for the NULL value, default issubstituteNull('NULL')
JSON( )
Syntax: JSON( [transpose(), tz(), timeformat(), precision(), rownum() ] )
Generates JSON results from the values of the records.
transpose
transpose(boolean) transpose rows and columns, it is useful that specifyingtranspose(true)
for the most of chart libraries.tz
tz(name) time zone, default istz('UTC')
timeformat
timeformat(string) specify the format how represents datetime fields, default istimeformat('ns')
rownum
*rownum(boolean)` adds rownum columnprecision
precision(int) specify precision of float fields,precision(-1)
means no restriction,precision(0)
converts to integer
MARKDOWN()
Generates a table in markdown format or HTML.
Syntax: MARKDOWN( [html(), rownum(), brief(), briefCount() ] )
html(boolean)
produce result by HTML renderer, defaultfalse
rownum(boolean)
show rownum columnbrief(boolean)
omit result rows,brief(true)
is equivalent withbriefCount(5)
briefCount(limit int)
omit result rows if the records exceeds the given limit, no omition if limit is0
If briefCount()
is applied…
DISCARD()
Syntax: DISCARD()
Since v8.0.7
DISCARD()
silently ignore all records as its name implies, so that no output generates.
CHART_LINE()
Syntax: CHART_LINE()
Generates a line chart in HTML format.
FAKE( oscillator(freq(1.5, 1.0), freq(1.0, 0.7), range('now', '3s', '10ms')))
CHART_LINE()
CHART_BAR()
Syntax: CHART_BAR()
Generates a bar chart in HTML format.
FAKE( oscillator(freq(1.5, 1.0), freq(1.0, 0.7), range('now', '1s', '10ms')))
CHART_BAR()
CHART_SCATTER()
Syntax: CHART_SCATTER()
Generates a scatter chart in HTML format.
FAKE( oscillator(freq(1.5, 1.0), freq(1.0, 0.7), range('now', '1s', '10ms')))
CHART_SCATTER()
CHART_LINE3D
Syntax: CHART_LINE3D()
Generates a 3D line chart in HTML format.
CHART_BAR3D()
Syntax: CHART_BAR3D()
Generates a 3D bar chart in HTML format.
CHART_SCATTER3D()
Syntax: CHART_SCATTER3D()
Generates a 3D scatter chart in HTML format.
Chart options
size()
Syntax: size(width, height)
width
string chart width in HTML syntax ex) ‘800px’height
string chart height in HTML syntax ex) ‘800px’
title()
Syntax: title(label)
label
string
subtitle()
Syntax: subtitle(label)
label
string
xAxis(), yAxis(), zAxis()
Syntax: xAxis(idx, label [, type])
idx
number index of column for the axislabel
string label of the axistype
string type fo the axis, available:'time'
and'value'
, default is'value'
if not specified.
zAxis() is effective only with 3D chart
dataZoom()
Syntax: dataZoom(type, minPercentage, maxPercentage)
type
string “slider”, “inside”minPercentage
number 0 ~ 100maxPercentage
number 0 ~ 100
2D chart only
opacity()
Syntax: opacity(alpha)
alpha
number 0.0 ~ 1.0
3D chart only
autoRotate()
Syntax: autoRotate( [speed] )
speed
number degree/sec, default is 10
gridSize()
Syntax: gridSize( width, height, [depth] )
width
number percentage (default: 100)height
number percentage (default: 100)depth
number percentage (default: 100)
toolbox
toolboxSaveAsImage()
Syntax: toolboxSaveAsImage(filename)
Since v8.0.4
filename
string filename with extension supporting (.png, .jpeg, .svg).
Show the toolbox button to save chart as an image file.
toolboxDataZoom()
Syntax: toolboxDataZoom()
Since v8.0.4
Show the toolbox button for data zoom.
toolboxDataView()
Syntax: toolboxDataView()
Since v8.0.4
Show the toolbox button for raw data viewer.
FAKE( oscillator(freq(1.5, 1.0), freq(1.0, 0.7), range('now', '3s', '10ms')) )
CHART_LINE(
size('400px', '300px'),
toolboxSaveAsImage('image.png'),
toolboxDataZoom(),
toolboxDataView()
)
visualMap()
Syntax: visualMap(min, max)
min
numbermax
number
It calls visualMapColor()
internally with pre-defined default colors.
visualMapColor()
Syntax: visualMapColor(min, max, colors...)
Since v8.0.4
min
numbermax
numbercolors
colors in array of string
Example)
FAKE( oscillator(freq(1.5, 1.0), freq(1.0, 0.7), range('now', '3s', '10ms')) )
CHART_LINE(
size('400px', '300px'),
visualMapColor(-2.0, 2.0,
"#a50026", "#d73027", "#f46d43", "#fdae61", "#e0f3f8", "#abd9e9", "#74add1", "#4575b4", "#313695",
"#313695", "#4575b4", "#74add1", "#abd9e9", "#e0f3f8", "#fdae61", "#f46d43", "#d73027", "#a50026"
)
)
markArea()
Syntax: markArea(coord0, coord1 [, label [, color [, opacity]]])
coord0
any : area begining x-valuecoord1
any : area ending x-valuelabel
string : titlecolor
string : color of areaopacity
number : 0~1 of opacity
Example)
FAKE( oscillator(freq(1.5, 1.0), range('now', '3s', '10ms')) )
CHART_SCATTER(
markArea(time('now+1s'), time('now+2s'), 'Error', '#ff000033'),
markArea(time('now+1.5s'), time('now+2.5s'), 'Marked', '#22ff0022')
)
markXAxis()
Syntax: markXAxis(coord, label)
coord
any : marked x-valuelabel
string : title
FAKE( oscillator(freq(1.5, 1.0), range('now', '3s', '10ms')) )
CHART_SCATTER( markXAxis(time('now+1.5s'), 'NOW') )
markYAxis()
Syntax: markYAxis(coord, label)
coord
any : marked y-valuelabel
string : title
FAKE( oscillator(freq(1.5, 1.0), range('now', '3s', '10ms')) )
CHART_SCATTER( markYAxis(1.0, 'max'), markYAxis(-1.0, 'min') )
theme()
Syntax: theme(name)
name
string theme name
Apply a chart theme.
Available themes : chalk
, essos
, infographic
, macarons
, purple-passion
, roma
, romantic
, shine
, vintage
, walden
, westeros
, wonderland