You can find here a recipe with an hello-world example which will :
- Show you how to connect to the API
- How to use the streams API
- Upload an example dataset as a stream
- Get the stream definition schema
- How to (basically) use the Query API on this example dataset
It's a request builder to get data from a stream
Supports multiple "modes":
- listing all records matching a criteria
- performing ad-hoc aggregations over records
- retrieving a distinct_on of records at a specific time, distinct on a set of fields
This reuses all the principles of a SQL query and can be considered as a (very) simplified layer above the data. A basic understanding of the main SQL principles would be helpful to understand its capacities, especially because we'll use SQL as a guideline to explain the different principles.
With this documentation is also provided a set of examples which contain :
- A raw data example of the stream we are querying
- A sentence explaining what we're trying to achieve with this query
- The full payload of the sentence
- An extract of the response sent by the API :
- schema of the columns response
- the first row result
You can find it HERE
The API already provides the stream definition of the columns on different endpoints ( GET zone/{zone_id}/streams/, GET zone/{zone_id}/streams/{stream_id} ). This stream definition gives us information about data present in the stream :
- the column name
- the min/max of the column
- the number of rows
- the data type
Here is a stream definition example
"stream_fields": {
"additionalProp1": {
"index": "primary",
"extents": {
"min": 2345,
"max": 6789
},
"count": 0,
"data_type": "number"
},
...
},
With this stream definition, you have the necessary informations to build a request to answer questions you have on the data.
A payload for the query endpoint ( POST zone/{zone_id}/streams/query ) is composed like this :
{
"fields": [],
"aggregation": {
"time": {
"resolution": "minute",
"field": "string",
"label": "string"
},
"operations": []
},
"computed_fields": [],
"distinct_on": {
"fields": [],
"order_by": [],
"where": []
},
"joins": [],
"where": [],
"order_by": [],
"limit": 50000,
"sample": null
}
Let's discover what's the use case for each field