databendlabs / databend

๐——๐—ฎ๐˜๐—ฎ, ๐—”๐—ป๐—ฎ๐—น๐˜†๐˜๐—ถ๐—ฐ๐˜€ & ๐—”๐—œ. Modern alternative to Snowflake. Cost-effective and simple for massive-scale analytics. https://databend.com
https://docs.databend.com
Other
7.71k stars 732 forks source link

feat(query): Support access Mysql data from dictionaries via the `dict_get` function. #16444

Closed Winnie-Hong0927 closed 1 week ago

Winnie-Hong0927 commented 2 weeks ago

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

This pull request introduces support for accessing Mysql data from dictionaries using the dict_getfunction.Other source like PostgreSQL will be introduced in the future PRs.Besides, this pull request can only support bool,string,int and float, other types will be supported later.

  1. Dictionary Creation with Mysql Source:
CREATE OR REPLACE DICTIONARY dd3(id int, name string, age int, address string, salary float, b bool) PRIMARY KEY id SOURCE(mysql(host='localhost' port='3306' username='root' password='123456' db='test' table='user3'));

Options are used to provide the Mysql connection URL, host, port, username, password, db and table are all required options to identify specific table.

Connect to Mysql, create a table and insert some records.

mysql -uroot -P3306 -p123456
CREATE TABLE `user3`(`id` int(11), `name` varchar(100), `age` int(11), `address` varchar(100), `salary` float, `b` bool);
INSERT INTO `user3` VALUES(1, 'andy', 10, 'beijing', '1234.56', true);
  1. Data Access with dict_get Function:
MySQL [(none)]> select dict_get(dd3, 'name', 1);
+----------------------------------+
| dict_get(default.dd3, 'name', 1) |
+----------------------------------+
| andy                             |
+----------------------------------+
1 row in set (0.112 sec)

MySQL [(none)]> select dict_get(dd3, 'age', 1);
+---------------------------------+
| dict_get(default.dd3, 'age', 1) |
+---------------------------------+
|                              10 |
+---------------------------------+
1 row in set (0.109 sec)

MySQL [(none)]> select dict_get(dd3, 'salary', 1);
+------------------------------------+
| dict_get(default.dd3, 'salary', 1) |
+------------------------------------+
|                            1234.56 |
+------------------------------------+
1 row in set (0.106 sec)

MySQL [(none)]> select dict_get(dd3, 'b', 1);
+-------------------------------+
| dict_get(default.dd3, 'b', 1) |
+-------------------------------+
|                             1 |
+-------------------------------+
1 row in set (0.077 sec)

part of https://github.com/datafuselabs/databend/issues/15901

Tests

Type of change


This change isโ€‚Reviewable