2015-06-29 04:54:52 +00:00
|
|
|
#include <DB/DataTypes/DataTypeString.h>
|
2013-03-27 10:07:23 +00:00
|
|
|
#include <DB/DataTypes/DataTypeFixedString.h>
|
2015-06-29 04:54:52 +00:00
|
|
|
#include <DB/DataTypes/DataTypeArray.h>
|
2012-08-26 11:14:52 +00:00
|
|
|
|
2011-11-06 06:22:52 +00:00
|
|
|
#include <DB/Columns/ColumnString.h>
|
|
|
|
#include <DB/Columns/ColumnConst.h>
|
2013-05-05 15:25:25 +00:00
|
|
|
#include <DB/Columns/ColumnArray.h>
|
2016-02-14 02:37:42 +00:00
|
|
|
#include <DB/Columns/ColumnTuple.h>
|
2013-03-27 10:07:23 +00:00
|
|
|
#include <DB/Columns/ColumnFixedString.h>
|
2015-12-24 14:31:41 +00:00
|
|
|
#include <DB/DataTypes/DataTypeTuple.h>
|
|
|
|
#include <ext/enumerate.hpp>
|
2011-11-06 06:22:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2013-03-06 13:56:11 +00:00
|
|
|
|
2011-11-06 06:22:52 +00:00
|
|
|
|
|
|
|
template <> ColumnPtr ColumnConst<String>::convertToFullColumn() const
|
|
|
|
{
|
2014-06-26 00:58:14 +00:00
|
|
|
if (!data_type || typeid_cast<const DataTypeString *>(&*data_type))
|
2013-03-27 10:07:23 +00:00
|
|
|
{
|
|
|
|
ColumnString * res = new ColumnString;
|
|
|
|
ColumnPtr res_ptr = res;
|
|
|
|
ColumnString::Offsets_t & offsets = res->getOffsets();
|
2013-05-05 15:25:25 +00:00
|
|
|
ColumnString::Chars_t & vec = res->getChars();
|
2011-11-06 06:22:52 +00:00
|
|
|
|
2013-03-27 10:07:23 +00:00
|
|
|
size_t string_size = data.size() + 1;
|
|
|
|
size_t offset = 0;
|
|
|
|
offsets.resize(s);
|
|
|
|
vec.resize(s * string_size);
|
2011-11-06 06:22:52 +00:00
|
|
|
|
2013-03-27 10:07:23 +00:00
|
|
|
for (size_t i = 0; i < s; ++i)
|
|
|
|
{
|
|
|
|
memcpy(&vec[offset], data.data(), string_size);
|
|
|
|
offset += string_size;
|
|
|
|
offsets[i] = offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res_ptr;
|
2011-11-06 06:22:52 +00:00
|
|
|
}
|
2014-06-26 00:58:14 +00:00
|
|
|
else if (const DataTypeFixedString * type = typeid_cast<const DataTypeFixedString *>(&*data_type))
|
2013-03-27 10:07:23 +00:00
|
|
|
{
|
|
|
|
size_t n = type->getN();
|
2011-11-06 06:22:52 +00:00
|
|
|
|
2013-03-27 10:07:23 +00:00
|
|
|
if (data.size() > n)
|
|
|
|
throw Exception("Too long value for " + type->getName(), ErrorCodes::TOO_LARGE_STRING_SIZE);
|
|
|
|
|
|
|
|
ColumnFixedString * res = new ColumnFixedString(n);
|
|
|
|
ColumnPtr res_ptr = res;
|
2013-05-05 15:25:25 +00:00
|
|
|
ColumnFixedString::Chars_t & vec = res->getChars();
|
2013-03-27 10:07:23 +00:00
|
|
|
|
2013-12-03 10:01:04 +00:00
|
|
|
vec.resize_fill(n * s);
|
2013-03-27 10:07:23 +00:00
|
|
|
size_t offset = 0;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < s; ++i)
|
|
|
|
{
|
|
|
|
memcpy(&vec[offset], data.data(), data.size());
|
|
|
|
offset += n;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res_ptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw Exception("Invalid data type in ColumnConstString: " + data_type->getName(), ErrorCodes::LOGICAL_ERROR);
|
2011-11-06 06:22:52 +00:00
|
|
|
}
|
|
|
|
|
2012-08-26 06:48:39 +00:00
|
|
|
|
2015-06-29 07:41:23 +00:00
|
|
|
ColumnPtr ColumnConst<Array>::convertToFullColumn() const
|
2012-08-26 06:48:39 +00:00
|
|
|
{
|
2013-03-27 10:07:23 +00:00
|
|
|
if (!data_type)
|
|
|
|
throw Exception("No data type specified for ColumnConstArray", ErrorCodes::LOGICAL_ERROR);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
|
|
|
const DataTypeArray * type = typeid_cast<const DataTypeArray *>(&*data_type);
|
2013-03-27 10:07:23 +00:00
|
|
|
if (!type)
|
|
|
|
throw Exception("Non-array data type specified for ColumnConstArray", ErrorCodes::LOGICAL_ERROR);
|
2014-06-26 00:58:14 +00:00
|
|
|
|
2015-06-29 07:41:23 +00:00
|
|
|
const Array & array = getDataFromHolderImpl();
|
|
|
|
size_t array_size = array.size();
|
2013-03-27 10:07:23 +00:00
|
|
|
ColumnPtr nested_column = type->getNestedType()->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)
|
2015-06-29 07:41:23 +00:00
|
|
|
nested_column->insert(array[j]);
|
2012-08-26 11:14:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
2012-08-26 06:48:39 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 13:56:11 +00:00
|
|
|
|
2015-06-29 07:41:23 +00:00
|
|
|
StringRef ColumnConst<Array>::getDataAt(size_t n) const
|
|
|
|
{
|
|
|
|
throw Exception("Method getDataAt is not supported for " + this->getName(), ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
UInt64 ColumnConst<Array>::get64(size_t n) const
|
|
|
|
{
|
|
|
|
throw Exception("Method get64 is not supported for " + this->getName(), ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef ColumnConst<Array>::getDataAtWithTerminatingZero(size_t n) const
|
|
|
|
{
|
|
|
|
throw Exception("Method getDataAt is not supported for " + this->getName(), ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-24 14:31:41 +00:00
|
|
|
ColumnPtr ColumnConst<Tuple>::convertToFullColumn() const
|
|
|
|
{
|
|
|
|
if (!data_type)
|
|
|
|
throw Exception("No data type specified for ColumnConstTuple", ErrorCodes::LOGICAL_ERROR);
|
|
|
|
|
|
|
|
const DataTypeTuple * type = typeid_cast<const DataTypeTuple *>(&*data_type);
|
|
|
|
if (!type)
|
|
|
|
throw Exception("Non-Tuple data type specified for ColumnConstTuple", ErrorCodes::LOGICAL_ERROR);
|
|
|
|
|
|
|
|
/// Ask data_type to create ColumnTuple of corresponding type
|
|
|
|
ColumnPtr res = type->createColumn();
|
2015-12-24 16:14:07 +00:00
|
|
|
static_cast<ColumnTuple &>(*res).insert(getDataFromHolderImpl());
|
2015-12-24 14:31:41 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ColumnConst<Tuple>::getExtremes(Field & min, Field & max) const
|
|
|
|
{
|
|
|
|
min = data_type->getDefault();
|
|
|
|
max = data_type->getDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef ColumnConst<Tuple>::getDataAt(size_t n) const
|
|
|
|
{
|
|
|
|
throw Exception("Method getDataAt is not supported for " + this->getName(), ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
UInt64 ColumnConst<Tuple>::get64(size_t n) const
|
|
|
|
{
|
|
|
|
throw Exception("Method get64 is not supported for " + this->getName(), ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
StringRef ColumnConst<Tuple>::getDataAtWithTerminatingZero(size_t n) const
|
|
|
|
{
|
|
|
|
throw Exception("Method getDataAt is not supported for " + this->getName(), ErrorCodes::NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-06 06:22:52 +00:00
|
|
|
}
|