SINK
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()
function can render various 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 database table by an ‘INSERT’ statement for each record.
bridge()
bridge(’name’) optional.columns
string column list.table()
table(’name’) specify the destination table name.tag()
tag(’name’) optional, applicable only to tag tables.
Write records to machbase that contains tag name.
|
|
Write records to machbase with same tag name by adding “name” field by PUSHVALUE()
.
|
|
Write records to machbase with same tag name by using tag()
option if the destination is a tag table.
|
|
Insert records into bridged database.
|
|
APPEND()
Syntax: APPEND( table() )
APPEND() stores incoming records into specified database table via the ‘append’ method of machbase-neo.
table()
table(string) specify destination table
|
|
CSV()
Syntax: CSV( [tz(), timeformat(), precision(), rownum(), heading(), delimiter(), nullValue() ] )
Makes the records of the result in CSV format. The values of the records become the fields of the CSV lines.
The end of the data is identified by the last two consecutive newline characters (\n\n
).
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(,
).nullValue()
specify substitution string for the NULL value, default isnullValue('NULL')
. Since v8.0.14substituteNull
substitute(string) specify substitution string for the NULL value, default issubstituteNull('NULL')
. (deprecated, replaced bynullValue()
)
|
|
1,10
2,20
3,30
|
|
x,x10
1,10
2,20
3,30
|
|
x|x10
1|10
2|20
3|30
|
|
A|123
B|***
C|234
JSON()
Syntax: JSON( [transpose(), tz(), timeformat(), precision(), rownum(), rowsFlatten(), rowsArray() ] )
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 column.precision
precision(int) specify precision of float fields,precision(-1)
means no restriction,precision(0)
converts to integer.rowsFlatten
rowsFlatten(boolean) reduces the array dimension of the rows field in the JSON object. IfJSON()
hastranspose(true)
androwsFlatten(true)
together, it ignoresrowsFlatten(true)
and onlytranspose(true)
affects on the result. Since v8.0.12rowsArray
rowsArray(boolean) produces JSON that contains only array of object for each record. TherowsArray(true)
has higher priority thantranspose(true)
androwsFlatten(true)
. Since v8.0.12
|
|
{
"data": {
"columns": [ "x" ],
"types": [ "double" ],
"rows": [ [ 1, 10 ], [ 2, 20 ], [ 3, 30 ] ]
},
"success": true,
"reason": "success",
"elapse": "228.541µs"
}
|
|
{
"data": {
"columns": [ "x", "x10" ],
"types": [ "double", "double" ],
"cols": [ [ 1, 2, 3 ], [ 20, 30, 40 ] ]
},
"success": true,
"reason": "success",
"elapse": "121.375µs"
}
|
|
{
"data": {
"columns": [ "x", "x10" ],
"types": [ "double", "double" ],
"rows": [ 1, 10, 2, 20, 3, 30 ]
},
"success": true,
"reason": "success",
"elapse": "130.916µs"
}
|
|
{
"data": {
"columns": [ "x", "x10" ],
"types": [ "double", "double" ],
"rows": [ { "x": 1, "x10": 10 }, { "x": 2, "x10": 20 }, { "x": 3, "x10": 30 } ]
},
"success": true,
"reason": "success",
"elapse": "549.833µs"
}
NDJSON()
Syntax: NDJSON( [tz(), timeformat(), rownum()] )
Since v8.0.33
Generates NDJSON results from the values of the records.
NDJSON (Newline Delimited JSON) is a format for streaming JSON data where each line is a valid JSON object. This is useful for processing large datasets or streaming data because it allows you to handle one JSON object at a time.
The end of the data is identified by the last two consecutive newline characters (\n\n
).
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 column.
|
|
{"NAME":"neo_load1","ROWNUM":1,"TIME":"2024-09-06 14:46:19.852","VALUE":4.58}
{"NAME":"neo_load1","ROWNUM":2,"TIME":"2024-09-06 14:46:22.853","VALUE":4.69}
{"NAME":"neo_load1","ROWNUM":3,"TIME":"2024-09-06 14:46:25.852","VALUE":4.69}
MARKDOWN()
Generates a table in markdown format or HTML.
Syntax: MARKDOWN( [ options... ] )
tz(string)
time zone, default istz('UTC')
timeformat(string)
specify the format how represents datetime fields, default istimeformat('ns')
html(boolean)
produce result by HTML renderer, defaultfalse
rownum(boolean)
show rownum columnprecision
precision(int) specify precision of float fields,precision(-1)
means no restriction,precision(0)
converts to integer.brief(boolean)
omit result rows,brief(true)
is equivalent withbriefCount(5)
briefCount(limit int)
omit result rows if the records exceeds the given limit, no omission if limit is0
FAKE( csv(`
10,The first line
20,2nd line
30,Third line
40,4th line
50,The last is 5th
`))
MARKDOWN()
|column0 | column1 |
|:-------|:---------|
| 10 | The first line |
| 20 | 2nd line |
| 30 | Third line |
| 40 | 4th line |
| 50 | The last is 5th |
FAKE( csv(`
10,The first line
20,2nd line
30,Third line
40,4th line
50,The last is 5th
`))
MARKDOWN( briefCount(2) )
|column0 | column1 |
|:-------|:---------|
| 10 | The first line |
| 20 | 2nd line |
| ... | ... |
> Total 5 records
FAKE( csv(`
10,The first line
20,2nd line
30,Third line
40,4th line
50,The last is 5th
`))
MARKDOWN( briefCount(2), html(true) )
column0 | column1 |
---|---|
10 | The first line |
20 | 2nd line |
… | … |
Total 5 records
DISCARD()
Syntax: DISCARD()
Since v8.0.7
DISCARD()
silently ignore all records as its name implies, so that no output generates.
|
|
CHART()
Syntax: CHART()
Since v8.0.8
Generates chart using Apache echarts.
Refer to CHART() examples for the various usages.
Deprecated
CHART_LINE()
DEPRECATED: use CHART() instead.
Syntax: CHART_LINE()
Generates a line chart in HTML format.
|
|
|
|
CHART_BAR()
DEPRECATED: use CHART() instead.
Syntax: CHART_BAR()
Generates a bar chart in HTML format.
|
|
|
|
CHART_SCATTER()
DEPRECATED: use CHART() instead.
Syntax: CHART_SCATTER()
Generates a scatter chart in HTML format.
|
|
|
|
CHART_LINE3D()
DEPRECATED: use CHART() instead.
Syntax: CHART_LINE3D()
Generates a 3D line chart in HTML format.
|
|
|
|
CHART_BAR3D()
DEPRECATED: use CHART() instead.
Syntax: CHART_BAR3D()
Generates a 3D bar chart in HTML format.
|
|
|
|
CHART_SCATTER3D()
DEPRECATED: use CHART() instead.
Syntax: CHART_SCATTER3D()
Generates a 3D scatter chart in HTML format.
|
|
|
|
title()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: title(label)
label
string
subtitle()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: subtitle(label)
label
string
xAxis(), yAxis(), zAxis()
DEPRECATED: use chartOption() with CHART() instead.
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()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: dataZoom(type, minPercentage, maxPercentage)
type
string “slider”, “inside”minPercentage
number 0 ~ 100maxPercentage
number 0 ~ 100
2D chart only
opacity()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: opacity(alpha)
alpha
number 0.0 ~ 1.0
3D chart only
autoRotate()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: autoRotate( [speed] )
speed
number degree/sec, default is 10
gridSize()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: gridSize( width, height, depth )
width
number percentage (default: 100)height
number percentage (default: 100)depth
number percentage (default: 100)
3D chart only
seriesLabels()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: seriesLabels( label... )
label
string
Specify the label text of each series.
toolbox
toolboxSaveAsImage()
DEPRECATED: use chartOption() with CHART() instead.
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()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: toolboxDataZoom()
Since v8.0.4
Show the toolbox button for data zoom.
toolboxDataView()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: toolboxDataView()
Since v8.0.4
Show the toolbox button for raw data viewer.
|
|
visualMap()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: visualMap(min, max)
min
numbermax
number
It calls visualMapColor()
internally with pre-defined default colors.
visualMapColor()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: visualMapColor(min, max, colors...)
Since v8.0.4
min
numbermax
numbercolors
colors in array of string
Example)
|
|
markArea()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: markArea(coord0, coord1 [, label [, color [, opacity]]])
coord0
any : area beginning x-valuecoord1
any : area ending x-valuelabel
string : titlecolor
string : color of areaopacity
number : 0~1 of opacity
Example)
|
|
markXAxis()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: markXAxis(coord, label)
coord
any : marked x-valuelabel
string : title
|
|
markYAxis()
DEPRECATED: use chartOption() with CHART() instead.
Syntax: markYAxis(coord, label)
coord
any : marked y-valuelabel
string : title
|
|