Better semantic of sharing columns: development [#CLICKHOUSE-2].

This commit is contained in:
Alexey Milovidov 2017-12-15 06:04:33 +03:00
parent a086e3e6d8
commit 96ee187d1a
5 changed files with 22 additions and 28 deletions

View File

@ -63,7 +63,7 @@ Block createSampleBlock(const DictionaryStructure & dict_struct)
auto column = attribute.type->createColumn();
column->insertDefault();
block.insert(ColumnWithTypeAndName{column, attribute.type, attribute.name});
block.insert(ColumnWithTypeAndName{std::move(column), attribute.type, attribute.name});
}
}
@ -77,7 +77,7 @@ Block createSampleBlock(const DictionaryStructure & dict_struct)
auto column = attribute.type->createColumn();
column->insert(attribute.null_value);
block.insert(ColumnWithTypeAndName{column, attribute.type, attribute.name});
block.insert(ColumnWithTypeAndName{std::move(column), attribute.type, attribute.name});
}
return block;

View File

@ -33,13 +33,13 @@ void formatKeys(const DictionaryStructure & dict_struct, BlockOutputStreamPtr &
for (size_t i = 0, size = key_columns.size(); i < size; ++i)
{
const ColumnPtr & source_column = key_columns[i];
ColumnPtr filtered_column = source_column->cloneEmpty();
auto filtered_column = source_column->cloneEmpty();
filtered_column->reserve(requested_rows.size());
for (size_t idx : requested_rows)
filtered_column->insertFrom(*source_column, idx);
block.insert({ filtered_column, (*dict_struct.key)[i].type, toString(i) });
block.insert({ std::move(filtered_column), (*dict_struct.key)[i].type, toString(i) });
}
out->writePrefix();

View File

@ -283,15 +283,14 @@ std::vector<DictionaryAttribute> DictionaryStructure::getAttributes(
try
{
ReadBufferFromString null_value_buffer{null_value_string};
ColumnPtr column_with_null_value = type->createColumn();
auto column_with_null_value = type->createColumn();
type->deserializeTextEscaped(*column_with_null_value, null_value_buffer);
null_value = (*column_with_null_value)[0];
}
catch (const std::exception & e)
catch (Exception & e)
{
throw Exception{
std::string{"Error parsing null_value: "} + e.what(),
ErrorCodes::BAD_ARGUMENTS};
e.addMessage("error parsing null_value");
throw;
}
}

View File

@ -69,15 +69,17 @@ CStringsHolder getLibSettings(const Poco::Util::AbstractConfiguration & config,
}
bool dataToBlock(const void * data, Block & block)
Block dataToBlock(const Block & sample_block, const void * data)
{
if (!data)
return true;
return sample_block.cloneEmpty();
auto columns_received = static_cast<const ClickHouseLibrary::ColumnsUInt64 *>(data);
std::vector<IColumn *> columns(block.columns());
MutableColumns columns(sample_block.columns());
for (const auto i : ext::range(0, columns.size()))
columns[i] = block.getByPosition(i).column.get();
columns[i] = sample_block.getByPosition(i).column->cloneEmpty();
for (size_t col_n = 0; col_n < columns_received->size; ++col_n)
{
if (columns.size() != columns_received->data[col_n].size)
@ -86,11 +88,10 @@ bool dataToBlock(const void * data, Block & block)
ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH);
for (size_t row_n = 0; row_n < columns_received->data[col_n].size; ++row_n)
{
columns[row_n]->insert(static_cast<UInt64>(columns_received->data[col_n].data[row_n]));
}
}
return false;
return sample_block.cloneWithColumns(std::move(columns));
}
}
@ -148,8 +149,7 @@ BlockInputStreamPtr LibraryDictionarySource::loadAll()
= library->get<void * (*)(decltype(data_ptr), decltype(&settings->strings), decltype(&columns))>("ClickHouseDictionary_v1_loadAll");
data_ptr = library->get<void * (*)()>("ClickHouseDictionary_v1_dataAllocate")();
auto data = fptr(data_ptr, &settings->strings, &columns);
auto block = description.sample_block.cloneEmpty();
dataToBlock(data, block);
auto block = dataToBlock(description.sample_block, data);
library->get<void (*)(void *)>("ClickHouseDictionary_v1_dataDelete")(data_ptr);
return std::make_shared<OneBlockInputStream>(block);
}
@ -175,8 +175,7 @@ BlockInputStreamPtr LibraryDictionarySource::loadIds(const std::vector<UInt64> &
"ClickHouseDictionary_v1_loadIds");
data_ptr = library->get<void * (*)()>("ClickHouseDictionary_v1_dataAllocate")();
auto data = fptr(data_ptr, &settings->strings, &columns_pass, &ids_data);
auto block = description.sample_block.cloneEmpty();
dataToBlock(data, block);
auto block = dataToBlock(description.sample_block, data);
library->get<void (*)(void * data_ptr)>("ClickHouseDictionary_v1_dataDelete")(data_ptr);
return std::make_shared<OneBlockInputStream>(block);
}
@ -213,8 +212,7 @@ BlockInputStreamPtr LibraryDictionarySource::loadKeys(const Columns & key_column
"ClickHouseDictionary_v1_loadKeys");
data_ptr = library->get<void * (*)()>("ClickHouseDictionary_v1_dataAllocate")();
auto data = fptr(data_ptr, &settings->strings, &columns_pass, &requested_rows_c);
auto block = description.sample_block.cloneEmpty();
dataToBlock(data, block);
auto block = dataToBlock(description.sample_block, data);
library->get<void (*)(void * data_ptr)>("ClickHouseDictionary_v1_dataDelete")(data_ptr);
return std::make_shared<OneBlockInputStream>(block);
}

View File

@ -141,14 +141,11 @@ Block MongoDBBlockInputStream::readImpl()
if (all_read)
return {};
Block block = description.sample_block.cloneEmpty();
/// cache pointers returned by the calls to getByPosition
std::vector<IColumn *> columns(block.columns());
MutableColumns columns(description.sample_block.columns());
const size_t size = columns.size();
for (const auto i : ext::range(0, size))
columns[i] = block.getByPosition(i).column.get();
columns[i] = description.sample_block.getByPosition(i).column->cloneEmpty();
size_t num_rows = 0;
while (num_rows < max_block_size)
@ -181,7 +178,7 @@ Block MongoDBBlockInputStream::readImpl()
if (num_rows == 0)
return {};
return block;
return description.sample_block.cloneWithColumns(std::move(columns));
}
}