| <!-- |
| |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| |
| --> |
| |
| ### 选择函数 |
| |
| 目前 IoTDB 支持如下选择函数: |
| |
| | 函数名 | 输入序列类型 | 必要的属性参数 | 输出序列类型 | 功能描述 | |
| | -------- | ------------------------------------- | ------------------------------------------------- | ------------------------ | ------------------------------------------------------------ | |
| | TOP_K | INT32 / INT64 / FLOAT / DOUBLE / TEXT | `k`: 最多选择的数据点数,必须大于 0 小于等于 1000 | 与输入序列的实际类型一致 | 返回某时间序列中值最大的`k`个数据点。若多于`k`个数据点的值并列最大,则返回时间戳最小的数据点。 | |
| | BOTTOM_K | INT32 / INT64 / FLOAT / DOUBLE / TEXT | `k`: 最多选择的数据点数,必须大于 0 小于等于 1000 | 与输入序列的实际类型一致 | 返回某时间序列中值最小的`k`个数据点。若多于`k`个数据点的值并列最小,则返回时间戳最小的数据点。 | |
| |
| 例如: |
| |
| ``` sql |
| select s1, top_k(s1, 'k'='2'), bottom_k(s1, 'k'='2') from root.sg1.d2 where time > 2020-12-10T20:36:15.530+08:00; |
| ``` |
| |
| 结果: |
| |
| ``` |
| +-----------------------------+--------------------+------------------------------+---------------------------------+ |
| | Time| root.sg1.d2.s1|top_k(root.sg1.d2.s1, "k"="2")|bottom_k(root.sg1.d2.s1, "k"="2")| |
| +-----------------------------+--------------------+------------------------------+---------------------------------+ |
| |2020-12-10T20:36:15.531+08:00| 1531604122307244742| 1531604122307244742| null| |
| |2020-12-10T20:36:15.532+08:00|-7426070874923281101| null| null| |
| |2020-12-10T20:36:15.533+08:00|-7162825364312197604| -7162825364312197604| null| |
| |2020-12-10T20:36:15.534+08:00|-8581625725655917595| null| -8581625725655917595| |
| |2020-12-10T20:36:15.535+08:00|-7667364751255535391| null| -7667364751255535391| |
| +-----------------------------+--------------------+------------------------------+---------------------------------+ |
| Total line number = 5 |
| It costs 0.006s |
| ``` |