diff --git a/src/Dictionaries/RedisSource.cpp b/src/Dictionaries/RedisSource.cpp index 27125077c10..261242c627f 100644 --- a/src/Dictionaries/RedisSource.cpp +++ b/src/Dictionaries/RedisSource.cpp @@ -27,14 +27,18 @@ namespace DB const RedisStorageType & storage_type_, const DB::Block & sample_block, size_t max_block_size_) - : ISource(sample_block), max_block_size(max_block_size_)// TODO + : ISource(sample_block) + , connection(std::move(connection_)) + , keys(keys_) + , storage_type(storage_type_) + , max_block_size{max_block_size_} { RedisColumnTypes columns_types_; if (storage_type_ == RedisStorageType::HASH_MAP) columns_types_ = REDIS_HASH_MAP_COLUMN_TYPES; else columns_types_ = REDIS_SIMPLE_COLUMN_TYPES; - RedisSource(std::move(connection_), keys_, storage_type_, sample_block, columns_types_, max_block_size_); + description.init(sample_block); } RedisSource::RedisSource( diff --git a/src/Storages/StorageRedis.cpp b/src/Storages/StorageRedis.cpp index cd1cd06b4c4..e670012d060 100644 --- a/src/Storages/StorageRedis.cpp +++ b/src/Storages/StorageRedis.cpp @@ -75,9 +75,8 @@ Pipe StorageRedis::read( if (all_scan) { + /// TODO use scan to avoid performance issue RedisCommand command_for_keys("KEYS"); - /// generate keys by table name prefix -// command_for_keys << table_id.getTableName() + ":" + serializeStorageType(configuration.storage_type) + ":*"; command_for_keys << "*"; auto all_keys = connection->client->execute(command_for_keys); @@ -136,7 +135,16 @@ Pipe StorageRedis::read( RedisArray keys; for (size_t pos=begin; posat(pos).get()); + { + if (WhichDataType(*primary_key_data_type).isStringOrFixedString()) + { + keys.add(fields->at(pos).get()); + } + else + { + keys.add(toString(fields->at(pos))); /// TODO redis source deserialize + } + } if (configuration.storage_type == RedisStorageType::HASH_MAP) { diff --git a/tests/integration/test_storage_redis/test.py b/tests/integration/test_storage_redis/test.py index d4fbdaddd7f..19e7b4e5340 100644 --- a/tests/integration/test_storage_redis/test.py +++ b/tests/integration/test_storage_redis/test.py @@ -181,3 +181,4 @@ def test_create_table(started_cluster): """ ) + diff --git a/tests/integration/test_table_function_redis/test.py b/tests/integration/test_table_function_redis/test.py index e53022095c9..7c342690027 100644 --- a/tests/integration/test_table_function_redis/test.py +++ b/tests/integration/test_table_function_redis/test.py @@ -157,3 +157,63 @@ def test_customized_table_structure(started_cluster): FROM redis('{address}', 0, 'clickhouse', "simple", 10, "k Ss, v String") """) + + +def test_data_type(started_cluster): + client = get_redis_connection() + address = get_address_for_ch() + + # string + client.flushall() + client.set('0', '0') + + response = TSV.toMat(node.query( + f""" + SELECT + * + FROM + redis('{address}', 0, 'clickhouse', 'simple', 10, "k String, v UInt8") + WHERE + k='0' + FORMAT TSV + """)) + + assert (len(response) == 1) + assert (response[0] == ['0', '0']) + + # number + client.flushall() + client.set('0', '0') + + response = TSV.toMat(node.query( + f""" + SELECT + * + FROM + redis('{address}', 0, 'clickhouse', 'simple', 10, "k UInt8, v UInt8") + WHERE + k=0 + FORMAT TSV + """)) + + assert (len(response) == 1) + assert (response[0] == ['0', '0']) + + # datetime + client.flushall() + client.set('2023-06-01 00:00:00', '0') + + response = TSV.toMat(node.query( + f""" + SELECT + * + FROM + redis('{address}', 0, 'clickhouse', 'simple', 10, "k DateTime, v UInt8") + WHERE + k='2023-06-01 00:00:00' + FORMAT TSV + """)) + + # TODO open + # assert (len(response) == 1) + # assert (response[0] == ['2023-06-01 00:00:00', '0'])