Skip to content

Commit a78b73a

Browse files
authored
Add support version to minby maxby (#784)
* fix iotdb enterprise edition to timechodb * add support version to minby and maxby * remove other changes
1 parent 66a078f commit a78b73a

File tree

8 files changed

+474
-97
lines changed

8 files changed

+474
-97
lines changed

src/UserGuide/V1.3.x/SQL-Manual/Function-and-Expression.md

Lines changed: 208 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,12 @@ The aggregate functions supported by IoTDB are as follows:
539539
| SUM | Summation. | INT32 INT64 FLOAT DOUBLE | / | DOUBLE |
540540
| COUNT | Counts the number of data points. | All data types | / | INT |
541541
| AVG | Average. | INT32 INT64 FLOAT DOUBLE | / | DOUBLE |
542+
STDDEV | Alias for STDDEV_SAMP. Return the sample standard deviation. | INT32 INT64 FLOAT DOUBLE | / | DOUBLE |
543+
| STDDEV_POP | Return the population standard deviation. | INT32 INT64 FLOAT DOUBLE | / | DOUBLE |
544+
| STDDEV_SAMP | Return the sample standard deviation. | INT32 INT64 FLOAT DOUBLE | / | DOUBLE |
545+
| VARIANCE | Alias for VAR_SAMP. Return the sample variance. | INT32 INT64 FLOAT DOUBLE | / | DOUBLE |
546+
| VAR_POP | Return the population variance. | INT32 INT64 FLOAT DOUBLE | / | DOUBLE |
547+
| VAR_SAMP | Return the sample variance. | INT32 INT64 FLOAT DOUBLE | / | DOUBLE |
542548
| EXTREME | Finds the value with the largest absolute value. Returns a positive value if the maximum absolute value of positive and negative values is equal. | INT32 INT64 FLOAT DOUBLE | / | Consistent with the input data type |
543549
| MAX_VALUE | Find the maximum value. | INT32 INT64 FLOAT DOUBLE | / | Consistent with the input data type |
544550
| MIN_VALUE | Find the minimum value. | INT32 INT64 FLOAT DOUBLE | / | Consistent with the input data type |
@@ -549,29 +555,11 @@ The aggregate functions supported by IoTDB are as follows:
549555
| COUNT_IF | Find the number of data points that continuously meet a given condition and the number of data points that meet the condition (represented by keep) meet the specified threshold. | BOOLEAN | `[keep >=/>/=/!=/</<=]threshold`:The specified threshold or threshold condition, it is equivalent to `keep >= threshold` if `threshold` is used alone, type of `threshold` is `INT64` `ignoreNull`:Optional, default value is `true`;If the value is `true`, null values are ignored, it means that if there is a null value in the middle, the value is ignored without interrupting the continuity. If the value is `true`, null values are not ignored, it means that if there are null values in the middle, continuity will be broken | INT64 |
550556
| TIME_DURATION | Find the difference between the timestamp of the largest non-null value and the timestamp of the smallest non-null value in a column | All data Types | / | INT64 |
551557
| MODE | Find the mode. Note: 1.Having too many different values in the input series risks a memory exception; 2.If all the elements have the same number of occurrences, that is no Mode, return the value with earliest time; 3.If there are many Modes, return the Mode with earliest time. | All data Types | / | Consistent with the input data type |
552-
| STDDEV | Calculate the overall standard deviation of the data. Note:<br> Missing points, null points and `NaN` in the input series will be ignored.| INT32 INT64 FLOAT DOUBLE | / | DOUBLE |
553558
| COUNT_TIME | The number of timestamps in the query data set. When used with `align by device`, the result is the number of timestamps in the data set per device. | All data Types, the input parameter can only be `*` | / | INT64 |
559+
| MAX_BY | MAX_BY(x, y) returns the value of x corresponding to the maximum value of the input y. MAX_BY(time, x) returns the timestamp when x is at its maximum value. <br> Note: Supported from version V1.3.2 | The first input x can be of any type, while the second input y must be of type INT32, INT64, FLOAT, DOUBLE, STRING, TIMESTAMP or DATE. | / | Consistent with the data type of the first input x. |
560+
| MIN_BY | MIN_BY(x, y) returns the value of x corresponding to the minimum value of the input y. MIN_BY(time, x) returns the timestamp when x is at its minimum value. <br> Note: Supported from version V1.3.2 | The first input x can be of any type, while the second input y must be of type INT32, INT64, FLOAT, DOUBLE, STRING, TIMESTAMP or DATE. | / | Consistent with the data type of the first input x. |
554561
555562
556-
### COUNT
557-
558-
#### example
559-
560-
```sql
561-
select count(status) from root.ln.wf01.wt01;
562-
```
563-
Result:
564-
565-
```
566-
+-------------------------------+
567-
|count(root.ln.wf01.wt01.status)|
568-
+-------------------------------+
569-
| 10080|
570-
+-------------------------------+
571-
Total line number = 1
572-
It costs 0.016s
573-
```
574-
575563
### COUNT_IF
576564
577565
#### Grammar
@@ -800,6 +788,206 @@ Result
800788
> 3. Count_time aggregation used with having statement is not supported, and count_time aggregation can not appear in the having statement.
801789
> 4. Count_time does not support use with group by level, group by tag.
802790
791+
792+
793+
794+
### MAX_BY
795+
796+
#### Function Definition
797+
`max_by(x, y)`: Returns the value of x at the timestamp where y reaches its maximum.
798+
799+
- `max_by` must have two input parameters x and y.
800+
- The first input can be the time keyword. `max_by(time, x)` returns the timestamp when x reaches its maximum value.
801+
- Returns null if x is null at the timestamp where y is maximum.
802+
- If y achieves its maximum at multiple timestamps, returns the x value at the smallest timestamp among them.
803+
- Aligns with IoTDB's `max_value`: Only supports INT32, INT64, FLOAT, DOUBLE as y input. Supports all six data types as x input.
804+
- Inputs x and y cannot be literal values.
805+
806+
#### Syntax
807+
```sql
808+
select max_by(x, y) from root.sg
809+
select max_by(time, x) from root.sg
810+
```
811+
812+
#### Examples
813+
814+
##### Raw Data
815+
```sql
816+
IoTDB> select * from root.test
817+
+-----------------------------+-----------+-----------+
818+
| Time|root.test.a|root.test.b|
819+
+-----------------------------+-----------+-----------+
820+
|1970-01-01T08:00:00.001+08:00| 1.0| 10.0|
821+
|1970-01-01T08:00:00.002+08:00| 2.0| 10.0|
822+
|1970-01-01T08:00:00.003+08:00| 3.0| 3.0|
823+
|1970-01-01T08:00:00.004+08:00| 10.0| 10.0|
824+
|1970-01-01T08:00:00.005+08:00| 10.0| 12.0|
825+
|1970-01-01T08:00:00.006+08:00| 6.0| 6.0|
826+
+-----------------------------+-----------+-----------+
827+
```
828+
##### Query Examples
829+
Get timestamp corresponding to maximum value:
830+
```sql
831+
IoTDB> select max_by(time, a), max_value(a) from root.test
832+
+-------------------------+------------------------+
833+
|max_by(Time, root.test.a)| max_value(root.test.a)|
834+
+-------------------------+------------------------+
835+
| 4| 10.0|
836+
+-------------------------+------------------------+
837+
```
838+
839+
Get b value when a is maximum:
840+
```sql
841+
IoTDB> select max_by(b, a) from root.test
842+
+--------------------------------+
843+
|max_by(root.test.b, root.test.a)|
844+
+--------------------------------+
845+
| 10.0|
846+
+--------------------------------+
847+
```
848+
849+
With expressions:
850+
```sql
851+
IoTDB> select max_by(b + 1, a * 2) from root.test
852+
+----------------------------------------+
853+
|max_by(root.test.b + 1, root.test.a * 2)|
854+
+----------------------------------------+
855+
| 11.0|
856+
+----------------------------------------+
857+
```
858+
859+
With GROUP BY TIME clause:
860+
```sql
861+
IoTDB> select max_by(b, a) from root.test group by ([0,7),4ms)
862+
+-----------------------------+--------------------------------+
863+
| Time|max_by(root.test.b, root.test.a)|
864+
+-----------------------------+--------------------------------+
865+
|1970-01-01T08:00:00.000+08:00| 3.0|
866+
+-----------------------------+--------------------------------+
867+
|1970-01-01T08:00:00.004+08:00| 10.0|
868+
+-----------------------------+--------------------------------+
869+
```
870+
871+
With HAVING clause:
872+
```sql
873+
IoTDB> select max_by(b, a) from root.test group by ([0,7),4ms) having max_by(b, a) > 4.0
874+
+-----------------------------+--------------------------------+
875+
| Time|max_by(root.test.b, root.test.a)|
876+
+-----------------------------+--------------------------------+
877+
|1970-01-01T08:00:00.004+08:00| 10.0|
878+
+-----------------------------+--------------------------------+
879+
```
880+
With ORDER BY clause:
881+
```sql
882+
IoTDB> select max_by(b, a) from root.test group by ([0,7),4ms) order by time desc
883+
+-----------------------------+--------------------------------+
884+
| Time|max_by(root.test.b, root.test.a)|
885+
+-----------------------------+--------------------------------+
886+
|1970-01-01T08:00:00.004+08:00| 10.0|
887+
+-----------------------------+--------------------------------+
888+
|1970-01-01T08:00:00.000+08:00| 3.0|
889+
+-----------------------------+--------------------------------+
890+
```
891+
892+
### MIN_BY
893+
#### Function Definition
894+
`min_by(x, y)`: Returns the value of x at the timestamp where y reaches its minimum.
895+
896+
- `min_by` must have two input parameters x and y.
897+
- The first input can be the time keyword. `min_by(time, x)` returns the timestamp when x reaches its minimum value.
898+
- Returns null if x is null at the timestamp where y is minimum.
899+
- If y achieves its minimum at multiple timestamps, returns the x value at the smallest timestamp among them.
900+
- Aligns with IoTDB's `min_value`: Only supports INT32, INT64, FLOAT, DOUBLE as y input. Supports all six data types as x input.
901+
- Inputs x and y cannot be literal values.
902+
903+
#### Syntax
904+
```sql
905+
select min_by(x, y) from root.sg
906+
select min_by(time, x) from root.sg
907+
```
908+
909+
#### Examples
910+
911+
##### Raw Data
912+
```sql
913+
IoTDB> select * from root.test
914+
+-----------------------------+-----------+-----------+
915+
| Time|root.test.a|root.test.b|
916+
+-----------------------------+-----------+-----------+
917+
|1970-01-01T08:00:00.001+08:00| 4.0| 10.0|
918+
|1970-01-01T08:00:00.002+08:00| 3.0| 10.0|
919+
|1970-01-01T08:00:00.003+08:00| 2.0| 3.0|
920+
|1970-01-01T08:00:00.004+08:00| 1.0| 10.0|
921+
|1970-01-01T08:00:00.005+08:00| 1.0| 12.0|
922+
|1970-01-01T08:00:00.006+08:00| 6.0| 6.0|
923+
+-----------------------------+-----------+-----------+
924+
```
925+
##### Query Examples
926+
Get timestamp corresponding to minimum value:
927+
```sql
928+
IoTDB> select min_by(time, a), min_value(a) from root.test
929+
+-------------------------+------------------------+
930+
|min_by(Time, root.test.a)| min_value(root.test.a)|
931+
+-------------------------+------------------------+
932+
| 4| 1.0|
933+
+-------------------------+------------------------+
934+
```
935+
936+
Get b value when a is minimum:
937+
```sql
938+
IoTDB> select min_by(b, a) from root.test
939+
+--------------------------------+
940+
|min_by(root.test.b, root.test.a)|
941+
+--------------------------------+
942+
| 10.0|
943+
+--------------------------------+
944+
```
945+
946+
With expressions:
947+
```sql
948+
IoTDB> select min_by(b + 1, a * 2) from root.test
949+
+----------------------------------------+
950+
|min_by(root.test.b + 1, root.test.a * 2)|
951+
+----------------------------------------+
952+
| 11.0|
953+
+----------------------------------------+
954+
```
955+
956+
With GROUP BY TIME clause:
957+
```sql
958+
IoTDB> select min_by(b, a) from root.test group by ([0,7),4ms)
959+
+-----------------------------+--------------------------------+
960+
| Time|min_by(root.test.b, root.test.a)|
961+
+-----------------------------+--------------------------------+
962+
|1970-01-01T08:00:00.000+08:00| 3.0|
963+
+-----------------------------+--------------------------------+
964+
|1970-01-01T08:00:00.004+08:00| 10.0|
965+
+-----------------------------+--------------------------------+
966+
```
967+
968+
With HAVING clause:
969+
```sql
970+
IoTDB> select min_by(b, a) from root.test group by ([0,7),4ms) having max_by(b, a) > 4.0
971+
+-----------------------------+--------------------------------+
972+
| Time|min_by(root.test.b, root.test.a)|
973+
+-----------------------------+--------------------------------+
974+
|1970-01-01T08:00:00.004+08:00| 10.0|
975+
+-----------------------------+--------------------------------+
976+
```
977+
978+
With ORDER BY clause:
979+
```sql
980+
IoTDB> select min_by(b, a) from root.test group by ([0,7),4ms) order by time desc
981+
+-----------------------------+--------------------------------+
982+
| Time|min_by(root.test.b, root.test.a)|
983+
+-----------------------------+--------------------------------+
984+
|1970-01-01T08:00:00.004+08:00| 10.0|
985+
+-----------------------------+--------------------------------+
986+
|1970-01-01T08:00:00.000+08:00| 3.0|
987+
+-----------------------------+--------------------------------+
988+
```
989+
990+
803991
<!--
804992
805993
​ Licensed to the Apache Software Foundation (ASF) under one

0 commit comments

Comments
 (0)