databendlabs / databend

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

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

Closed Winnie-Hong0927 closed 2 months ago

Winnie-Hong0927 commented 2 months 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 Redis data from dictionaries using the dict_getfunction. Other source like MySQL, PostgreSQL will be introduced in the future PRs.

  1. Dictionary Creation with Redis Source:
CREATE OR REPLACE DICTIONARY d(key string not null, value string not null) PRIMARY KEY key SOURCE(redis(host='127.0.0.1' port='6379'))

options are used to provide the Redis connection URL, host and port are required options, and username, password, db_index are optional options.

connect to Redis and set some test keys and values

redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> set a abc
OK
127.0.0.1:6379> set b def
OK
127.0.0.1:6379>
  1. Data Access with dict_get Function:
MySQL [(none)]> create or replace table t(a string);
Query OK, 0 rows affected (0.201 sec)

MySQL [(none)]> insert into t values('a'),('b'),('c');
Query OK, 3 rows affected (0.095 sec)

MySQL [(none)]> select a, dict_get(d, 'value', a) from t;
+------+---------------------------------+
| a | dict_get(default.d, 'value', a) |
+------+---------------------------------+
| a | abc |
| b | def |
| c | |
+------+---------------------------------+
3 rows in set (0.173 sec)

This PR also introduces a mock_source, which simulates a Redis server to test the dict_get function. Future work will expand this mock data source functionality to include support for other sources such as MySQL, PostgreSQL, and more.

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

Tests

Type of change


This change isโ€‚Reviewable