Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(universe): support for dynamic queries (#1284)
- Loading branch information
Showing
4 changed files
with
2,132 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package testdata_test | ||
|
||
import "testing" | ||
|
||
option now = () => (2030-01-01T00:00:00Z) | ||
|
||
inData = " | ||
#datatype,string,long,dateTime:RFC3339,double,string,string | ||
#group,false,false,false,false,true,true | ||
#default,_result,,,,, | ||
,result,table,_time,_value,_measurement,user | ||
,,0,2018-05-22T19:53:26Z,0,CPU,user1 | ||
,,0,2018-05-22T19:53:36Z,1,CPU,user1 | ||
,,1,2018-05-22T19:53:26Z,4,CPU,user2 | ||
,,1,2018-05-22T19:53:36Z,20,CPU,user2 | ||
,,1,2018-05-22T19:53:46Z,7,CPU,user2 | ||
,,2,2018-05-22T19:53:26Z,1,RAM,user1" | ||
|
||
outData = " | ||
#datatype,string,long,dateTime:RFC3339,double,string,string | ||
#group,false,false,false,false,true,true | ||
#default,_result,,,,, | ||
,result,table,_time,_value,_measurement,user | ||
,,0,2018-05-22T19:53:26Z,0,CPU,user1 | ||
,,0,2018-05-22T19:53:36Z,1,CPU,user1 | ||
,,1,2018-05-22T19:53:26Z,1,RAM,user1 | ||
" | ||
|
||
t_dynamic = (table=<-) => { | ||
r = table |> range(start: 2018-05-22T19:53:26Z) |> drop(columns: ["_start", "_stop"]) | ||
t = r |> tableFind(fn: (key) => key._measurement == "CPU") | ||
users = t |> getColumn(column: "user") | ||
|
||
// This is a dynamic query, because this query uses the results of another one. | ||
return r |> filter(fn: (r) => contains(value: r.user, set: users)) | ||
} | ||
|
||
test _dynamic_query = () => | ||
({input: testing.loadStorage(csv: inData), want: testing.loadMem(csv: outData), fn: t_dynamic}) |
Oops, something went wrong.