2012-08-26 11:14:52 +00:00
|
|
|
#include <DB/DataTypes/FieldToDataType.h>
|
|
|
|
|
2011-11-06 06:22:52 +00:00
|
|
|
#include <DB/Columns/ColumnString.h>
|
|
|
|
#include <DB/Columns/ColumnConst.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
template <> ColumnPtr ColumnConst<String>::convertToFullColumn() const
|
|
|
|
{
|
|
|
|
ColumnString * res = new ColumnString;
|
|
|
|
ColumnString::Offsets_t & offsets = res->getOffsets();
|
|
|
|
ColumnUInt8::Container_t & vec = dynamic_cast<ColumnVector<UInt8> &>(res->getData()).getData();
|
|
|
|
|
|
|
|
size_t string_size = data.size() + 1;
|
|
|
|
size_t offset = 0;
|
|
|
|
offsets.resize(s);
|
|
|
|
vec.resize(s * string_size);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < s; ++i)
|
|
|
|
{
|
|
|
|
memcpy(&vec[offset], data.data(), string_size);
|
|
|
|
offset += string_size;
|
|
|
|
offsets[i] = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2012-08-26 06:48:39 +00:00
|
|
|
|
|
|
|
template <> ColumnPtr ColumnConst<Array>::convertToFullColumn() const
|
|
|
|
{
|
2012-08-26 11:14:52 +00:00
|
|
|
size_t array_size = data.size();
|
2012-09-17 04:31:25 +00:00
|
|
|
ColumnPtr nested_column = data.empty()
|
|
|
|
? new ColumnUInt8 /// Для пустого массива непонятно, какого типа будет материализованный столбец. Пусть будет UInt8.
|
2013-01-05 20:03:19 +00:00
|
|
|
: apply_visitor(FieldToDataType(), data.at(0))->createColumn();
|
2012-09-17 04:31:25 +00:00
|
|
|
|
2012-08-26 11:14:52 +00:00
|
|
|
ColumnArray * res = new ColumnArray(nested_column);
|
|
|
|
ColumnArray::Offsets_t & offsets = res->getOffsets();
|
|
|
|
|
|
|
|
offsets.resize(s);
|
|
|
|
for (size_t i = 0; i < s; ++i)
|
|
|
|
{
|
|
|
|
offsets[i] = (i + 1) * array_size;
|
|
|
|
for (size_t j = 0; j < array_size; ++j)
|
|
|
|
nested_column->insert(data[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2012-08-26 06:48:39 +00:00
|
|
|
}
|
|
|
|
|
2011-11-06 06:22:52 +00:00
|
|
|
}
|