Skip to content

Commit ea30894

Browse files
💬Generate LLM translations (#1953)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent b17ec51 commit ea30894

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

docs/cn/sql-reference/10-sql-commands/00-ddl/17-dictionary/create-dictionary.md

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import FunctionDescription from '@site/src/components/FunctionDescription';
55

66
<FunctionDescription description="Introduced or updated: v1.2.636"/>
77

8-
使用指定的源创建字典
8+
创建一个字典,支持从外部源实时访问数据。字典允许 Databend 直接从 MySQL 和 Redis 等外部系统查询数据,而无需传统的 ETL 流程,从而确保数据一致性并提高查询性能
99

1010
## 语法
1111

@@ -20,15 +20,17 @@ PRIMARY KEY <primary_key_column>
2020
SOURCE(<source_type>(<source_parameters>))
2121
```
2222

23+
创建字典时,Databend 会建立与指定外部数据源的连接。然后可以使用 `dict_get()` 函数查询字典,以在查询时直接从源检索数据。
24+
2325
| 参数 | 描述 |
24-
|------------------------|----------------------------------------------------------------------------------------------------------------------------|
25-
| `<dictionary_name>` | 字典的名称 |
26-
| `<column_name>` | 字典中列的名称。 |
27-
| `<data_type>` | 存储在列中的数据类型。 |
28-
| `<default-value>` | 指定列的默认值,以便在从源填充字典时未提供值的情况下使用|
29-
| `<primary_key_column>` | 用于快速查找的主键列。此键应对应于字典中每个条目的唯一值。 |
30-
| `<source_type>` | 指定数据源的类型,`MYSQL``REDIS`|
31-
| `<source_parameters>` | 定义指定源类型所需的配置参数|
26+
|------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
27+
| `<dictionary_name>` | 字典的名称,在查询中被引用。 |
28+
| `<column_name>` | 字典中列的名称。这些列定义了可以从外部源检索的数据的结构。 |
29+
| `<data_type>` | 每列的数据类型。对于 MySQL 源,Databend 支持 boolean、string 和 numeric 类型(包括 int、bigint、float32、float64)。对于 Redis 源,仅支持 string 类型。 |
30+
| `<default-value>` | 当在外部源中找不到值时,列的可选默认值。这确保了即使缺少数据,查询也能返回有意义的结果|
31+
| `<primary_key_column>` | 查询字典时用作查找键的列。这应对应于外部数据源中的唯一标识符。 |
32+
| `<source_type>` | 外部数据源的类型。当前支持:`MYSQL``REDIS`。未来版本将支持其他源|
33+
| `<source_parameters>` | 特定于所选源类型的连接和配置参数|
3234

3335
### MySQL 参数
3436

@@ -48,15 +50,17 @@ SOURCE(<source_type>(<source_parameters>))
4850
下表列出了配置 Redis 数据源所需的和可选的参数:
4951

5052
| 参数 | 是否必需? | 描述 |
51-
|-----------|-----------|-----------------------------------------------------------------------------------------------------------------------------|
53+
|-----------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------|
5254
| host || Redis 服务器的主机名或 IP 地址。 |
5355
| port || Redis 服务器的端口号。 |
5456
| username || 如果 Redis 服务器需要用户身份验证,则为用户名。 |
5557
| password || 用于用户身份验证的密码。 |
56-
| db_index || 指定 Redis 数据库索引,默认为 0。索引范围为 0 到 15,因为 Redis 支持从 0 到 15 索引的 16 个数据库|
58+
| db_index || 指定 Redis 数据库索引,默认为 0。索引范围为 0 到 15,因为 Redis 支持 16 个从 0 到 15 索引的数据库|
5759

5860
## 示例
5961

62+
### MySQL 字典示例
63+
6064
以下示例使用来自 MySQL 数据库的数据创建一个名为 `courses_dict` 的字典:
6165

6266
```sql
@@ -76,6 +80,8 @@ SOURCE(MYSQL(
7680
));
7781
```
7882

83+
### Redis 字典示例
84+
7985
以下示例使用来自 Redis 数据源的数据创建一个名为 `student_name_dict` 的字典:
8086

8187
```sql
@@ -89,4 +95,20 @@ SOURCE(REDIS(
8995
host='127.0.0.1'
9096
port='6379'
9197
));
92-
```
98+
```
99+
100+
## 与 dict_get() 一起使用
101+
102+
创建字典后,可以使用 `dict_get()` 函数查询它:
103+
104+
```sql
105+
-- 使用字典查询学生信息
106+
SELECT
107+
student_id,
108+
dict_get(student_name_dict, 'student_name', to_string(student_id)) as student_name,
109+
course_id,
110+
dict_get(courses_dict, 'course_name', course_id) as course_name
111+
FROM student_scores;
112+
```
113+
114+
这种方法支持跨多个源的实时数据集成,而无需复杂的 ETL 流程。

0 commit comments

Comments
 (0)