#pragma once #include #include namespace DB { namespace ErrorCodes { extern const int UNKNOWN_TYPE; } /** Общая часть реализации MySQLBlockInputStream, MongoDBBlockInputStream, ODBCBlockInputStream. */ struct ExternalResultDescription { enum struct ValueType { UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, Float32, Float64, String, Date, DateTime }; Block sample_block; std::vector types; std::vector names; ConstColumnPlainPtrs sample_columns; void init(const Block & sample_block_) { sample_block = sample_block_; const auto num_columns = sample_block.columns(); types.reserve(num_columns); names.reserve(num_columns); sample_columns.reserve(num_columns); for (const auto idx : ext::range(0, num_columns)) { const auto & column = sample_block.getByPosition(idx); const auto type = column.type.get(); if (typeid_cast(type)) types.push_back(ValueType::UInt8); else if (typeid_cast(type)) types.push_back(ValueType::UInt16); else if (typeid_cast(type)) types.push_back(ValueType::UInt32); else if (typeid_cast(type)) types.push_back(ValueType::UInt64); else if (typeid_cast(type)) types.push_back(ValueType::Int8); else if (typeid_cast(type)) types.push_back(ValueType::Int16); else if (typeid_cast(type)) types.push_back(ValueType::Int32); else if (typeid_cast(type)) types.push_back(ValueType::Int64); else if (typeid_cast(type)) types.push_back(ValueType::Float32); else if (typeid_cast(type)) types.push_back(ValueType::Float64); else if (typeid_cast(type)) types.push_back(ValueType::String); else if (typeid_cast(type)) types.push_back(ValueType::Date); else if (typeid_cast(type)) types.push_back(ValueType::DateTime); else throw Exception{ "Unsupported type " + type->getName(), ErrorCodes::UNKNOWN_TYPE}; names.emplace_back(column.name); sample_columns.emplace_back(column.column.get()); } } }; }