File tree Expand file tree Collapse file tree
cn/sql-reference/10-sql-commands/00-ddl
en/sql-reference/10-sql-commands/00-ddl Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ {
2+ "label" : " 字典(Dictionary)" ,
3+ "position" : 17
4+ }
Original file line number Diff line number Diff line change 1+ ---
2+ title : CREATE DICTIONARY
3+ sidebar_position : 1
4+ ---
5+
6+ 创建一个字典。
7+
8+ ## 语法
9+
10+ ``` sql
11+ CREATE [ OR REPLACE ] DICTIONARY [ IF NOT EXISTS ] [ < catalog_name> . ][ < database_name> . ]< dictionary_name>
12+ (
13+ < column_name> < data_type> [ , < column_name> < data_type> , ... ]
14+ )
15+ PRIMARY KEY < column_name> [ , < column_name> , ... ]
16+ SOURCE(
17+ < source_name> (
18+ < source_option> = ' <value>' [ < source_option> = ' <value>' ... ]
19+ )
20+ )
21+ [ COMMENT ' <comment>' ]
22+ ```
23+
24+ ## 参数
25+
26+ | 参数 | 说明 |
27+ | -----------| -------------|
28+ | ` OR REPLACE ` | 如果同名字典已存在,则替换它。 |
29+ | ` IF NOT EXISTS ` | 如果字典已存在,则成功返回但不做修改。 |
30+ | ` <dictionary_name> ` | 字典名称。可以带上 catalog 和 database 限定。 |
31+ | ` (<column_name> <data_type>, ...) ` | 定义字典的列结构。 |
32+ | ` PRIMARY KEY ` | 定义一个或多个用于字典查找的主键列。 |
33+ | ` SOURCE(...) ` | 定义数据源连接器名称及其键值参数。 |
34+ | ` COMMENT ` | 可选的字典备注。 |
35+
36+ ::: note
37+ - SOURCE 仅支持 ` MySQL ` 和 ` Redis ` 。
38+ :::
39+
40+ ## 示例
41+
42+ MySQL 示例:
43+
44+ ``` sql
45+ CREATE DICTIONARY user_info
46+ (
47+ user_id UInt64,
48+ user_name String,
49+ user_email String
50+ )
51+ PRIMARY KEY user_id
52+ SOURCE(
53+ mysql(
54+ host = ' 127.0.0.1'
55+ port = ' 3306'
56+ username = ' root'
57+ password = ' root'
58+ db = ' app'
59+ table = ' users'
60+ )
61+ )
62+ COMMENT ' User dictionary from MySQL' ;
63+ ```
64+
65+ Redis 示例:
66+
67+ ``` sql
68+ CREATE DICTIONARY cache
69+ (
70+ key String,
71+ value String
72+ )
73+ PRIMARY KEY key
74+ SOURCE(
75+ redis(
76+ host = ' 127.0.0.1'
77+ port = ' 6379'
78+ )
79+ )
80+ COMMENT ' cache dictionary from Redis' ;
81+ ```
Original file line number Diff line number Diff line change 1+ ---
2+ title : 字典(Dictionary)
3+ ---
4+
5+ Dictionary 提供了一种基于键值对的方法,用于从各种外部数据源(包括 MySQL 和 Redis)读取数据。
6+
7+ ## 字典管理
8+
9+ | 命令 | 描述 |
10+ | ---------| -------------|
11+ | [ CREATE DICTIONARY] ( create-dictionary.md ) | 创建字典 |
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ title: DDL(Data Definition Language)命令
4444| ** [ 序列 (Sequence)] ( 04-sequence/index.md ) ** | 生成唯一的序列号 |
4545| ** [ 连接 (Connection)] ( 13-connection/index.md ) ** | 配置外部数据源连接 |
4646| ** [ 文件格式 (File Format)] ( 13-file-format/index.md ) ** | 为数据导入/导出定义格式 |
47+ | ** [ 字典 (Dictionary)] ( 17-dictionary/index.md ) ** | 定义由外部数据源驱动的字典 |
4748
4849## 函数和存储过程
4950
Original file line number Diff line number Diff line change 1+ {
2+ "label" : " Dictionary" ,
3+ "position" : 17
4+ }
Original file line number Diff line number Diff line change 1+ ---
2+ title : CREATE DICTIONARY
3+ sidebar_position : 1
4+ ---
5+
6+ Creates a dictionary.
7+
8+ ## Syntax
9+
10+ ``` sql
11+ CREATE [ OR REPLACE ] DICTIONARY [ IF NOT EXISTS ] [ < catalog_name> . ][ < database_name> . ]< dictionary_name>
12+ (
13+ < column_name> < data_type> [ , < column_name> < data_type> , ... ]
14+ )
15+ PRIMARY KEY < column_name> [ , < column_name> , ... ]
16+ SOURCE(
17+ < source_name> (
18+ < source_option> = ' <value>' [ < source_option> = ' <value>' ... ]
19+ )
20+ )
21+ [ COMMENT ' <comment>' ]
22+ ```
23+
24+ ## Parameters
25+
26+ | Parameter | Description |
27+ | -----------| -------------|
28+ | ` OR REPLACE ` | Replaces an existing dictionary with the same name. |
29+ | ` IF NOT EXISTS ` | Succeeds without changes if the dictionary already exists. |
30+ | ` <dictionary_name> ` | The dictionary name. You can qualify it with catalog and database names. |
31+ | ` (<column_name> <data_type>, ...) ` | Declares the dictionary schema. |
32+ | ` PRIMARY KEY ` | Defines one or more key columns used for dictionary lookups. |
33+ | ` SOURCE(...) ` | Defines the source connector name and its key-value options. |
34+ | ` COMMENT ` | Optional dictionary comment. |
35+
36+ ::: note
37+ - SOURCE only support ` MySQL ` and ` Redis ` .
38+ :::
39+
40+ ## Examples
41+
42+ MySQL example:
43+
44+ ``` sql
45+ CREATE DICTIONARY user_info
46+ (
47+ user_id UInt64,
48+ user_name String,
49+ user_email String
50+ )
51+ PRIMARY KEY user_id
52+ SOURCE(
53+ mysql(
54+ host = ' 127.0.0.1'
55+ port = ' 3306'
56+ username = ' root'
57+ password = ' root'
58+ db = ' app'
59+ table = ' users'
60+ )
61+ )
62+ COMMENT ' User dictionary from MySQL' ;
63+ ```
64+
65+ Redis example:
66+
67+ ``` sql
68+ CREATE DICTIONARY cache
69+ (
70+ key String,
71+ value String
72+ )
73+ PRIMARY KEY key
74+ SOURCE(
75+ redis(
76+ host = ' 127.0.0.1'
77+ port = ' 6379'
78+ )
79+ )
80+ COMMENT ' cache dictionary from Redis' ;
81+ ```
Original file line number Diff line number Diff line change 1+ ---
2+ title : Dictionary
3+ ---
4+
5+ Dictionary provides a key-value approach for reading data from various external data sources, including MySQL and Redis.
6+
7+ ## Dictionary Management
8+
9+ | Command | Description |
10+ | ---------| -------------|
11+ | [ CREATE DICTIONARY] ( create-dictionary.md ) | Creates a dictionary |
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ These topics provide reference information for the DDL (Data Definition Language
4444| ** [ Sequence] ( 04-sequence/index.md ) ** | Generate unique sequential numbers |
4545| ** [ Connection] ( 13-connection/index.md ) ** | Configure external data source connections |
4646| ** [ File Format] ( 13-file-format/index.md ) ** | Define formats for data import/export |
47+ | ** [ Dictionary] ( 17-dictionary/index.md ) ** | Define dictionaries backed by external sources |
4748
4849## Functions & Procedures
4950
You can’t perform that action at this time.
0 commit comments