spec := parser.QuerySpec{ Database: "mydb", Statement: "SELECT mean(temp) FROM weather WHERE time > now() - 1h GROUP BY time(10s)", ChunkSize: 10000, } parsedQuery, err := parser.ParseQuery(&spec) if err != nil { log.Fatal(err) } fmt.Println(parsedQuery)
spec := parser.QuerySpec{ Database: "mydb", Statement: "SELECT last(temp) FROM weather WHERE time >= '2020-01-01T00:00:00Z'", ChunkSize: 10000, } parsedQuery, err := parser.ParseQuery(&spec) if err != nil { log.Fatal(err) } for _, stmt := range parsedQuery.Statements { for _, res := range stmt.Results { fmt.Println("Columns:", res.Columns) fmt.Println("Values:", res.Values) } }In this example, we are again defining a `QuerySpec` structure for a database named "mydb". We are defining a query statement to get the latest temperature reading from weather data where the time is after or equal to January 1st, 2020. We are also defining a `ChunkSize` of 10000. We again pass the `QuerySpec` structure to the `ParseQuery` function to parse the query and get the parsed query result. We are then looping through the statements and results to print out the columns and values of the query result. Overall, the `github.com.influxdb.influxdb.parser` package library provides useful functionality for parsing InfluxDB query language in Go.