External Dictionaries
- RFC PR: datafuselabs/databend-docs#996
- Tracking Issue: datafuselabs/databend#15901
Summary
Implementing External Dictionary allows Databend to access data from other external data sources.
Motivation
Accessing data from external databases like MySQL within Databend often requires exporting the MySQL dataset and subsequently importing it into the Databend database. This procedure becomes burdensome when handling substantial amounts of information and may result in inconsistencies due to frequent updates.
The introduction of an external dictionary feature resolves these challenges by facilitating seamless integration between Databend and diverse database systems. Through dictionary creation, direct access to external datasets enables real-time modifcations while streamlining overall data management.
Guide-level explanation
DICTIONARY employs the subsequent syntax for creation, deletion, and querying.
- Create a Dictionary named user_info.
CREATE DICTIONARY user_info(
user_id UInt86,
user_name String,
user_address String
)
primary key(user_id)
SOURCE(MYSQL(
host '[localhost](http://localhost/)'
user 'root'
password 'root'
db 'db_name'
table 'table_name'
));
- Query the existing dictionary.
SHOW DICTIONARIES;
- Inquire about the SQL statement utilized for creating the dictionary user_info.
SHOW CREATE DICTIONARY user_info;
- Delete the Dictionary user_info.
DROP DICTIONARY user_info;
You can use the dict_get(dict_name, dict_field, dict_id)
to query data from a dictionary.
The dict_get
function takes three arguments: the first is the name of the dictionary, the second is the field to query, and the third is the ID of the query dictionary.