Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
---

Check notice on line 1 in docs/sql-manual/sql-functions/aggregate-functions/bitmap-union-int.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-version-candidate

A 3.x counterpart exists. Confirm whether the change is supported in 3.x before leaving it unsynced. Owner%3A @apache/doris-website-maintainers

Check warning on line 1 in docs/sql-manual/sql-functions/aggregate-functions/bitmap-union-int.md

View workflow job for this annotation

GitHub Actions / Build Check

i18n-sync-version-counterpart

English current and 4.x docs are strongly synchronized. Update the counterpart or explain the version-specific exception in the PR description. Owner%3A @apache/doris-website-maintainers

Check warning on line 1 in docs/sql-manual/sql-functions/aggregate-functions/bitmap-union-int.md

View workflow job for this annotation

GitHub Actions / Build Check

seo-title-duplicate

Rendered SEO title is duplicated across indexable pages%3A "BITMAP-UNION-INT - Apache Doris". Add a version%2C locale%2C or page-specific qualifier. Owner%3A @apache/doris-website-maintainers
{
"title": "BITMAP-UNION-INT",
"language": "en",
"description": "Counts the number of distinct values in the input expression. The return value is the same as COUNT(DISTINCT expr)."
"description": "Counts distinct nonnegative integers in the input expression, ignoring negative values and NULLs."
}
---

## Description

Counts the number of distinct values in the input expression. The return value is the same as COUNT(DISTINCT expr).
Counts distinct nonnegative integers in the input expression, ignoring negative values and NULLs.

For supported integer inputs, this is equivalent to `COUNT(DISTINCT CASE WHEN expr >= 0 THEN expr END)` and to `BITMAP_COUNT(BITMAP_AGG(expr))`. It is equivalent to `COUNT(DISTINCT expr)` only when the input contains no negative values.

## Usage Notes

Ignoring negative values is the behavior of the development version. Earlier releases may count negative values; queries containing negative inputs can therefore return different results after upgrading.

## Syntax

```sql
BITMAP_UNION_INT(<expr>)
```

## Arguments
## Parameters

| Argument | Description |
| -- | -- |
| Parameter | Description |
| --- | --- |
| `<expr>` | The input expression. Supported types: TinyInt, SmallInt, Integer. |

## Return Value

Returns the number of distinct values in the column. If there is no valid data in the group, returns 0.
Returns a BIGINT containing the number of distinct nonnegative integers. NULLs and negative values are ignored. Returns 0 for empty input or a group containing only NULLs and negative values; the result is never NULL.

## Example

Expand All @@ -44,6 +50,11 @@
(2, 200, to_bitmap(300));
```

```text
Query OK, 0 rows affected
Query OK, 5 rows affected
```

```sql
select bitmap_union_int(dt) from pv_bitmap;
```
Expand All @@ -66,4 +77,37 @@
+----------------------+
| 0 |
+----------------------+
```
```

Negative integers are excluded while zero is included:

```sql
SELECT bitmap_union_int(x) AS nonnegative_count
FROM (
SELECT -1 AS x UNION ALL SELECT 0 UNION ALL SELECT 1
UNION ALL SELECT 1 UNION ALL SELECT NULL
) AS input;
```

```text
+-------------------+
| nonnegative_count |
+-------------------+
| 2 |
+-------------------+
```

A group with only negative values and NULLs returns zero:

```sql
SELECT bitmap_union_int(x) AS nonnegative_count
FROM (SELECT -1 AS x UNION ALL SELECT -2 UNION ALL SELECT NULL) AS input;
```

```text
+-------------------+
| nonnegative_count |
+-------------------+
| 0 |
+-------------------+
```
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
---

Check warning on line 1 in i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/bitmap-union-int.md

View workflow job for this annotation

GitHub Actions / Build Check

seo-title-duplicate

Rendered SEO title is duplicated across indexable pages%3A "BITMAP-UNION-INT - Apache Doris". Add a version%2C locale%2C or page-specific qualifier. Owner%3A @apache/doris-website-maintainers

Check warning on line 1 in i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/bitmap-union-int.md

View workflow job for this annotation

GitHub Actions / Build Check

seo-description-length

SEO description should be 80-160 characters; current length is 29. Owner%3A @apache/doris-website-maintainers
{
"title": "BITMAP-UNION-INT",
"language": "zh-CN",
"description": "计算输入的表达式中不同值的个数,返回值和 COUNT(DISTINCT expr) 相同。"
"description": "计算输入表达式中不同非负整数的个数,忽略负数和 NULL。"
}
---

## 描述

计算输入的表达式中不同值的个数,返回值和 COUNT(DISTINCT expr) 相同。
计算输入表达式中不同非负整数的个数,忽略负数和 NULL。

对于支持的整数类型,结果等价于 `COUNT(DISTINCT CASE WHEN expr >= 0 THEN expr END)` 和 `BITMAP_COUNT(BITMAP_AGG(expr))`。只有输入不包含负数时,结果才与 `COUNT(DISTINCT expr)` 相同。

## 使用说明

忽略负数是开发版本的行为。早期版本可能将负数计入结果,因此升级后,包含负数的查询可能返回不同的结果。

## 语法

Expand All @@ -18,16 +24,15 @@

## 参数

| 参数 | 说明 |
| -- | -- |
| 参数 | 描述 |
| --- | --- |
| `<expr>` | 输入的表达式,支持类型为 TinyInt,SmallInt,Integer。 |

## 返回值

返回列中不同值的个数。
组内没有合法数据时,返回 0 。
返回 BIGINT 类型,表示不同非负整数的个数。忽略 NULL 和负数。输入为空或组内只有 NULL 和负数时,返回 0;结果不会为 NULL。

## 举例
## 示例

```sql
-- setup
Expand All @@ -45,6 +50,11 @@
(2, 200, to_bitmap(300));
```

```text
Query OK, 0 rows affected
Query OK, 5 rows affected
```

```sql
select bitmap_union_int(dt) from pv_bitmap;
```
Expand All @@ -68,3 +78,36 @@
| 0 |
+----------------------+
```

负数不计入结果,零计入结果:

```sql
SELECT bitmap_union_int(x) AS nonnegative_count
FROM (
SELECT -1 AS x UNION ALL SELECT 0 UNION ALL SELECT 1
UNION ALL SELECT 1 UNION ALL SELECT NULL
) AS input;
```

```text
+-------------------+
| nonnegative_count |
+-------------------+
| 2 |
+-------------------+
```

组内只有负数和 NULL 时返回零:

```sql
SELECT bitmap_union_int(x) AS nonnegative_count
FROM (SELECT -1 AS x UNION ALL SELECT -2 UNION ALL SELECT NULL) AS input;
```

```text
+-------------------+
| nonnegative_count |
+-------------------+
| 0 |
+-------------------+
```
Loading