You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/sql-reference/10-sql-commands/00-ddl/17-dictionary/create-dictionary.md
+31-9Lines changed: 31 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ import FunctionDescription from '@site/src/components/FunctionDescription';
5
5
6
6
<FunctionDescriptiondescription="Introduced or updated: v1.2.636"/>
7
7
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.
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.
|`<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. |
32
34
33
35
### MySQL Parameters
34
36
@@ -57,6 +59,8 @@ The following table lists the required and optional parameters for configuring a
57
59
58
60
## Examples
59
61
62
+
### MySQL Dictionary Example
63
+
60
64
The following example creates a dictionary named `courses_dict` using data from a MySQL database:
61
65
62
66
```sql
@@ -76,6 +80,8 @@ SOURCE(MYSQL(
76
80
));
77
81
```
78
82
83
+
### Redis Dictionary Example
84
+
79
85
The following example creates a dictionary named `student_name_dict` using data from a Redis data source:
80
86
81
87
```sql
@@ -89,4 +95,20 @@ SOURCE(REDIS(
89
95
host='127.0.0.1'
90
96
port='6379'
91
97
));
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