Skip to content

Commit 6d967e4

Browse files
authored
refine: dictionary (#1952)
1 parent 2e39bc0 commit 6d967e4

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

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

Lines changed: 31 additions & 9 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-
Creates a dictionary using a specified source.
8+
Creates a dictionary that enables real-time data access from external sources. Dictionaries allow Databend to query data directly from external systems like MySQL and Redis without traditional ETL processes, ensuring data consistency and improving query performance.
99

1010
## Syntax
1111

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

23+
When a dictionary is created, Databend establishes a connection to the specified external data source. The dictionary can then be queried using the `dict_get()` function to retrieve data directly from the source at query time.
24+
2325
| Parameter | Description |
2426
|------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
25-
| `<dictionary_name>` | The name of the dictionary. |
26-
| `<column_name>` | The name of a column in the dictionary. |
27-
| `<data_type>` | The type of data stored in the column. |
28-
| `<default-value>` | Specifies a default value for a column in case no value is provided when the dictionary is populated from the source. |
29-
| `<primary_key_column>` | The primary key column used for fast lookups. This key should correspond to a unique value for each entry in the dictionary. |
30-
| `<source_type>` | Specifies the type of data source, `MYSQL` or `REDIS`. |
31-
| `<source_parameters>` | Defines the configuration parameters required for the specified source type. |
27+
| `<dictionary_name>` | The name of the dictionary to be referenced in queries. |
28+
| `<column_name>` | The name of a column in the dictionary. These columns define the structure of data that can be retrieved from the external source. |
29+
| `<data_type>` | The data type for each column. For MySQL sources, Databend supports boolean, string, and numeric types (including int, bigint, float32, float64). For Redis sources, only string type is supported. |
30+
| `<default-value>` | Optional default value for a column when no value is found in the external source. This ensures queries return meaningful results even when data is missing. |
31+
| `<primary_key_column>` | The column used as the lookup key when querying the dictionary. This should correspond to a unique identifier in the external data source. |
32+
| `<source_type>` | The type of external data source. Currently supported: `MYSQL` or `REDIS`. Future versions will support additional sources. |
33+
| `<source_parameters>` | Connection and configuration parameters specific to the selected source type. |
3234

3335
### MySQL Parameters
3436

@@ -57,6 +59,8 @@ The following table lists the required and optional parameters for configuring a
5759

5860
## Examples
5961

62+
### MySQL Dictionary Example
63+
6064
The following example creates a dictionary named `courses_dict` using data from a MySQL database:
6165

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

83+
### Redis Dictionary Example
84+
7985
The following example creates a dictionary named `student_name_dict` using data from a Redis data source:
8086

8187
```sql
@@ -89,4 +95,20 @@ SOURCE(REDIS(
8995
host='127.0.0.1'
9096
port='6379'
9197
));
92-
```
98+
```
99+
100+
## Usage with dict_get()
101+
102+
After creating a dictionary, you can query it using the `dict_get()` function:
103+
104+
```sql
105+
-- Query student information using the dictionary
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+
This approach enables real-time data integration across multiple sources without complex ETL processes.

0 commit comments

Comments
 (0)