It is time to go back to the basics. The FETCH function allows you to extract your data from Warp 10 in different manners.
It is time to go back to basics. The FETCH function allows you to extract your data from Warp 10 in different manners.
Fetch in a glance
The FETCH
function has the following signature:
[
< read token >
< class name selector >
< labels and/or attributes selector >
< start of the range >
< end of the range >
] FETCH
Remember that the end of the range is in the past compared to the start, we are looking back in time.
A class name selector could be a full class name or a regular expression: 'my.sensor.speed'
or '~my.*'
.
A labels and/or attribute selector could be empty or described as a string or a regular expression:
{}
{ 'sensorId' '123' 'customer' '456' }
{ 'sensorId' '~12.*' }
.
Get the last 100 data-points
The start of the range is a positive LONG, the end of the range is a negative LONG.
From now
[ < read token > 'my.sensor.speed' {} NOW -100 ] FETCH
The start of the range is NOW and the end of the range is a negative value which corresponds to the number of data-points we want to extract.
From a specific date
[ < read token > 'my.sensor.speed' {} 1568812068234472 -100 ] FETCH
The start of the range is a timestamp in microseconds.
You can obtain such a timestamp with TOTIMESTAMP or TSELEMENTS->:
'2019-09-18T13:09:04.749292Z' TOTIMESTAMP
[ 2019 09 18 13 09 04 ] TSELEMENTS->
Get the last hour of data
The start of the range is a positive LONG, the end of the range is a positive LONG.
From now
[ < read token > 'my.sensor.speed' {} NOW 3600000000 ] FETCH
The start of the range is NOW and the end of the range is defined by a positive value which corresponds to a number of microseconds.
To obtain an amount of microseconds, you can use time unit functions :
d (day), h (hour), m (minute), ms (millisecond), ns (nanosecond), ps (picosecond), s (second), us (microsecond), w (week)
So in the previous WarpScript, you could use 1 h
instead of 3600000000
.
From a specific date
[ < read token > 'my.sensor.speed' {} 1568812068234472 1 h ] FETCH
The start of the range is a timestamp in microseconds.
You can obtain such a timestamp with TOTIMESTAMP or TSELEMENTS->:
'2019-09-18T13:09:04.749292Z' TOTIMESTAMP
[ 2019 09 18 13 09 04 ] TSELEMENTS->
Between two dates
The start and the end of the string must be ISO-8601 strings.
[
< read token >
'my.sensor.speed'
{}
'2019-09-01T00:00:00.000000Z'
'2019-10-01T00:00:00.000000Z'
] FETCH
You can obtain such a string with ISO8601 and TSELEMENTS->:
1568812068234472 ISO8601
[ 2019 09 18 13 09 04 ] TSELEMENTS-> ISO8601
A last word
All dates and timestamps must be in UTC. If you want to switch from time zones, have a look here.
Try it with your data, you can use our Sandbox and Warp-Studio for that.
Read more
Fetch the first data point in Warp 10
Working with GEOSHAPEs
Compare data hour to hour, day to day
Senior Software Engineer