2017-07-13 16:49:09 +00:00
|
|
|
#include <Columns/IColumn.h>
|
2017-07-21 06:35:58 +00:00
|
|
|
#include <Columns/ColumnConst.h>
|
2017-07-13 16:49:09 +00:00
|
|
|
|
2017-08-07 07:31:16 +00:00
|
|
|
#include <Common/Exception.h>
|
|
|
|
#include <Common/escapeForFileName.h>
|
|
|
|
|
|
|
|
#include <Core/Defines.h>
|
|
|
|
|
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
|
2017-07-13 16:49:09 +00:00
|
|
|
#include <DataTypes/IDataType.h>
|
2017-08-07 07:31:16 +00:00
|
|
|
#include <DataTypes/DataTypeNested.h>
|
2017-07-13 16:49:09 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
|
2017-07-13 16:49:09 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-08-07 07:31:16 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int MULTIPLE_STREAMS_REQUIRED;
|
2017-12-09 06:32:22 +00:00
|
|
|
extern const int LOGICAL_ERROR;
|
2017-08-07 07:31:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-13 20:58:19 +00:00
|
|
|
void IDataType::updateAvgValueSizeHint(const IColumn & column, double & avg_value_size_hint)
|
2017-07-13 16:49:09 +00:00
|
|
|
{
|
|
|
|
/// Update the average value size hint if amount of read rows isn't too small
|
|
|
|
size_t column_size = column.size();
|
|
|
|
if (column_size > 10)
|
|
|
|
{
|
|
|
|
double current_avg_value_size = static_cast<double>(column.byteSize()) / column_size;
|
|
|
|
|
|
|
|
/// Heuristic is chosen so that avg_value_size_hint increases rapidly but decreases slowly.
|
|
|
|
if (current_avg_value_size > avg_value_size_hint)
|
|
|
|
avg_value_size_hint = std::min(1024., current_avg_value_size); /// avoid overestimation
|
|
|
|
else if (current_avg_value_size * 2 < avg_value_size_hint)
|
|
|
|
avg_value_size_hint = (current_avg_value_size + avg_value_size_hint * 3) / 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
ColumnPtr IDataType::createConstColumn(size_t size, const Field & field) const
|
|
|
|
{
|
|
|
|
ColumnPtr column = createColumn();
|
|
|
|
column->insert(field);
|
|
|
|
return std::make_shared<ColumnConst>(column, size);
|
|
|
|
}
|
|
|
|
|
2017-08-07 07:31:16 +00:00
|
|
|
|
2017-12-01 20:21:35 +00:00
|
|
|
void IDataType::serializeBinaryBulk(const IColumn &, WriteBuffer &, size_t, size_t) const
|
2017-08-07 07:31:16 +00:00
|
|
|
{
|
|
|
|
throw Exception("Data type " + getName() + " must be serialized with multiple streams", ErrorCodes::MULTIPLE_STREAMS_REQUIRED);
|
|
|
|
}
|
|
|
|
|
2017-12-01 20:21:35 +00:00
|
|
|
void IDataType::deserializeBinaryBulk(IColumn &, ReadBuffer &, size_t, double) const
|
2017-08-07 07:31:16 +00:00
|
|
|
{
|
|
|
|
throw Exception("Data type " + getName() + " must be deserialized with multiple streams", ErrorCodes::MULTIPLE_STREAMS_REQUIRED);
|
|
|
|
}
|
|
|
|
|
2017-12-09 06:32:22 +00:00
|
|
|
size_t IDataType::getSizeOfValueInMemory() const
|
|
|
|
{
|
|
|
|
throw Exception("Value of type " + getName() + " in memory is not of fixed size.", ErrorCodes::LOGICAL_ERROR);
|
|
|
|
}
|
|
|
|
|
2017-08-07 07:31:16 +00:00
|
|
|
|
|
|
|
String IDataType::getFileNameForStream(const String & column_name, const IDataType::SubstreamPath & path)
|
|
|
|
{
|
2017-11-20 02:15:15 +00:00
|
|
|
String nested_table_name = DataTypeNested::extractNestedTableName(column_name);
|
|
|
|
bool is_sizes_of_nested_type = !path.empty() && path.back().type == IDataType::Substream::ArraySizes
|
|
|
|
&& nested_table_name != column_name;
|
|
|
|
|
2017-08-07 07:31:16 +00:00
|
|
|
size_t array_level = 0;
|
2017-11-20 02:15:15 +00:00
|
|
|
String stream_name = escapeForFileName(is_sizes_of_nested_type ? nested_table_name : column_name);
|
2017-12-03 02:59:59 +00:00
|
|
|
for (const Substream & elem : path)
|
2017-08-07 07:31:16 +00:00
|
|
|
{
|
2017-12-03 02:59:59 +00:00
|
|
|
if (elem.type == Substream::NullMap)
|
2017-12-02 22:12:27 +00:00
|
|
|
stream_name += ".null";
|
2017-12-03 02:59:59 +00:00
|
|
|
else if (elem.type == Substream::ArraySizes)
|
2017-12-03 06:55:56 +00:00
|
|
|
stream_name += ".size" + toString(array_level);
|
2017-12-03 02:59:59 +00:00
|
|
|
else if (elem.type == Substream::ArrayElements)
|
2017-08-07 07:31:16 +00:00
|
|
|
++array_level;
|
2017-12-03 02:59:59 +00:00
|
|
|
else if (elem.type == Substream::TupleElement)
|
|
|
|
stream_name += "." + toString(elem.tuple_element);
|
2017-08-07 07:31:16 +00:00
|
|
|
}
|
|
|
|
return stream_name;
|
|
|
|
}
|
|
|
|
|
2017-09-04 01:11:00 +00:00
|
|
|
|
|
|
|
void IDataType::insertDefaultInto(IColumn & column) const
|
|
|
|
{
|
|
|
|
column.insertDefault();
|
2017-07-13 16:49:09 +00:00
|
|
|
}
|
2017-09-04 14:04:35 +00:00
|
|
|
|
|
|
|
}
|