Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] fix some agg functions doc #1857

Closed
wants to merge 33 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5284529
PERCENTILE_APPROX
Jan 17, 2025
a0291c6
PERCENTILE_APPROX_WEIGHTED
Jan 17, 2025
c7fdda8
PERCENTILE_ARRAY
Jan 17, 2025
cde687e
QUANTILE_UNION
Jan 17, 2025
fe873ec
REGR_INTERCEPT
Jan 17, 2025
fde4973
REGR_SLOPE
Jan 17, 2025
34b3cc0
RETENTION
Jan 17, 2025
30ce7e7
RETENTION
Jan 17, 2025
eb6f9ba
SEQUENCE_COUNT
Jan 17, 2025
93f7713
RETENTION
Jan 17, 2025
93d0286
[opt] Add more storage vault demo about different product (#1788)
SWJTU-ZhangLei Jan 17, 2025
6206e35
[update](reference) Update sql stmt of dev version (#1868)
KassieZ Jan 19, 2025
eb2dda3
[doc] geographical function (#1818)
wyx123654 Jan 20, 2025
205af3f
[doc](update-of-agg-model) fix title error for en doc (#1867)
zhannngchen Jan 20, 2025
11a949b
[doc] fix some agg functions doc (#1861)
hechao-ustc Jan 20, 2025
9051146
[Doc] Add date time function (#1821)
QuakeWang Jan 20, 2025
ba0a57e
[doc] Fix json_array zh_doc (#1809)
mklzl Jan 20, 2025
f2c72db
[fix] Fix en docs typo (#1873)
KassieZ Jan 20, 2025
c93afe7
[Feat]: Archive Document Version 1.2 (#1854)
yang1666204 Jan 20, 2025
cc4d26b
[ecosystem]fix kafka server prompt address (#1795)
DongLiang-0 Jan 20, 2025
d11972f
[doc]Fix aggregate function documentation docs (#1870)
chenzhx Jan 20, 2025
b9aa25e
[opt](function) optimize some map function docs (#1872)
chaoyangqi Jan 20, 2025
6efa869
PERCENTILE_APPROX
Jan 17, 2025
bf5c994
PERCENTILE_APPROX_WEIGHTED
Jan 17, 2025
4049c51
PERCENTILE_ARRAY
Jan 17, 2025
e692658
QUANTILE_UNION
Jan 17, 2025
3adc40c
REGR_INTERCEPT
Jan 17, 2025
166b164
REGR_SLOPE
Jan 17, 2025
c8c5366
RETENTION
Jan 17, 2025
077e336
RETENTION
Jan 17, 2025
7ce5d12
SEQUENCE_COUNT
Jan 17, 2025
3c0160d
RETENTION
Jan 17, 2025
dd1eea1
Merge remote-tracking branch 'origin/sql_manual_0117' into sql_manual…
Jan 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
RETENTION
hechao committed Jan 20, 2025
commit 077e3362c266c587bf8e2445a7c0d726eea6a1a0
144 changes: 48 additions & 96 deletions docs/sql-manual/sql-functions/aggregate-functions/retention.md
Original file line number Diff line number Diff line change
@@ -13,9 +13,7 @@ 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
@@ -24,118 +22,72 @@ specific language governing permissions and limitations
under the License.
-->

## RETENTION

RETENTION

### Description
#### Syntax

`retention(event1, event2, ... , eventN);`
## Description

The `retention` function takes as arguments a set of conditions from 1 to 32 arguments of type `UInt8` that indicate whether a certain condition was met for the event. Any condition can be specified as an argument.

The conditions, except the first, apply in pairs: the result of the second will be true if the first and second are true, of the third if the first and third are true, etc.

To put it simply, the first digit of the return value array indicates whether `event1` is true or false, the second digit represents the truth and falseness of `event1` and `event2`, and the third digit represents whether `event1` is true or false and `event3` is true False and, and so on. If `event1` is false, return an array full of zeros.

#### Arguments
## Syntax

`event` — An expression that returns a `UInt8` result (1 or 0).
```sql
RETENTION(<event1> [, <event2>, ... , <eventN>]);
```

##### Returned value
## Parameters

An array of 1s and 0s with a maximum length of 32 bits, the final output array has the same length as the input parameter.
| Parameter | Description |
| -- | -- |
| `<eventN>` | The `N`th event condition, of type `UInt8` and value 1 or 0. |

1 — Condition was met for the event.
## Returned value

0 — Condition wasn’t met for the event.
An array of 1 and 0 with a maximum length of 32, where the final output array length matches the input parameter length.

### example
- 1: Condition is met.
- 0: Condition is not met.

```sql
DROP TABLE IF EXISTS retention_test;
## Examples

```sql
-- Create sample table
CREATE TABLE retention_test(
`uid` int COMMENT 'user id',
`date` datetime COMMENT 'date time'
)
DUPLICATE KEY(uid)
DISTRIBUTED BY HASH(uid) BUCKETS 3
`uid` int COMMENT 'user id',
`date` datetime COMMENT 'date time'
) DUPLICATE KEY(uid)
DISTRIBUTED BY HASH(uid) BUCKETS AUTO
PROPERTIES (
"replication_num" = "1"
);

INSERT into retention_test (uid, date) values (0, '2022-10-12'),
(0, '2022-10-13'),
(0, '2022-10-14'),
(1, '2022-10-12'),
(1, '2022-10-13'),
(2, '2022-10-12');

SELECT * from retention_test;

+------+---------------------+
| uid | date |
+------+---------------------+
| 0 | 2022-10-14 00:00:00 |
| 0 | 2022-10-13 00:00:00 |
| 0 | 2022-10-12 00:00:00 |
| 1 | 2022-10-13 00:00:00 |
| 1 | 2022-10-12 00:00:00 |
| 2 | 2022-10-12 00:00:00 |
+------+---------------------+

"replication_allocation" = "tag.location.default: 1"
);

-- Insert sample data
INSERT into retention_test values
(0, '2022-10-12'),
(0, '2022-10-13'),
(0, '2022-10-14'),
(1, '2022-10-12'),
(1, '2022-10-13'),
(2, '2022-10-12');

-- Calculate user retention
SELECT
uid,
retention(date = '2022-10-12')
AS r
FROM retention_test
GROUP BY uid
ORDER BY uid ASC;

+------+------+
| uid | r |
+------+------+
| 0 | [1] |
| 1 | [1] |
| 2 | [1] |
+------+------+

SELECT
uid,
retention(date = '2022-10-12', date = '2022-10-13')
AS r
FROM retention_test
GROUP BY uid
ORDER BY uid ASC;

+------+--------+
| uid | r |
+------+--------+
| 0 | [1, 1] |
| 1 | [1, 1] |
| 2 | [1, 0] |
+------+--------+

SELECT
uid,
retention(date = '2022-10-12', date = '2022-10-13', date = '2022-10-14')
AS r
FROM retention_test
GROUP BY uid
ORDER BY uid ASC;

+------+-----------+
| uid | r |
+------+-----------+
| 0 | [1, 1, 1] |
| 1 | [1, 1, 0] |
| 2 | [1, 0, 0] |
+------+-----------+

RETENTION(date = '2022-10-12') AS r,
RETENTION(date = '2022-10-12', date = '2022-10-13') AS r2,
RETENTION(date = '2022-10-12', date = '2022-10-13', date = '2022-10-14') AS r3
FROM retention_test
GROUP BY uid
ORDER BY uid ASC;
```

### keywords

RETENTION
```text
+------+------+--------+-----------+
| uid | r | r2 | r3 |
+------+------+--------+-----------+
| 0 | [1] | [1, 1] | [1, 1, 1] |
| 1 | [1] | [1, 1] | [1, 1, 0] |
| 2 | [1] | [1, 0] | [1, 0, 0] |
+------+------+--------+-----------+
```
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ under the License.
## 语法

```sql
retention(<event1> [, <event2>, ... , <eventN>]);
RETENTION(<event1> [, <event2>, ... , <eventN>]);
```

## 参数
@@ -75,9 +75,9 @@ INSERT into retention_test values
-- 计算用户留存
SELECT
uid,
retention(date = '2022-10-12') AS r,
retention(date = '2022-10-12', date = '2022-10-13') AS r2,
retention(date = '2022-10-12', date = '2022-10-13', date = '2022-10-14') AS r3
RETENTION(date = '2022-10-12') AS r,
RETENTION(date = '2022-10-12', date = '2022-10-13') AS r2,
RETENTION(date = '2022-10-12', date = '2022-10-13', date = '2022-10-14') AS r3
FROM retention_test
GROUP BY uid
ORDER BY uid ASC;
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ under the License.
## 语法

```sql
retention(<event1> [, <event2>, ... , <eventN>]);
RETENTION(<event1> [, <event2>, ... , <eventN>]);
```

## 参数
@@ -75,9 +75,9 @@ INSERT into retention_test values
-- 计算用户留存
SELECT
uid,
retention(date = '2022-10-12') AS r,
retention(date = '2022-10-12', date = '2022-10-13') AS r2,
retention(date = '2022-10-12', date = '2022-10-13', date = '2022-10-14') AS r3
RETENTION(date = '2022-10-12') AS r,
RETENTION(date = '2022-10-12', date = '2022-10-13') AS r2,
RETENTION(date = '2022-10-12', date = '2022-10-13', date = '2022-10-14') AS r3
FROM retention_test
GROUP BY uid
ORDER BY uid ASC;
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ under the License.
## 语法

```sql
retention(<event1> [, <event2>, ... , <eventN>]);
RETENTION(<event1> [, <event2>, ... , <eventN>]);
```

## 参数
@@ -75,9 +75,9 @@ INSERT into retention_test values
-- 计算用户留存
SELECT
uid,
retention(date = '2022-10-12') AS r,
retention(date = '2022-10-12', date = '2022-10-13') AS r2,
retention(date = '2022-10-12', date = '2022-10-13', date = '2022-10-14') AS r3
RETENTION(date = '2022-10-12') AS r,
RETENTION(date = '2022-10-12', date = '2022-10-13') AS r2,
RETENTION(date = '2022-10-12', date = '2022-10-13', date = '2022-10-14') AS r3
FROM retention_test
GROUP BY uid
ORDER BY uid ASC;
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ To put it simply, the first digit of the return value array indicates whether `e
## Syntax

```sql
retention(<event1> [, <event2>, ... , <eventN>]);
RETENTION(<event1> [, <event2>, ... , <eventN>]);
```

## Parameters
@@ -74,9 +74,9 @@ INSERT into retention_test values
-- Calculate user retention
SELECT
uid,
retention(date = '2022-10-12') AS r,
retention(date = '2022-10-12', date = '2022-10-13') AS r2,
retention(date = '2022-10-12', date = '2022-10-13', date = '2022-10-14') AS r3
RETENTION(date = '2022-10-12') AS r,
RETENTION(date = '2022-10-12', date = '2022-10-13') AS r2,
RETENTION(date = '2022-10-12', date = '2022-10-13', date = '2022-10-14') AS r3
FROM retention_test
GROUP BY uid
ORDER BY uid ASC;
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ To put it simply, the first digit of the return value array indicates whether `e
## Syntax

```sql
retention(<event1> [, <event2>, ... , <eventN>]);
RETENTION(<event1> [, <event2>, ... , <eventN>]);
```

## Parameters
@@ -74,9 +74,9 @@ INSERT into retention_test values
-- Calculate user retention
SELECT
uid,
retention(date = '2022-10-12') AS r,
retention(date = '2022-10-12', date = '2022-10-13') AS r2,
retention(date = '2022-10-12', date = '2022-10-13', date = '2022-10-14') AS r3
RETENTION(date = '2022-10-12') AS r,
RETENTION(date = '2022-10-12', date = '2022-10-13') AS r2,
RETENTION(date = '2022-10-12', date = '2022-10-13', date = '2022-10-14') AS r3
FROM retention_test
GROUP BY uid
ORDER BY uid ASC;