时间限定语法说明
查询 API 快速衍生
查询的 API 中,支持使用快速的时间限定方法来快速为基础指标,同时也支持完整的时间限定写法
快捷时间限定语法
| 类型 | 快捷写法 |
|---|---|
| 近N日 | json period__{n} [ y\|q\|m\|d\|h\|min ] * 近7日:ordercounts__period__7d |
| 本日至今 | json period__[ y\|q\|m\|w\|d\|h\|mi\|s ] t [ d\| {n}h \| {n}min \| {n}s] * 本年至今(日):ordercounts__period__ytd * 本日至今(1秒):ordercounts__period__dts * 本日至今(5min):ordercounts__period__dt5min |
| 当前 | json period__c [ y\|q\|m\|w\|d\| {n}h \| {n}min \| {n}s] * 本年:ordercounts__period__cy * 当前5min:ordercounts__period__c5min |
通用时间限定语法
{
"metrics":[
"order_count_7d"
],
"metricDefinitions":{
"order_count_7d":{
"refMetric":"order_count",
"period":"to_date -6 day of 0 day",
"period":"",
"specifyDimension":{
"type":"include",
"dimensions":"province,city"
}
}
}
}
metricDefinitions
用于生成临时的指标,具体的参数设置如下
| 参数 | 说明 |
|---|---|
| {metricname} | 临时生成的指标名,在本次查询中使用该指标名进行查询 json "order_count_7d":{ /* 生成临时指标 order_count_7d */ "refMetric":"", "period":"", "specifyDimension":{}, } |
| refMetric | 基于的指标,传入指标CODE(若启用的是指标名称模式,则传入指标名称) |
| period | 时间限定:具体参考下述示例 |
| filter | 业务限定 |
| specifyDimension | 可用维度控制 |
period
| 时间限定类型 | 说明 |
|---|---|
| to_date | 近N粒度:时段范围 * 近N日,近N个月 json "period":"to_date -6 day of 0 day" 最近7日 |
| grain_to_date | 至今:年初至今,去年初至今 * 本年至今,本月至今 json "period":"grain_to_date 0 day to 0 5minute" 本日至今(5min粒度) |
| specify_date | 期末期初:期初期末特殊日期 * 本年第一天,本月最后一天 json "period":" end day of -1 month" 上月的最后一天 |
| relative_date | 单日期:单个日期 * 7日前当日,上个月,本月整月 json "period":"relative_date 0 5minute of 0 5minute" 最近5min |
to_date
| 参数 | 说明 |
|---|---|
| 偏移数量 | 当前查询的偏移粒度。 -N表示过去N;N表示未来N ![]() |
| 偏移粒度 | 偏移的粒度,支持: * year、quarter、month、week、day、hour、nhour、minute、nminute ![]() |
| 日期粒度 | 日期粒度,支持: * year、quarter、month、week、day、hour、nhour、minute、nminute ![]() |
grain_to_date
"grain_to_date":
" [偏移数量] [偏移粒度] to 0 [日期粒度] ",
"period":"grain_to_date 0 day to 0 5minute"
本日至今(5min粒度)
| 参数 | 说明 |
|---|---|
| 偏移数量 + 偏移粒度 | 当前查询的偏移粒度。 -N表示过去N;N表示未来N。 偏移的粒度,支持: * year、quarter、month、week、day、hour、nhour、minute、nminute ![]() |
| 日期粒度 | 日期粒度,支持: * year、quarter、month、week、day、hour、nhour、minute、nminute ![]() |
specify_date
| 参数 | 说明 |
|---|---|
| 周期内第一个、最后一个 | ![]() |
| 偏移数量 + 偏移粒度 | 当前查询的偏移粒度。 -N表示过去N;N表示未来N。 偏移的粒度,支持: * year、quarter、month、week、day、hour、nhour、minute、nminute ![]() |
| 日期粒度 | 日期粒度,支持: * year、quarter、month、week、day、hour、nhour、minute、nminute ![]() |
relative_date
"relative_date":
" [偏移数量] [偏移粒度] of 0 [日期粒度] ",
"period":"relative_date 0 5minute of 0 5minute"
最近5min
集成查询示例
获取 当日的累计值(10min粒度)
使用完整定义
{
"metrics":[
"order_count"
],
"metricDefinitions":{
"order_count_10minute_accsum":{
"refMetric":"order_count",
"period":"grain_to_date 0 day to 0 10minute"
}
"dimensions": [
"metric_time__10minute"
],
"timeConstraint": "(['metric_time'] = TODAY() )",
}
}
使用快速定义
{
"metrics":[
"dt10mi__order_count"
],
"dimensions": [
"metric_time__10minute"
],
"timeConstraint": "(['metric_time'] = TODAY() )",
}
}
查询结果会返回以下结构数据
| metric_time_minute_10 | order_count_10minute_accsum |
|---|---|
| 2024-08-12 00:00:00 | 12 |
| 2024-08-12 00:10:00 | 18 |
| 2024-08-12 00:20:00 | 32 |
| 2024-08-12 00:30:00 | 40 |
| ... | ... |
获取当日 每10min的销量
{
"metrics":[
"order_count"
],
"dimensions": [
"metric_time__10minute"
],
"timeConstraint": "(['metric_time'] = TODAY() )",
}
}
查询结果会返回以下结构数据
| metric_time_minute_5 | order_count |
|---|---|
| 2024-08-12 00:00:00 | 2 |
| 2024-08-12 00:10:00 | 4 |
| 2024-08-12 00:20:00 | 2 |
| 2024-08-12 00:30:00 | 5 |
| ... | ... |
传入当前时间,获取至今的累计值
使用完整定义
minute_10{
"metrics":[
"order_count_10minute"
],
"metricDefinitions":{
"order_count_5minute":{
"refMetric":"order_count",
"period":"grain_to_date 0 day to 0 day"
}
"dimensions": [],
"timeConstraint": "(['metric_time'] = NOW() )",
}
}
使用快速定义
minute_10{
"metrics":[
"dt10mi__order_count"
],
"dimensions": [],
"timeConstraint": "(['metric_time'] = NOW() )",
}
}
查询结果会返回以下结构数据
| order_count_10minute |
|---|
| 4213 |
传入当前时间,获取所在的10min区间内的指标汇总
使用完整定义
{
"metrics":[
"order_count_10minute"
],
"metricDefinitions":{
"order_count_5minute":{
"refMetric":"order_count",
"period":"relative_date 0 10minute of 0 10minute"
}
"dimensions": [],
"timeConstraint": "(['metric_time'] = NOW() )",
}
}
使用快速定义
{
"metrics":[
"c10mi__order_count"
],
"dimensions": [],
"timeConstraint": "(['metric_time'] = NOW() )",
}
}
查询结果会返回以下结构数据
| order_count_10minute |
|---|
| 420 |







