2010-05-13 16:17:10 +00:00
|
|
|
|
#ifndef DBMS_CORE_COLUMN_FIXED_ARRAY_H
|
|
|
|
|
#define DBMS_CORE_COLUMN_FIXED_ARRAY_H
|
|
|
|
|
|
|
|
|
|
#include <Poco/SharedPtr.h>
|
|
|
|
|
|
|
|
|
|
#include <DB/Core/Exception.h>
|
|
|
|
|
#include <DB/Core/ErrorCodes.h>
|
|
|
|
|
|
|
|
|
|
#include <DB/Columns/IColumn.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using Poco::SharedPtr;
|
|
|
|
|
|
|
|
|
|
/** Cтолбeц значений типа "массив фиксированного размера".
|
|
|
|
|
*/
|
|
|
|
|
class ColumnFixedArray : public IColumn
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/** Создать пустой столбец массивов фиксированного размера n, со типом значений, как в столбце nested_column */
|
2011-08-09 19:19:00 +00:00
|
|
|
|
ColumnFixedArray(ColumnPtr nested_column, size_t n_)
|
2010-05-13 16:17:10 +00:00
|
|
|
|
: data(nested_column), n(n_)
|
|
|
|
|
{
|
2011-08-07 02:08:22 +00:00
|
|
|
|
clear();
|
2010-05-13 16:17:10 +00:00
|
|
|
|
}
|
2010-05-21 19:52:50 +00:00
|
|
|
|
|
2011-08-09 19:19:00 +00:00
|
|
|
|
ColumnPtr cloneEmpty() const
|
2010-05-21 19:52:50 +00:00
|
|
|
|
{
|
|
|
|
|
return new ColumnFixedArray(data->cloneEmpty(), n);
|
|
|
|
|
}
|
2010-05-13 16:17:10 +00:00
|
|
|
|
|
|
|
|
|
size_t size() const
|
|
|
|
|
{
|
|
|
|
|
return data->size() / n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Field operator[](size_t index) const
|
|
|
|
|
{
|
|
|
|
|
Array res;
|
|
|
|
|
for (size_t i = n * index; i < n * (index + 1); ++i)
|
|
|
|
|
res[i] = (*data)[n * index + i];
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void cut(size_t start, size_t length)
|
|
|
|
|
{
|
|
|
|
|
data->cut(n * start, n * length);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-20 19:29:04 +00:00
|
|
|
|
void insert(const Field & x)
|
|
|
|
|
{
|
|
|
|
|
const Array & array = boost::get<Array &>(x);
|
|
|
|
|
if (n != array.size())
|
|
|
|
|
throw Exception("Size of array doesn't match size of FixedArray column",
|
|
|
|
|
ErrorCodes::SIZE_OF_ARRAY_DOESNT_MATCH_SIZE_OF_FIXEDARRAY_COLUMN);
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < n; ++i)
|
|
|
|
|
data->insert(array[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void insertDefault()
|
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0; i < n; ++i)
|
|
|
|
|
data->insertDefault();
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-13 16:17:10 +00:00
|
|
|
|
void clear()
|
|
|
|
|
{
|
2011-08-07 02:08:22 +00:00
|
|
|
|
data->clear();
|
2010-05-13 16:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Более эффективные методы манипуляции */
|
|
|
|
|
IColumn & getData()
|
|
|
|
|
{
|
|
|
|
|
return *data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const IColumn & getData() const
|
|
|
|
|
{
|
|
|
|
|
return *data;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 02:08:22 +00:00
|
|
|
|
protected:
|
2011-08-09 19:19:00 +00:00
|
|
|
|
ColumnPtr data;
|
2010-05-13 16:17:10 +00:00
|
|
|
|
const size_t n;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|