This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push:
new 13e26931008 [docs] Clarify version-specific ARRAY NULL ordering for
MIN/MAX and MIN_BY/MAX_BY (#4121)
13e26931008 is described below
commit 13e26931008fa6c2b47eaeaf3c125525b7e8952a
Author: Mryange <[email protected]>
AuthorDate: Sat Oct 17 05:38:58 2026 +0800
[docs] Clarify version-specific ARRAY NULL ordering for MIN/MAX and
MIN_BY/MAX_BY (#4121)
## Summary
Clarify array NULL ordering in MIN_BY/MAX_BY, distinguish NULL elements
from an entirely NULL array, and document the historical ordering
difference on 4.x MIN/MAX pages. Add self-contained examples.
## Versions
- [x] dev
- [x] 4.x
- [ ] 3.x
- [ ] 2.1 or older
Dev and 4.x, English and Chinese. In the Doris 4.1 series since 4.1.5,
and in 4.2/master, NULL array elements compare greater; 4.0 and 4.1
before 4.1.5 compare them smaller. Current MIN/MAX content was already
corrected on master, so those current pages are preserved; their 4.x
counterparts receive the additional historical-version explanation. 3.x
and older are outside this audit scope.
## Languages
- [x] Chinese
- [x] English
## Validation
Reviewed against Doris master `88f22fd875e0be4dea2c58c53744f4074378a870`
and the corresponding current 4.0, 4.1, and 4.2 source branches. Rebased
onto website master `f582020241f825849ffa3b57fc3220cb674d28a7`.
- SQL function structure and internal-link checks passed for the final
changed pages.
- `git diff --check` passed.
- English and Chinese changes are synchronized. Remaining version-sync
notices are explained above.
- Doris and the website were not built; examples were checked against
source and existing regression expectations where available.
---------
Co-authored-by: morningman <[email protected]>
---
.../sql-functions/aggregate-functions/max-by.md | 33 +++++++++++++++++-
.../sql-functions/aggregate-functions/min-by.md | 33 +++++++++++++++++-
.../sql-functions/aggregate-functions/max-by.md | 39 +++++++++++++++++++---
.../sql-functions/aggregate-functions/min-by.md | 39 +++++++++++++++++++---
.../sql-functions/aggregate-functions/max-by.md | 39 +++++++++++++++++++---
.../sql-functions/aggregate-functions/max.md | 18 +++++-----
.../sql-functions/aggregate-functions/min-by.md | 39 +++++++++++++++++++---
.../sql-functions/aggregate-functions/min.md | 18 +++++-----
.../sql-functions/aggregate-functions/max-by.md | 33 +++++++++++++++++-
.../sql-functions/aggregate-functions/max.md | 8 ++++-
.../sql-functions/aggregate-functions/min-by.md | 33 +++++++++++++++++-
.../sql-functions/aggregate-functions/min.md | 8 ++++-
12 files changed, 302 insertions(+), 38 deletions(-)
diff --git a/docs/sql-manual/sql-functions/aggregate-functions/max-by.md
b/docs/sql-manual/sql-functions/aggregate-functions/max-by.md
index 08c9eb52f32..f9d00738cf3 100644
--- a/docs/sql-manual/sql-functions/aggregate-functions/max-by.md
+++ b/docs/sql-manual/sql-functions/aggregate-functions/max-by.md
@@ -10,6 +10,10 @@
The MAX_BY function returns the associated value based on the maximum value of
the specified column.
+When `<expr2>` is an Array, arrays are compared lexicographically, element by
element; a NULL element is greater than any non-NULL element. A NULL array
value is ignored.
+
+Version difference: In the Doris 4.1 series since 4.1.5, and in Doris 4.2 and
later, a `NULL` element inside an array compares greater than a non-`NULL`
element. In Doris 4.0 and Doris 4.1 before 4.1.5, a `NULL` array element
compares smaller. A `NULL` array value is ignored in all these versions.
+
## Syntax
```sql
@@ -19,7 +23,7 @@ MAX_BY(<expr1>, <expr2>)
## Parameters
| Parameter | Description |
-| -- | -- |
+| --- | --- |
| `<expr1>` | The expression for the associated value, supports types: Bool,
TinyInt, SmallInt, Int, BigInt, LargeInt, Float, Double, Decimal, String, Date,
Datetime, TimestampNs, Array, Map, Struct. |
| `<expr2>` | The expression for the maximum value, supports types: Bool,
TinyInt, SmallInt, Int, BigInt, LargeInt, Float, Double, Decimal, String, Date,
Datetime, TimestampNs, Array. |
@@ -47,6 +51,10 @@ insert into tbl values
(3, 1, [8], {"x": 4, "y": 1}, NAMED_STRUCT("a", 4, "b", "r"));
```
+```text
+Table created and data inserted successfully.
+```
+
```sql
select max_by(k1, k2) from tbl;
```
@@ -94,3 +102,26 @@ select max_by(k1, k2) from tbl where k1 is null;
| NULL |
+----------------+
```
+
+The following array comparison example applies to the Doris 4.1 series since
4.1.5, and to Doris 4.2 and later.
+
+```sql
+SELECT max_by(label, sort_key) AS result
+FROM (
+ SELECT 'null element' AS label, [1, NULL] AS sort_key
+ UNION ALL SELECT 'non-null element', [1, 2]
+ UNION ALL SELECT 'null array', CAST(NULL AS ARRAY<INT>)
+) t;
+```
+
+```text
+null element
+```
+
+```sql
+SELECT max_by(1, CAST(NULL AS ARRAY<INT>)) AS result;
+```
+
+```text
+NULL
+```
diff --git a/docs/sql-manual/sql-functions/aggregate-functions/min-by.md
b/docs/sql-manual/sql-functions/aggregate-functions/min-by.md
index d0564ccfeef..9d586870ccb 100644
--- a/docs/sql-manual/sql-functions/aggregate-functions/min-by.md
+++ b/docs/sql-manual/sql-functions/aggregate-functions/min-by.md
@@ -10,6 +10,10 @@
The MIN_BY function returns the associated value based on the minimum value of
the specified column.
+When `<expr2>` is an Array, arrays are compared lexicographically, element by
element; a NULL element is greater than any non-NULL element. A NULL array
value is ignored.
+
+Version difference: In the Doris 4.1 series since 4.1.5, and in Doris 4.2 and
later, a `NULL` element inside an array compares greater than a non-`NULL`
element. In Doris 4.0 and Doris 4.1 before 4.1.5, a `NULL` array element
compares smaller. A `NULL` array value is ignored in all these versions.
+
## Syntax
```sql
@@ -19,7 +23,7 @@ MIN_BY(<expr1>, <expr2>)
## Parameters
| Parameter | Description |
-| -- | -- |
+| --- | --- |
| `<expr1>` | The expression for the associated value, supports types: Bool,
TinyInt, SmallInt, Int, BigInt, LargeInt, Float, Double, Decimal, String, Date,
Datetime, TimestampNs, Array, Map, Struct. |
| `<expr2>` | The expression for the minimum value, supports types: Bool,
TinyInt, SmallInt, Int, BigInt, LargeInt, Float, Double, Decimal, String, Date,
Datetime, TimestampNs, Array. |
@@ -47,6 +51,10 @@ insert into tbl values
(3, 1, [8], {"x": 4, "y": 1}, NAMED_STRUCT("a", 4, "b", "r"));
```
+```text
+Table created and data inserted successfully.
+```
+
```sql
select min_by(k1, k2) from tbl;
```
@@ -94,3 +102,26 @@ select min_by(k1, k2) from tbl where k1 is null;
| NULL |
+----------------+
```
+
+The following array comparison example applies to the Doris 4.1 series since
4.1.5, and to Doris 4.2 and later.
+
+```sql
+SELECT min_by(label, sort_key) AS result
+FROM (
+ SELECT 'null element' AS label, [1, NULL] AS sort_key
+ UNION ALL SELECT 'non-null element', [1, 2]
+ UNION ALL SELECT 'null array', CAST(NULL AS ARRAY<INT>)
+) t;
+```
+
+```text
+non-null element
+```
+
+```sql
+SELECT min_by(1, CAST(NULL AS ARRAY<INT>)) AS result;
+```
+
+```text
+NULL
+```
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/max-by.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/max-by.md
index ad537881fde..b8d21616d0e 100644
---
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/max-by.md
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/max-by.md
@@ -10,16 +10,20 @@
MAX_BY 函数用于根据指定列的最大值,返回对应的的关联值。
+当 `<expr2>` 为 Array 时,数组按字典序逐元素比较;数组元素中的 NULL 大于任何非 NULL 元素。整个数组为 NULL 时会被忽略。
+
+版本差异:Doris 4.1 系列自 4.1.5 起,以及 Doris 4.2 及后续版本中,数组内的 `NULL` 元素大于非 `NULL`
元素;Doris 4.0 和 4.1.5 之前的 4.1 版本中数组内的 `NULL` 元素小于非 `NULL` 元素。整个数组值为 `NULL`
的输入在这些版本中均被忽略。
+
## 语法
```sql
MAX_BY(<expr1>, <expr2>)
```
-## 参数说明
+## 参数 {#参数说明}
-| 参数 | 说明 |
-| -- | -- |
+| 参数 | 描述 |
+| --- | --- |
| `<expr1>` | 用于指定对应关联的表达式,支持
Bool、TinyInt、SmallInt、Int、BigInt、LargeInt、Float、Double、Decimal、String、Date、Datetime、TimestampNs、Array、Map、Struct。
|
| `<expr2>` | 用于指定最大值统计的表达式,支持
Bool、TinyInt、SmallInt、Int、BigInt、LargeInt、Float、Double、Decimal、String、Date、Datetime、TimestampNs、Array。
|
@@ -28,7 +32,7 @@ MAX_BY(<expr1>, <expr2>)
返回与输入表达式 <expr1> 相同的数据类型。
如果组内没有合法数据,则返回 NULL 。
-## 举例
+## 示例 {#举例}
```sql
-- setup
@@ -47,6 +51,10 @@ insert into tbl values
(3, 1, [8], {"x": 4, "y": 1}, NAMED_STRUCT("a", 4, "b", "r"));
```
+```text
+建表成功,数据已插入。
+```
+
```sql
select max_by(k1, k2) from tbl;
```
@@ -94,3 +102,26 @@ select max_by(k1, k2) from tbl where k1 is null;
| NULL |
+----------------+
```
+
+以下数组比较示例适用于 Doris 4.1 系列自 4.1.5 起,以及 Doris 4.2 及后续版本。
+
+```sql
+SELECT max_by(label, sort_key) AS result
+FROM (
+ SELECT 'null element' AS label, [1, NULL] AS sort_key
+ UNION ALL SELECT 'non-null element', [1, 2]
+ UNION ALL SELECT 'null array', CAST(NULL AS ARRAY<INT>)
+) t;
+```
+
+```text
+null element
+```
+
+```sql
+SELECT max_by(1, CAST(NULL AS ARRAY<INT>)) AS result;
+```
+
+```text
+NULL
+```
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/min-by.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/min-by.md
index 2b607fe539b..74a67b6cc13 100644
---
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/min-by.md
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/aggregate-functions/min-by.md
@@ -10,16 +10,20 @@
MIN_BY 函数用于根据指定列的最小值,返回对应的的关联值。
+当 `<expr2>` 为 Array 时,数组按字典序逐元素比较;数组元素中的 NULL 大于任何非 NULL 元素。整个数组为 NULL 时会被忽略。
+
+版本差异:Doris 4.1 系列自 4.1.5 起,以及 Doris 4.2 及后续版本中,数组内的 `NULL` 元素大于非 `NULL`
元素;Doris 4.0 和 4.1.5 之前的 4.1 版本中数组内的 `NULL` 元素小于非 `NULL` 元素。整个数组值为 `NULL`
的输入在这些版本中均被忽略。
+
## 语法
```sql
MIN_BY(<expr1>, <expr2>)
```
-## 参数说明
+## 参数 {#参数说明}
-| 参数 | 说明 |
-| -- | -- |
+| 参数 | 描述 |
+| --- | --- |
| `<expr1>` | 用于指定对应关联的表达式,支持
Bool、TinyInt、SmallInt、Int、BigInt、LargeInt、Float、Double、Decimal、String、Date、Datetime、TimestampNs、Array、Map、Struct。
|
| `<expr2>` | 用于指定最小值统计的表达式,支持
Bool、TinyInt、SmallInt、Int、BigInt、LargeInt、Float、Double、Decimal、String、Date、Datetime、TimestampNs、Array。
|
@@ -28,7 +32,7 @@ MIN_BY(<expr1>, <expr2>)
返回与输入表达式 <expr1> 相同的数据类型。
如果组内没有合法数据,则返回 NULL 。
-## 举例
+## 示例 {#举例}
```sql
-- setup
@@ -47,6 +51,10 @@ insert into tbl values
(3, 1, [8], {"x": 4, "y": 1}, NAMED_STRUCT("a", 4, "b", "r"));
```
+```text
+建表成功,数据已插入。
+```
+
```sql
select min_by(k1, k2) from tbl;
```
@@ -94,3 +102,26 @@ select min_by(k1, k2) from tbl where k1 is null;
| NULL |
+----------------+
```
+
+以下数组比较示例适用于 Doris 4.1 系列自 4.1.5 起,以及 Doris 4.2 及后续版本。
+
+```sql
+SELECT min_by(label, sort_key) AS result
+FROM (
+ SELECT 'null element' AS label, [1, NULL] AS sort_key
+ UNION ALL SELECT 'non-null element', [1, 2]
+ UNION ALL SELECT 'null array', CAST(NULL AS ARRAY<INT>)
+) t;
+```
+
+```text
+non-null element
+```
+
+```sql
+SELECT min_by(1, CAST(NULL AS ARRAY<INT>)) AS result;
+```
+
+```text
+NULL
+```
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max-by.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max-by.md
index f5d531ef835..9bc097d39be 100644
---
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max-by.md
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max-by.md
@@ -10,16 +10,20 @@
MAX_BY 函数用于根据指定列的最大值,返回对应的的关联值。
+当 `<expr2>` 为 Array 时,数组按字典序逐元素比较;数组元素中的 NULL 大于任何非 NULL 元素。整个数组为 NULL 时会被忽略。
+
+版本差异:Doris 4.1 系列自 4.1.5 起,以及 Doris 4.2 及后续版本中,数组内的 `NULL` 元素大于非 `NULL`
元素;Doris 4.0 和 4.1.5 之前的 4.1 版本中数组内的 `NULL` 元素小于非 `NULL` 元素。整个数组值为 `NULL`
的输入在这些版本中均被忽略。
+
## 语法
```sql
MAX_BY(<expr1>, <expr2>)
```
-## 参数说明
+## 参数 {#参数说明}
-| 参数 | 说明 |
-| -- | -- |
+| 参数 | 描述 |
+| --- | --- |
| `<expr1>` | 用于指定对应关联的表达式,支持类型为 Bool,
TinyInt,SmallInt,Int,BigtInt,LargeInt,Float,Double,Decimal, String, Date,
Datetime, Array, Map, Struct。 |
| `<expr2>` | 用于指定最大值统计的表达式,支持类型为 Bool,
TinyInt,SmallInt,Int,BigtInt,LargeInt,Float,Double,Decimal, String, Date,
Datetime, Array。 |
@@ -28,7 +32,7 @@ MAX_BY(<expr1>, <expr2>)
返回与输入表达式 <expr1> 相同的数据类型。
如果组内没有合法数据,则返回 NULL 。
-## 举例
+## 示例 {#举例}
```sql
-- setup
@@ -47,6 +51,10 @@ insert into tbl values
(3, 1, [8], {"x": 4, "y": 1}, NAMED_STRUCT("a", 4, "b", "r"));
```
+```text
+建表成功,数据已插入。
+```
+
```sql
select max_by(k1, k2) from tbl;
```
@@ -94,3 +102,26 @@ select max_by(k1, k2) from tbl where k1 is null;
| NULL |
+----------------+
```
+
+以下数组比较示例适用于 Doris 4.1 系列自 4.1.5 起,以及 Doris 4.2 及后续版本。
+
+```sql
+SELECT max_by(label, sort_key) AS result
+FROM (
+ SELECT 'null element' AS label, [1, NULL] AS sort_key
+ UNION ALL SELECT 'non-null element', [1, 2]
+ UNION ALL SELECT 'null array', CAST(NULL AS ARRAY<INT>)
+) t;
+```
+
+```text
+null element
+```
+
+```sql
+SELECT max_by(1, CAST(NULL AS ARRAY<INT>)) AS result;
+```
+
+```text
+NULL
+```
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max.md
index ec96689b6f6..d812025fae2 100644
---
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max.md
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max.md
@@ -10,18 +10,18 @@
MAX 函数返回表达式的最大非 NULL 值。
+版本差异:Doris 4.1 系列自 4.1.5 起,以及 Doris 4.2 及后续版本中,数组内的 `NULL` 元素大于非 `NULL`
元素;Doris 4.0 和 4.1.5 之前的 4.1 版本中数组内的 `NULL` 元素小于非 `NULL` 元素。整个数组值为 `NULL`
的输入在这些版本中均被忽略。
+
## 语法
```sql
MAX(<expr>)
```
-<a id="参数说明"></a>
-
-## 参数
+## 参数 {#参数说明}
-| 参数 | 说明 |
-| -- | -- |
+| 参数 | 描述 |
+| --- | --- |
| `<expr>` | 用于获取值的表达式。支持的类型包括
String、Time、Date、DateTime、Timestamptz、IPv4、IPv6、TinyInt、SmallInt、Integer、BigInt、LargeInt、Float、Double、Decimal、Array。
|
## 返回值
@@ -35,9 +35,7 @@ Doris 4.1 系列自 4.1.5 起,比较数组等复杂类型时,相同位置的
:::
-<a id="举例"></a>
-
-## 示例
+## 示例 {#举例}
```sql
-- setup
@@ -56,6 +54,10 @@ insert into t1 values
(3, null, null, null);
```
+```text
+建表成功,数据已插入。
+```
+
```sql
select k1, max(k_string) from t1 group by k1 order by k1;
```
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min-by.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min-by.md
index 43eaa10dd09..2dbbaa5ee1c 100644
---
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min-by.md
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min-by.md
@@ -10,16 +10,20 @@
MIN_BY 函数用于根据指定列的最小值,返回对应的的关联值。
+当 `<expr2>` 为 Array 时,数组按字典序逐元素比较;数组元素中的 NULL 大于任何非 NULL 元素。整个数组为 NULL 时会被忽略。
+
+版本差异:Doris 4.1 系列自 4.1.5 起,以及 Doris 4.2 及后续版本中,数组内的 `NULL` 元素大于非 `NULL`
元素;Doris 4.0 和 4.1.5 之前的 4.1 版本中数组内的 `NULL` 元素小于非 `NULL` 元素。整个数组值为 `NULL`
的输入在这些版本中均被忽略。
+
## 语法
```sql
MIN_BY(<expr1>, <expr2>)
```
-## 参数说明
+## 参数 {#参数说明}
-| 参数 | 说明 |
-| -- | -- |
+| 参数 | 描述 |
+| --- | --- |
| `<expr1>` | 用于指定对应关联的表达式,支持类型为 Bool,
TinyInt,SmallInt,Int,BigtInt,LargeInt,Float,Double,Decimal, String, Date,
Datetime, Array, Map, Struct。 |
| `<expr2>` | 用于指定最小值统计的表达式,支持类型为 Bool,
TinyInt,SmallInt,Int,BigtInt,LargeInt,Float,Double,Decimal, String, Date,
Datetime, Array。 |
@@ -28,7 +32,7 @@ MIN_BY(<expr1>, <expr2>)
返回与输入表达式 <expr1> 相同的数据类型。
如果组内没有合法数据,则返回 NULL 。
-## 举例
+## 示例 {#举例}
```sql
-- setup
@@ -47,6 +51,10 @@ insert into tbl values
(3, 1, [8], {"x": 4, "y": 1}, NAMED_STRUCT("a", 4, "b", "r"));
```
+```text
+建表成功,数据已插入。
+```
+
```sql
select min_by(k1, k2) from tbl;
```
@@ -94,3 +102,26 @@ select min_by(k1, k2) from tbl where k1 is null;
| NULL |
+----------------+
```
+
+以下数组比较示例适用于 Doris 4.1 系列自 4.1.5 起,以及 Doris 4.2 及后续版本。
+
+```sql
+SELECT min_by(label, sort_key) AS result
+FROM (
+ SELECT 'null element' AS label, [1, NULL] AS sort_key
+ UNION ALL SELECT 'non-null element', [1, 2]
+ UNION ALL SELECT 'null array', CAST(NULL AS ARRAY<INT>)
+) t;
+```
+
+```text
+non-null element
+```
+
+```sql
+SELECT min_by(1, CAST(NULL AS ARRAY<INT>)) AS result;
+```
+
+```text
+NULL
+```
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min.md
index b42848b3397..330a99af3ec 100644
---
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min.md
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min.md
@@ -10,18 +10,18 @@
MIN 函数返回表达式的最小非 NULL 值。
+版本差异:Doris 4.1 系列自 4.1.5 起,以及 Doris 4.2 及后续版本中,数组内的 `NULL` 元素大于非 `NULL`
元素;Doris 4.0 和 4.1.5 之前的 4.1 版本中数组内的 `NULL` 元素小于非 `NULL` 元素。整个数组值为 `NULL`
的输入在这些版本中均被忽略。
+
## 语法
```sql
MIN(<expr>)
```
-<a id="参数说明"></a>
-
-## 参数
+## 参数 {#参数说明}
-| 参数 | 说明 |
-| -- | -- |
+| 参数 | 描述 |
+| --- | --- |
| `<expr>` | 用于计算的表达式。支持的类型包括
String、Time、Date、DateTime、Timestamptz、IPv4、IPv6、TinyInt、SmallInt、Integer、BigInt、LargeInt、Float、Double、Decimal、Array。
|
## 返回值
@@ -35,9 +35,7 @@ Doris 4.1 系列自 4.1.5 起,比较数组等复杂类型时,相同位置的
:::
-<a id="举例"></a>
-
-## 示例
+## 示例 {#举例}
```sql
-- setup
@@ -56,6 +54,10 @@ insert into t1 values
(3, null, null, null);
```
+```text
+建表成功,数据已插入。
+```
+
```sql
select k1, min(k_string) from t1 group by k1 order by k1;
```
diff --git
a/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max-by.md
b/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max-by.md
index f909435a898..5bd095384f4 100644
---
a/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max-by.md
+++
b/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max-by.md
@@ -10,6 +10,10 @@
The MAX_BY function returns the associated value based on the maximum value of
the specified column.
+When `<expr2>` is an Array, arrays are compared lexicographically, element by
element; a NULL element is greater than any non-NULL element. A NULL array
value is ignored.
+
+Version difference: In the Doris 4.1 series since 4.1.5, and in Doris 4.2 and
later, a `NULL` element inside an array compares greater than a non-`NULL`
element. In Doris 4.0 and Doris 4.1 before 4.1.5, a `NULL` array element
compares smaller. A `NULL` array value is ignored in all these versions.
+
## Syntax
```sql
@@ -19,7 +23,7 @@ MAX_BY(<expr1>, <expr2>)
## Parameters
| Parameter | Description |
-| -- | -- |
+| --- | --- |
| `<expr1>` | The expression for the associated value, supports types: Bool,
TinyInt, SmallInt, Int, BigInt, LargeInt, Float, Double, Decimal, String, Date,
Datetime, Array, Map, Struct. |
| `<expr2>` | The expression for the maximum value, supports types: Bool,
TinyInt, SmallInt, Int, BigInt, LargeInt, Float, Double, Decimal, String, Date,
Datetime, Array. |
@@ -47,6 +51,10 @@ insert into tbl values
(3, 1, [8], {"x": 4, "y": 1}, NAMED_STRUCT("a", 4, "b", "r"));
```
+```text
+Table created and data inserted successfully.
+```
+
```sql
select max_by(k1, k2) from tbl;
```
@@ -94,3 +102,26 @@ select max_by(k1, k2) from tbl where k1 is null;
| NULL |
+----------------+
```
+
+The following array comparison example applies to the Doris 4.1 series since
4.1.5, and to Doris 4.2 and later.
+
+```sql
+SELECT max_by(label, sort_key) AS result
+FROM (
+ SELECT 'null element' AS label, [1, NULL] AS sort_key
+ UNION ALL SELECT 'non-null element', [1, 2]
+ UNION ALL SELECT 'null array', CAST(NULL AS ARRAY<INT>)
+) t;
+```
+
+```text
+null element
+```
+
+```sql
+SELECT max_by(1, CAST(NULL AS ARRAY<INT>)) AS result;
+```
+
+```text
+NULL
+```
diff --git
a/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max.md
b/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max.md
index 2b0bfd8de9e..c3273a10d51 100644
---
a/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max.md
+++
b/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/max.md
@@ -10,6 +10,8 @@
The MAX function returns the maximum non-NULL value of the expression.
+Version difference: In the Doris 4.1 series since 4.1.5, and in Doris 4.2 and
later, a `NULL` element inside an array compares greater than a non-`NULL`
element. In Doris 4.0 and Doris 4.1 before 4.1.5, a `NULL` array element
compares smaller. A `NULL` array value is ignored in all these versions.
+
## Syntax
```sql
@@ -19,7 +21,7 @@ MAX(<expr>)
## Parameters
| Parameter | Description |
-| -- | -- |
+| --- | --- |
| `<expr>` | The expression to get the value. Supported types are String,
Time, Date, DateTime, Timestamptz, IPv4, IPv6, TinyInt, SmallInt, Integer,
BigInt, LargeInt, Float, Double, Decimal, Array. |
## Return Value
@@ -53,6 +55,10 @@ insert into t1 values
(3, null, null, null);
```
+```text
+Table created and data inserted successfully.
+```
+
```sql
select k1, max(k_string) from t1 group by k1 order by k1;
```
diff --git
a/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min-by.md
b/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min-by.md
index c1a4a7d1b5c..cce5d69bfdd 100644
---
a/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min-by.md
+++
b/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min-by.md
@@ -10,6 +10,10 @@
The MIN_BY function returns the associated value based on the minimum value of
the specified column.
+When `<expr2>` is an Array, arrays are compared lexicographically, element by
element; a NULL element is greater than any non-NULL element. A NULL array
value is ignored.
+
+Version difference: In the Doris 4.1 series since 4.1.5, and in Doris 4.2 and
later, a `NULL` element inside an array compares greater than a non-`NULL`
element. In Doris 4.0 and Doris 4.1 before 4.1.5, a `NULL` array element
compares smaller. A `NULL` array value is ignored in all these versions.
+
## Syntax
```sql
@@ -19,7 +23,7 @@ MIN_BY(<expr1>, <expr2>)
## Parameters
| Parameter | Description |
-| -- | -- |
+| --- | --- |
| `<expr1>` | The expression for the associated value, supports types: Bool,
TinyInt, SmallInt, Int, BigInt, LargeInt, Float, Double, Decimal, String, Date,
Datetime, Array, Map, Struct. |
| `<expr2>` | The expression for the minimum value, supports types: Bool,
TinyInt, SmallInt, Int, BigInt, LargeInt, Float, Double, Decimal, String, Date,
Datetime, Array. |
@@ -47,6 +51,10 @@ insert into tbl values
(3, 1, [8], {"x": 4, "y": 1}, NAMED_STRUCT("a", 4, "b", "r"));
```
+```text
+Table created and data inserted successfully.
+```
+
```sql
select min_by(k1, k2) from tbl;
```
@@ -94,3 +102,26 @@ select min_by(k1, k2) from tbl where k1 is null;
| NULL |
+----------------+
```
+
+The following array comparison example applies to the Doris 4.1 series since
4.1.5, and to Doris 4.2 and later.
+
+```sql
+SELECT min_by(label, sort_key) AS result
+FROM (
+ SELECT 'null element' AS label, [1, NULL] AS sort_key
+ UNION ALL SELECT 'non-null element', [1, 2]
+ UNION ALL SELECT 'null array', CAST(NULL AS ARRAY<INT>)
+) t;
+```
+
+```text
+non-null element
+```
+
+```sql
+SELECT min_by(1, CAST(NULL AS ARRAY<INT>)) AS result;
+```
+
+```text
+NULL
+```
diff --git
a/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min.md
b/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min.md
index b5d4edde754..2bc1116f5c0 100644
---
a/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min.md
+++
b/versioned_docs/version-4.x/sql-manual/sql-functions/aggregate-functions/min.md
@@ -10,6 +10,8 @@
The MIN function returns the minimum non-NULL value of the expression.
+Version difference: In the Doris 4.1 series since 4.1.5, and in Doris 4.2 and
later, a `NULL` element inside an array compares greater than a non-`NULL`
element. In Doris 4.0 and Doris 4.1 before 4.1.5, a `NULL` array element
compares smaller. A `NULL` array value is ignored in all these versions.
+
## Syntax
```sql
@@ -19,7 +21,7 @@ MIN(<expr>)
## Parameters
| Parameter | Description |
-| -- | -- |
+| --- | --- |
| `<expr>` | The expression to get the value. Supported types are String,
Time, Date, DateTime, Timestamptz, IPv4, IPv6, TinyInt, SmallInt, Integer,
BigInt, LargeInt, Float, Double, Decimal, Array. |
## Return Value
@@ -52,6 +54,10 @@ insert into t1 values
(3, null, null, null);
```
+```text
+Table created and data inserted successfully.
+```
+
```sql
select k1, min(k_string) from t1 group by k1 order by k1;
```
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]