Provide examples to havingSpec filters (#5774)

* expand examples

* expand examples for filtered havingSpecs

* expand other having examples

* remove blank code block

* add better AND/OR/NOT examples

* fix indentation
This commit is contained in:
Caroline1000 2018-05-14 13:43:42 -07:00 committed by Jonathan Wei
parent 15864434be
commit c73e3ea4f5

View File

@ -15,16 +15,27 @@ Query filter HavingSpecs allow all [Druid query filters](filters.html) to be use
The grammar for a query filter HavingSpec is:
```json
{
"queryType": "groupBy",
"dataSource": "sample_datasource",
...
"having":
{
"type" : "filter",
"filter" : <any Druid query filter>
}
}
```
For example, to use a selector filter:
```json
{
"queryType": "groupBy",
"dataSource": "sample_datasource",
...
"having":
{
"type" : "filter",
"filter" : {
@ -33,6 +44,7 @@ For example, to use a selector filter:
"value" : "<dimension_value>"
}
}
}
```
You can use "filter" HavingSpecs to filter on the timestamp of result rows by applying a filter to the "\_\_time"
@ -46,10 +58,16 @@ Numeric filters can be used as the base filters for more complex boolean express
Here's an example of a having-clause numeric filter:
```json
{
"queryType": "groupBy",
"dataSource": "sample_datasource",
...
"having":
{
"type": "greaterThan",
"aggregation": "myAggMetric",
"value": 100
"aggregation": "<aggregate_metric>",
"value": <numeric_value>
}
}
```
@ -59,11 +77,17 @@ The equalTo filter will match rows with a specific aggregate value.
The grammar for an `equalTo` filter is as follows:
```json
{
"queryType": "groupBy",
"dataSource": "sample_datasource",
...
"having":
{
"type": "equalTo",
"aggregation": "<aggregate_metric>",
"value": <numeric_value>
}
}
```
This is the equivalent of `HAVING <aggregate> = <value>`.
@ -74,11 +98,17 @@ The greaterThan filter will match rows with aggregate values greater than the gi
The grammar for a `greaterThan` filter is as follows:
```json
{
"queryType": "groupBy",
"dataSource": "sample_datasource",
...
"having":
{
"type": "greaterThan",
"aggregation": "<aggregate_metric>",
"value": <numeric_value>
}
}
```
This is the equivalent of `HAVING <aggregate> > <value>`.
@ -89,11 +119,17 @@ The lessThan filter will match rows with aggregate values less than the specifie
The grammar for a `greaterThan` filter is as follows:
```json
{
"queryType": "groupBy",
"dataSource": "sample_datasource",
...
"having":
{
"type": "lessThan",
"aggregation": "<aggregate_metric>",
"value": <numeric_value>
}
}
```
This is the equivalent of `HAVING <aggregate> < <value>`.
@ -108,11 +144,17 @@ The dimSelector filter will match rows with dimension values equal to the specif
The grammar for a `dimSelector` filter is as follows:
```json
{
"queryType": "groupBy",
"dataSource": "sample_datasource",
...
"having":
{
"type": "dimSelector",
"dimension": "<dimension>",
"value": <dimension_value>
}
}
```
@ -123,36 +165,75 @@ The grammar for a `dimSelector` filter is as follows:
The grammar for an AND filter is as follows:
```json
{
"queryType": "groupBy",
"dataSource": "sample_datasource",
...
"having":
{
"type": "and",
"havingSpecs": [<having clause>, <having clause>, ...]
"havingSpecs": [
{
"type": "greaterThan",
"aggregation": "<aggregate_metric>",
"value": <numeric_value>
},
{
"type": "lessThan",
"aggregation": "<aggregate_metric>",
"value": <numeric_value>
}
]
}
}
```
The having clauses in `havingSpecs` can be any other having clause defined on this page.
#### OR
The grammar for an OR filter is as follows:
```json
{
"queryType": "groupBy",
"dataSource": "sample_datasource",
...
"having":
{
"type": "or",
"havingSpecs": [<having clause>, <having clause>, ...]
"havingSpecs": [
{
"type": "greaterThan",
"aggregation": "<aggregate_metric>",
"value": <numeric_value>
},
{
"type": "equalTo",
"aggregation": "<aggregate_metric>",
"value": <numeric_value>
}
]
}
}
```
The having clauses in `havingSpecs` can be any other having clause defined on this page.
#### NOT
The grammar for a NOT filter is as follows:
```json
{
"queryType": "groupBy",
"dataSource": "sample_datasource",
...
"having":
{
"type": "not",
"havingSpec": <having clause>
"havingSpec":
{
"type": "equalTo",
"aggregation": "<aggregate_metric>",
"value": <numeric_value>
}
}
}
```
The having clause specified at `havingSpec` can be any other having clause defined on this page.