mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
CLICKHOUSE-3842: Fix loadKeys method in dictionary library
This commit is contained in:
parent
f491bccb1c
commit
1f2c54c8af
@ -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<ClickHouseLibrary::CString[]>(key_columns.size());
|
||||
ClickHouseLibrary::CStrings columns_pass{
|
||||
static_cast<decltype(ClickHouseLibrary::CStrings::data)>(columns_holder.get()), key_columns.size()};
|
||||
size_t key_columns_n = 0;
|
||||
for (auto & column : key_columns)
|
||||
auto holder = std::make_unique<ClickHouseLibrary::Row[]>(key_columns.size());
|
||||
std::vector<std::unique_ptr<ClickHouseLibrary::Field[]>> columnDataHolders;
|
||||
for (size_t i = 0; i < key_columns.size(); ++i)
|
||||
{
|
||||
columns_pass.data[key_columns_n] = column->getName().c_str();
|
||||
++key_columns_n;
|
||||
auto cellHolder = std::make_unique<ClickHouseLibrary::Field[]>(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<const void *>(dataRef.data), .size = dataRef.size};
|
||||
}
|
||||
const ClickHouseLibrary::VectorUInt64 requested_rows_c{
|
||||
ext::bit_cast<decltype(ClickHouseLibrary::VectorUInt64::data)>(requested_rows.data()), requested_rows.size()};
|
||||
void * data_ptr = nullptr;
|
||||
holder[i]
|
||||
= ClickHouseLibrary::Row{.data = static_cast<ClickHouseLibrary::Field *>(cellHolder.get()), .size = requested_rows.size()};
|
||||
|
||||
columnDataHolders.push_back(std::move(cellHolder));
|
||||
}
|
||||
|
||||
ClickHouseLibrary::Table requestCols{.data = static_cast<ClickHouseLibrary::Row *>(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->get<void * (*)(decltype(data_ptr), decltype(&settings->strings), decltype(&columns_pass), decltype(&requested_rows_c))>(
|
||||
auto func_loadKeys = library->get<void * (*)(decltype(data_ptr), decltype(&settings->strings), decltype(&requestCols))>(
|
||||
"ClickHouseDictionary_v3_loadKeys");
|
||||
data_ptr = library->get<decltype(data_ptr) (*)(decltype(lib_data))>("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<void (*)(decltype(lib_data), decltype(data_ptr))>("ClickHouseDictionary_v3_dataDelete")(lib_data, data_ptr));
|
||||
return std::make_shared<OneBlockInputStream>(block);
|
||||
|
@ -136,10 +136,7 @@ void * ClickHouseDictionary_v3_loadAll(void * data_ptr, ClickHouseLibrary::CStri
|
||||
return static_cast<void *>(&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<DataHolder *>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user