Query
is a golang structure as OLAP input, defining at github.com/awatercolorpen/olap-sql/api/types.
type Query struct {
DataSetName string `json:"data_set_name"`
TimeInterval *TimeInterval `json:"time_interval"`
Metrics []string `json:"metrics"`
Dimensions []string `json:"dimensions"`
Filters []*Filter `json:"filters"`
Orders []*OrderBy `json:"orders"`
Limit *Limit `json:"limit"`
Sql string `json:"Sql"`
}
Supported json protocol now.
{
"data_set_name": "",
"time_interval": {},
"metrics": [],
"dimensions": [],
"filters": [],
"orders": [],
"limit": {},
"sql": ""
}
data_set_name
(required) is the name of one business, also the name of sets.
{
"data_set_name": "wikistat"
}
time_interval
(optional) is a special structure for time interval filter condition.
It will auto translate to one filters.
WHERE (`name` >= `start` AND `name` < `end`)
name
(required) is the dimension name for time interval.start
(required) is a string that is valid for golangtime.Time
type.end
(required) is a string that is valid for golangtime.Time
type.
{
"time_interval": {
"name": "date",
"start": "2021-05-06",
"end": "2021-05-08"
}
}
metrics
(optional) is a list of metrics name.
At least one of metrics or dimensions is required.
{
"metrics": [
"hits",
"hits_avg"
]
}
dimensions
(optional) is a list of dimensions name.
At least one of metrics or dimensions is required.
{
"dimensions": [
"date"
]
}
filters
(optional) is a list of WHERE
statement object.
table
(don't fill) is an autofilled property byname
.name
(required) is a valid dimension name or metrics name.field_property
(don't fill) is an autofilled property byname
.operator_type
(required) is operator type of filter. For detail.value
(required) is array for values. For detail.value_type
(don't fill) is an autofilled property byname
.children
(optional) is a list of Filter. It is used forFILTER_OPERATOR_AND
orFILTER_OPERATOR_OR
case.
{
"filters": [
{
"operator_type":"FILTER_OPERATOR_IN",
"name":"date",
"value": [
"2021-05-06",
"2021-05-07"
]
}
]
}
type | description | required | sql example |
---|---|---|---|
FILTER_OPERATOR_EQUALS |
= condition. |
value size == 1. |
name = value[0] |
FILTER_OPERATOR_IN |
IN condition. |
value size > 0. |
name IN (value) |
FILTER_OPERATOR_NOT_IN |
NOT IN condition. |
value size > 0. |
name NOT IN (value) |
FILTER_OPERATOR_LESS_EQUALS |
<= condition. |
value size == 1. |
name <= value[0] |
FILTER_OPERATOR_LESS |
< condition. |
value size == 1. |
name < value[0] |
FILTER_OPERATOR_GREATER_EQUALS |
>= condition. |
value size == 1. |
name >= value[0] |
FILTER_OPERATOR_GREATER |
> condition. |
value size == 1. |
name > value[0] |
FILTER_OPERATOR_LIKE |
like condition. |
value size == 1. |
name like value[0] |
FILTER_OPERATOR_HAS |
has condition. |
value size == 1. |
hash(name, value[0]) |
FILTER_OPERATOR_EXTENSION |
expression as condition | value size == 1. |
value[0] |
FILTER_OPERATOR_AND |
AND multi children |
children size > 0. |
(children[0] AND children[1]) |
FILTER_OPERATOR_OR |
OR multi children |
children size > 0. |
(children[0] OR children[1]) |
type | description |
---|---|
VALUE_STRING |
string |
VALUE_INTEGER |
int64 |
VALUE_FLOAT |
float |
orders
(optional) is list of ORDER BY
statement object.
table
(don't fill) is an autofilled property byname
.name
(required) is a valid dimension name or metrics name.field_property
(don't fill) is an autofilled property byname
.direction
(optional) is direction type forORDER BY
.
{
"orders": [
{
"name": "date",
"direction": "ORDER_DIRECTION_DESCENDING"
}
]
}
type | description |
---|---|
|
ASC |
ORDER_DIRECTION_ASCENDING |
ASC |
ORDER_DIRECTION_DESCENDING |
DESC |
limit
(optional) is a structure for setting LIMIT
and OFFSET
.
LIMIT 100 OFFSET 20
limit
(optional) is uint64 for settingLIMIT
.offset
(optional) is uint64 for settingOFFSET
.
{
"limit": {
"limit": 100,
"offset": 20
}
}
sql
(optional) is a special property to override other metrics
, dimensions
, filters
, orders
and limit
properties.
It will not generate SQL.
{
"sql": "SELECT VERSION()"
}
{
"data_set_name": "wikistat",
"time_interval": {
"name": "date",
"start": "2021-05-06",
"end": "2021-05-08"
},
"metrics": [
"hits",
"hits_avg"
],
"dimensions": [
"date"
]
}
SELECT
wikistat.date AS date,
1.0 * SUM(wikistat.hits) AS hits,
( ( 1.0 * SUM(wikistat.hits) ) / NULLIF(( COUNT(*) ), 0) ) AS hits_avg
FROM wikistat AS wikistat
WHERE
( wikistat.date >= '2021-05-06' AND wikistat.date < '2021-05-08' )
GROUP BY
wikistat.date