2018-11-28 11:37:12 +00:00
|
|
|
#include "ExternalResultDescription.h"
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <DataTypes/DataTypeDate.h>
|
|
|
|
#include <DataTypes/DataTypeDateTime.h>
|
2018-10-12 02:09:47 +00:00
|
|
|
#include <DataTypes/DataTypeNullable.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <DataTypes/DataTypeString.h>
|
|
|
|
#include <DataTypes/DataTypeUUID.h>
|
|
|
|
#include <DataTypes/DataTypesNumber.h>
|
2017-07-13 20:58:19 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2018-12-10 15:25:45 +00:00
|
|
|
#include <ext/range.h>
|
2016-12-08 02:49:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int UNKNOWN_TYPE;
|
2016-12-08 02:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalResultDescription::init(const Block & sample_block_)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
sample_block = sample_block_;
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2018-10-12 02:09:47 +00:00
|
|
|
types.reserve(sample_block.columns());
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2018-10-12 02:09:47 +00:00
|
|
|
for (auto & elem : sample_block)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2018-10-12 02:09:47 +00:00
|
|
|
/// If default value for column was not provided, use default from data type.
|
|
|
|
if (elem.column->empty())
|
|
|
|
elem.column = elem.type->createColumnConstWithDefaultValue(1)->convertToFullColumnIfConst();
|
|
|
|
|
2018-10-12 02:26:48 +00:00
|
|
|
bool is_nullable = elem.type->isNullable();
|
2018-10-12 02:09:47 +00:00
|
|
|
DataTypePtr type_not_nullable = removeNullable(elem.type);
|
|
|
|
const IDataType * type = type_not_nullable.get();
|
2016-12-08 02:49:04 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (typeid_cast<const DataTypeUInt8 *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtUInt8, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (typeid_cast<const DataTypeUInt16 *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtUInt16, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (typeid_cast<const DataTypeUInt32 *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtUInt32, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (typeid_cast<const DataTypeUInt64 *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtUInt64, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (typeid_cast<const DataTypeInt8 *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtInt8, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (typeid_cast<const DataTypeInt16 *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtInt16, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (typeid_cast<const DataTypeInt32 *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtInt32, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (typeid_cast<const DataTypeInt64 *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtInt64, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (typeid_cast<const DataTypeFloat32 *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtFloat32, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (typeid_cast<const DataTypeFloat64 *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtFloat64, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (typeid_cast<const DataTypeString *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtString, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (typeid_cast<const DataTypeDate *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtDate, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else if (typeid_cast<const DataTypeDateTime *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtDateTime, is_nullable);
|
2018-08-07 19:09:30 +00:00
|
|
|
else if (typeid_cast<const DataTypeUUID *>(type))
|
2019-08-03 11:02:40 +00:00
|
|
|
types.emplace_back(ValueType::vtUUID, is_nullable);
|
2017-04-01 07:20:54 +00:00
|
|
|
else
|
2018-05-07 02:01:11 +00:00
|
|
|
throw Exception{"Unsupported type " + type->getName(), ErrorCodes::UNKNOWN_TYPE};
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2016-12-08 02:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|