Query Statistics
The query statistics request body is a JSON object sent in a Geovisualization REST API request to retrieve statistics about the data resulting from a query.
Element | Data Type | Mandatory | Description |
---|---|---|---|
stats | Object | Yes | A nested list containing two objects:
|
The code example below illustrates a typical column_stats
object.
"column_stats": {
"metric_a": ["$max", "$min", "$average"],
"facet_a": ["$count_distinct"]
}
The code example below illustrates a typical dynamic
object. The following would remove both the tx
and ty
dynamic parameters from the query and set the zoom to 10:
"dynamic": {
"tx": "$drop",
"ty": "$drop",
"zoom": 10
}
The following example shows the request body to get the average depth of earthquakes contained in the earthquake dataset in the Geovisualization starter pack (with dataset ID 90af668484394fa782cc103409cafe39
), when using the following query:
{
"origin": "user",
"description": "Earthquake data from 2012 - Absolute value of depths",
"tags": [
"depths",
"earthquakes"
],
"updated_at": "2016-01-15T09:34:09Z",
"visibility": "private",
"dataset": "90af668484394fa782cc103409cafe39",
"query": {
"metrics": [
"absolute_value"
],
"version": 0.3,
"namespace": {
"absolute_value": {
"source": [
"Depth"
],
"apply": [
{
"type": "transform",
"fn": "abs"
}
]
}
},
"dataset": "90af668484394fa782cc103409cafe39"
},
"id": "f943d8f5f4e247df8b53e318ee4ee60b",
"kind": "datalens#query",
"created_at": "2016-01-15T09:34:09Z",
"estimated_rows": 1076
}
The request body would be:
{
"stats": [
{
"column_stats": {
"absolute_value": ["$average"]
},
}
]
}
The response body would be:
{
"query_id": "f943d8f5f4e247df8b53e318ee4ee60b",
"stats": [
{
"column_stats": {
"absolute_value": {
"$average": 29.479739777
}
}
}
]
}
If you were to change the value $average
to $max
, then the stats response contains the maximum depth of the earthquakes in the dataset.