HappenLee commented on code in PR #2071:
URL: https://github.com/apache/doris-website/pull/2071#discussion_r1959127348


##########
i18n/zh-CN/docusaurus-plugin-content-docs/current/query-acceleration/dictionary.md:
##########
@@ -0,0 +1,434 @@
+---
+{
+    "title": "字典表(实验性功能)",
+    "language": "zh-CN"
+}
+---
+
+<!-- 
+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.
+-->
+
+## 概述
+
+字典表(Dictionary)是 Doris 提供的一种用于加速 JOIN 
操作的特殊数据结构。它通过将常用的键值对预先加载到内存中,实现快速的查找操作,从而提升查询性能。字典表特别适用于需要频繁进行键值查找的场景。
+
+## 使用场景
+
+字典表主要适用于以下场景:
+
+1. 需要频繁进行键值查找的场景
+2. 维度表较小,可以完全加载到内存中
+3. 数据更新频率相对较低的场景
+4. 需要优化 JOIN 操作性能的场景
+
+## 字典表定义
+
+### 基本语法
+
+```sql
+CREATE DICTIONARY <dict_name> USING <source_table>
+(
+    <key_column> KEY[,
+    ...,
+    <key_columns> VALUE]
+    <value_column> VALUE[,
+    ...,
+    <value_columns> VALUE]
+)
+LAYOUT(<layout_type>)
+PROPERTIES(
+    "<priority_item_key>" = "<priority_item_value>"[,
+    ...,
+    "<priority_item_key>" = "<priority_item_value>"]
+);
+```
+
+其中:
+
+- `<dict_name>`:字典表的名字
+- `<source_table>`:源数据表
+- `<key_column>`:作为键的列在源表中的列名
+- `<value_column>`:作为值的列在源表中的列名
+- `<layout_type>`:字典表的存储布局类型,详见后文。
+- `<priority_item_key>`:表的某项属性名
+- `<priority_item_value>`:表的某项属性取值
+
+`<key_column>` 不必出现在 `<value_column>` 前。
+
+### 布局类型
+
+目前支持两种布局类型:
+
+- `HASH_MAP`:基于哈希表的实现,适用于一般的键值查找场景
+- `IP_TRIE`:基于 Trie 树的实现,专门优化用于 IP 地址类型的查找。Key 列需要为 CIDR 表示法表示的 IP 地址,查询时依 
CIDR 表示法匹配。
+
+### 属性
+
+当前字典仅有一项允许且必须出现的属性:
+
+|属性名|值类型|含义|
+|-|-|-|
+|`date_lifetime`|整数,单位为秒|数据有效期。当该字典上次更新距今时间超过该值时,将会自动发起重新导入|
+
+### 示例
+
+```sql
+-- 创建源数据表
+CREATE TABLE source_table (
+    id INT NOT NULL,
+    city VARCHAR(32) NOT NULL,
+    code VARCHAR(32) NOT NULL
+) ENGINE=OLAP
+DISTRIBUTED BY HASH(id) BUCKETS 1
+PROPERTIES("replication_num" = "1");
+
+-- 创建字典表
+CREATE DICTIONARY city_dict USING source_table
+(
+    city KEY,
+    id VALUE
+)
+LAYOUT(HASH_MAP)
+PROPERTIES('data_lifetime' = '600');
+```
+
+基于该表,我们可以使用字典 `city_dict` 通过 `dict_get` 函数,基于 `source_table` 的 `city` 值查询对应的 
`id`。
+
+### 使用限制
+
+1. Key 列
+
+   - IP_TRIE 类型字典的 Key 列必须为 Varchar 或 String 类型,**Key 列中的值必须为 CIDR 格式**。
+   - HASH_MAP 类型字典的 Key 列支持所有简单类型(即排除所有 Map、Array 等嵌套类型)。
+   - 作为 Key 列的列,**在源表中不得存在重复值**,否则字典导入数据时将报错。
+
+2. Nullable 属性
+
+   - 所有 Key 列必须为 NOT NULLABLE, Value 列无限制。

Review Comment:
   rethink the require



##########
i18n/zh-CN/docusaurus-plugin-content-docs/current/query-acceleration/dictionary.md:
##########
@@ -0,0 +1,434 @@
+---
+{
+    "title": "字典表(实验性功能)",
+    "language": "zh-CN"
+}
+---
+
+<!-- 
+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.
+-->
+
+## 概述
+
+字典表(Dictionary)是 Doris 提供的一种用于加速 JOIN 
操作的特殊数据结构。它通过将常用的键值对预先加载到内存中,实现快速的查找操作,从而提升查询性能。字典表特别适用于需要频繁进行键值查找的场景。
+
+## 使用场景
+
+字典表主要适用于以下场景:
+
+1. 需要频繁进行键值查找的场景
+2. 维度表较小,可以完全加载到内存中
+3. 数据更新频率相对较低的场景
+4. 需要优化 JOIN 操作性能的场景
+
+## 字典表定义
+
+### 基本语法
+
+```sql
+CREATE DICTIONARY <dict_name> USING <source_table>
+(
+    <key_column> KEY[,
+    ...,
+    <key_columns> VALUE]
+    <value_column> VALUE[,
+    ...,
+    <value_columns> VALUE]
+)
+LAYOUT(<layout_type>)
+PROPERTIES(
+    "<priority_item_key>" = "<priority_item_value>"[,
+    ...,
+    "<priority_item_key>" = "<priority_item_value>"]
+);
+```
+
+其中:
+
+- `<dict_name>`:字典表的名字
+- `<source_table>`:源数据表
+- `<key_column>`:作为键的列在源表中的列名
+- `<value_column>`:作为值的列在源表中的列名
+- `<layout_type>`:字典表的存储布局类型,详见后文。
+- `<priority_item_key>`:表的某项属性名
+- `<priority_item_value>`:表的某项属性取值
+
+`<key_column>` 不必出现在 `<value_column>` 前。
+
+### 布局类型
+
+目前支持两种布局类型:
+
+- `HASH_MAP`:基于哈希表的实现,适用于一般的键值查找场景
+- `IP_TRIE`:基于 Trie 树的实现,专门优化用于 IP 地址类型的查找。Key 列需要为 CIDR 表示法表示的 IP 地址,查询时依 
CIDR 表示法匹配。
+
+### 属性
+
+当前字典仅有一项允许且必须出现的属性:
+
+|属性名|值类型|含义|
+|-|-|-|
+|`date_lifetime`|整数,单位为秒|数据有效期。当该字典上次更新距今时间超过该值时,将会自动发起重新导入|
+
+### 示例
+
+```sql
+-- 创建源数据表
+CREATE TABLE source_table (
+    id INT NOT NULL,
+    city VARCHAR(32) NOT NULL,
+    code VARCHAR(32) NOT NULL
+) ENGINE=OLAP
+DISTRIBUTED BY HASH(id) BUCKETS 1
+PROPERTIES("replication_num" = "1");
+
+-- 创建字典表
+CREATE DICTIONARY city_dict USING source_table
+(
+    city KEY,
+    id VALUE
+)
+LAYOUT(HASH_MAP)
+PROPERTIES('data_lifetime' = '600');
+```
+
+基于该表,我们可以使用字典 `city_dict` 通过 `dict_get` 函数,基于 `source_table` 的 `city` 值查询对应的 
`id`。
+
+### 使用限制
+
+1. Key 列
+
+   - IP_TRIE 类型字典的 Key 列必须为 Varchar 或 String 类型,**Key 列中的值必须为 CIDR 格式**。
+   - HASH_MAP 类型字典的 Key 列支持所有简单类型(即排除所有 Map、Array 等嵌套类型)。
+   - 作为 Key 列的列,**在源表中不得存在重复值**,否则字典导入数据时将报错。
+
+2. Nullable 属性
+
+   - 所有 Key 列必须为 NOT NULLABLE, Value 列无限制。
+
+## 使用与管理
+
+### 导入(刷新)数据
+
+字典支持自动与手动导入。
+
+#### 自动导入
+
+自动导入发生在以下时机:
+
+1. 字典建立以后
+2. 字典数据过期时(见[属性](#属性))
+3. BE 状态显示丢失该字典数据(有新 BE 上线,或旧 BE 重启等均有可能造成)
+
+#### 手动导入
+
+Doris 支持通过以下命令手动刷新字典的数据:
+
+```sql
+REFRESH DICTIONARY <dict_name>;
+```
+
+其中 `<dict_name>` 为要导入数据的字典名。
+
+#### 导入注意事项
+
+1. 只有导入数据后的字典才可以查询。
+2. 如果导入时 Key 列具有重复值,导入事务会失败。
+3. 如果导入的数据版本早于 BE 已有的版本,则事务会失败。
+4. 如果当前已经有导入事务正在进行(字典 Status 为 `LOADING` ),则手动进行的导入会失败。请等待正在进行的导入完成后操作。
+
+### 查询字典
+
+可以分别使用 `dict_get` 和 `dict_get_many` 函数进行单一 Key、Value 列和多 Key、Value 列的字典表查询。
+
+#### 语法
+
+```sql
+VALUE_TYPE dict_get("<db_name>.<dict_name>", "<query_column>", 
<query_key_value>);
+STRUCT<VALUE_TYPES> dict_get_many("<db_name>.<dict_name>", ARRAY<VARCHAR> 
<query_columns>, STRUCT <query_key_values>);
+```
+
+其中:
+
+- `<db_name>` 为字典所在的 database 名
+- `<dict_name>` 为字典名
+- `<query_columns>` 为要查询的 value 列列名
+- `<query_key_value>` 为用来查询的 key 列数据
+- `<value_col_names>` 为一个包含要查询的 value 列列名的常量数组
+- `<query_key_values>` 为一个包含该字典所有 key 列对应数据的 STRUCT
+
+`dict_get` 的返回类型为 `<query_column>` 对应的字典列类型。
+`dict_get_many` 的返回类型为 `<query_columns>` 对应的各个字典列类型所组成的 STRUCT。
+
+#### 查询示例
+
+该语句查询 `test_db` database 内的字典 `city_dict`,查询 key 列值为 "Beijing" 时的对应 `id` 列值:
+
+```sql
+SELECT dict_get("test_db.city_dict", "id", "Beijing");
+```
+
+该语句查询 `test_db` database 内的字典 `single_key_dict`,查询 key 列值为 1 时的对应 `k1` 和 `k3` 
列值:
+
+```sql
+SELECT dict_get_many("test_db.single_key_dict", ["k1", "k3"], struct(1));
+```
+
+该语句查询 `test_db` database 内的字典 `multi_key_dict`,查询 2 个 key 列值依次为 2 和 'ABC' 时的对应 
`k1` 和 `k3` 列值:
+
+```sql
+SELECT dict_get_many("test_db.multi_key_dict", ["k2", "k3"], struct(2, 'ABC'));
+```
+
+例如建表语句如下:
+
+```sql
+create table if not exists multi_key_table(
+    k0 int not null,
+    k1 varchar not null,
+    k2 float not null,
+    k3 varchar not null
+)
+DISTRIBUTED BY HASH(`k0`) BUCKETS auto
+properties("replication_num" = "1");
+
+create dictionary multi_key_dict using multi_key_table
+(
+    k0 KEY,
+    k1 KEY,
+    k2 VALUE,
+    k3 VALUE
+)
+LAYOUT(HASH_MAP)
+PROPERTIES('data_lifetime' = '600');
+```
+
+则上述语句
+
+```sql
+SELECT dict_get_many("test_db.multi_key_dict", ["k2", "k3"], struct(2, 'ABC'));
+```
+
+的返回值类型为 `STRUCT<float, varchar>`。
+
+#### 查询注意事项
+
+1. 当查询的 Key 数据不存在于字典表内时,返回值为 `<query_column>` 的类型**默认值**。

Review Comment:
   change the doc



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to