Skip to content

Commit

Permalink
Support Enums type for MySQL engine ClickHouse#3985
Browse files Browse the repository at this point in the history
  • Loading branch information
BohuTANG committed Jun 27, 2020
1 parent 3e6da7d commit f609fd3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Core/ExternalResultDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <DataTypes/DataTypeString.h>
#include <DataTypes/DataTypeUUID.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeEnum.h>
#include <Common/typeid_cast.h>
#include <ext/range.h>

Expand Down Expand Up @@ -60,6 +61,10 @@ void ExternalResultDescription::init(const Block & sample_block_)
types.emplace_back(ValueType::vtDateTime, is_nullable);
else if (typeid_cast<const DataTypeUUID *>(type))
types.emplace_back(ValueType::vtUUID, is_nullable);
else if (typeid_cast<const DataTypeEnum8 *>(type))
types.emplace_back(ValueType::vtString, is_nullable);
else if (typeid_cast<const DataTypeEnum16 *>(type))
types.emplace_back(ValueType::vtString, is_nullable);
else
throw Exception{"Unsupported type " + type->getName(), ErrorCodes::UNKNOWN_TYPE};
}
Expand Down
6 changes: 6 additions & 0 deletions src/Storages/StorageMySQL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <Interpreters/evaluateConstantExpression.h>
#include <Core/Settings.h>
#include <Interpreters/Context.h>
#include <DataTypes/DataTypeString.h>
#include <DataStreams/IBlockOutputStream.h>
#include <Formats/FormatFactory.h>
#include <Common/parseAddress.h>
Expand Down Expand Up @@ -85,6 +86,11 @@ Pipes StorageMySQL::read(
for (const String & column_name : column_names_)
{
auto column_data = metadata_snapshot->getColumns().getPhysical(column_name);

WhichDataType which(column_data.type);
/// Convert enum to string.
if (which.isEnum())
column_data.type = std::make_shared<DataTypeString>();
sample_block.insert({ column_data.type, column_data.name });
}

Expand Down

0 comments on commit f609fd3

Please sign in to comment.