diff --git a/dbms/src/Dictionaries/LibraryDictionarySource.cpp b/dbms/src/Dictionaries/LibraryDictionarySource.cpp index d9acef989c8..00a216686c0 100644 --- a/dbms/src/Dictionaries/LibraryDictionarySource.cpp +++ b/dbms/src/Dictionaries/LibraryDictionarySource.cpp @@ -208,25 +208,30 @@ BlockInputStreamPtr LibraryDictionarySource::loadKeys(const Columns & key_column { LOG_TRACE(log, "loadKeys " << toString() << " size = " << requested_rows.size()); - auto columns_holder = std::make_unique(key_columns.size()); - ClickHouseLibrary::CStrings columns_pass{ - static_cast(columns_holder.get()), key_columns.size()}; - size_t key_columns_n = 0; - for (auto & column : key_columns) + auto holder = std::make_unique(key_columns.size()); + std::vector> columnDataHolders; + for (size_t i = 0; i < key_columns.size(); ++i) { - columns_pass.data[key_columns_n] = column->getName().c_str(); - ++key_columns_n; - } - const ClickHouseLibrary::VectorUInt64 requested_rows_c{ - ext::bit_cast(requested_rows.data()), requested_rows.size()}; - void * data_ptr = nullptr; + auto cellHolder = std::make_unique(requested_rows.size()); + for (size_t j = 0; j < requested_rows.size(); ++j) + { + auto dataRef = key_columns[i]->getDataAt(requested_rows[j]); + cellHolder[j] = ClickHouseLibrary::Field{.data = static_cast(dataRef.data), .size = dataRef.size}; + } + holder[i] + = ClickHouseLibrary::Row{.data = static_cast(cellHolder.get()), .size = requested_rows.size()}; + columnDataHolders.push_back(std::move(cellHolder)); + } + + ClickHouseLibrary::Table requestCols{.data = static_cast(holder.get()), .size = key_columns.size()}; + + void * data_ptr = nullptr; /// Get function pointer before dataNew call because library->get may throw. - auto func_loadKeys - = library->getstrings), decltype(&columns_pass), decltype(&requested_rows_c))>( - "ClickHouseDictionary_v3_loadKeys"); + auto func_loadKeys = library->getstrings), decltype(&requestCols))>( + "ClickHouseDictionary_v3_loadKeys"); data_ptr = library->get("ClickHouseDictionary_v3_dataNew")(lib_data); - auto data = func_loadKeys(data_ptr, &settings->strings, &columns_pass, &requested_rows_c); + auto data = func_loadKeys(data_ptr, &settings->strings, &requestCols); auto block = dataToBlock(description.sample_block, data); SCOPE_EXIT(library->get("ClickHouseDictionary_v3_dataDelete")(lib_data, data_ptr)); return std::make_shared(block); diff --git a/dbms/tests/external_dictionaries/dictionary_library/dictionary_library.cpp b/dbms/tests/external_dictionaries/dictionary_library/dictionary_library.cpp index 8e18abbe80f..59b75d0a26f 100644 --- a/dbms/tests/external_dictionaries/dictionary_library/dictionary_library.cpp +++ b/dbms/tests/external_dictionaries/dictionary_library/dictionary_library.cpp @@ -136,10 +136,7 @@ void * ClickHouseDictionary_v3_loadAll(void * data_ptr, ClickHouseLibrary::CStri return static_cast(&ptr->ctable); } -void * ClickHouseDictionary_v3_loadKeys(void * data_ptr, - ClickHouseLibrary::CStrings * settings, - ClickHouseLibrary::CStrings * columns, - const ClickHouseLibrary::VectorUInt64 * requested_rows) +void * ClickHouseDictionary_v3_loadKeys(void * data_ptr, ClickHouseLibrary::CStrings * settings, ClickHouseLibrary::Table * requested_keys) { auto ptr = static_cast(data_ptr); LOG(ptr->lib->log, "loadKeys lib call ptr=" << data_ptr << " => " << ptr); @@ -151,20 +148,11 @@ void * ClickHouseDictionary_v3_loadKeys(void * data_ptr, LOG(ptr->lib->log, "setting " << i << " :" << settings->data[i]); } } - if (columns) + if (requested_keys) { - LOG(ptr->lib->log, "columns passed:" << columns->size); - for (size_t i = 0; i < columns->size; ++i) - { - LOG(ptr->lib->log, "col " << i << " :" << columns->data[i]); - } - } - if (requested_rows) - { - LOG(ptr->lib->log, "requested_rows passed: " << requested_rows->size); - for (size_t i = 0; i < requested_rows->size; ++i) - { - LOG(ptr->lib->log, "id " << i << " :" << requested_rows->data[i]); + LOG(ptr->lib->log, "requested_keys columns passed: " << requested_keys->size); + for (size_t i = 0; i < requested_keys->size; ++i) { + LOG(ptr->lib->log, "requested_keys at column " << i << " passed: " << requested_keys->data[i].size); } } diff --git a/dbms/tests/external_dictionaries/dictionary_library/dictionary_library_c.c b/dbms/tests/external_dictionaries/dictionary_library/dictionary_library_c.c index c3d5ba901d7..2a18b236485 100644 --- a/dbms/tests/external_dictionaries/dictionary_library/dictionary_library_c.c +++ b/dbms/tests/external_dictionaries/dictionary_library/dictionary_library_c.c @@ -30,6 +30,27 @@ typedef struct int someField; } DataHolder; +typedef struct +{ + const void * data; + uint64_t size; +} ClickHouseLibField; + +typedef struct +{ + const ClickHouseLibField * data; + uint64_t size; +} ClickHouseLibRow; + +typedef struct +{ + const ClickHouseLibRow * data; + uint64_t size; + uint64_t error_code; + const char * error_string; +} ClickHouseLibTable; + + #define LOG(logger, format, ...) \ do \ { \ @@ -54,11 +75,10 @@ void * ClickHouseDictionary_v3_loadAll(void * data_ptr, ClickHouseLibCStrings * return 0; } -void * ClickHouseDictionary_v3_loadKeys( - void * data_ptr, ClickHouseLibCStrings * settings, ClickHouseLibCStrings * columns, const ClickHouseLibVectorUInt64 * requested_rows) +void * ClickHouseDictionary_v3_loadKeys(void * data_ptr, ClickHouseLibCStrings * settings, ClickHouseLibTable* requested_keys) { LibHolder * lib = ((DataHolder *)(data_ptr))->lib; - LOG(lib->log, "loadKeys c lib call ptr=%p size=%" PRIu64, data_ptr, requested_rows->size); + LOG(lib->log, "loadKeys c lib call ptr=%p size=%" PRIu64, data_ptr, requested_keys->size); return 0; }