From 4de40e438e67f18e1371e2eceb79b21ed873e325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Donin=20de=20Rosi=C3=A8re?= Date: Tue, 29 Jan 2019 09:22:03 +0100 Subject: [PATCH] Support of Nullable types in MySQL tables --- .../src/TableFunctions/TableFunctionMySQL.cpp | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/dbms/src/TableFunctions/TableFunctionMySQL.cpp b/dbms/src/TableFunctions/TableFunctionMySQL.cpp index cccfb76dd80..a90bdc2aba6 100644 --- a/dbms/src/TableFunctions/TableFunctionMySQL.cpp +++ b/dbms/src/TableFunctions/TableFunctionMySQL.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -34,49 +35,53 @@ namespace ErrorCodes } -DataTypePtr getDataType(const String & mysql_data_type, bool is_unsigned, size_t length) +DataTypePtr getDataType(const String & mysql_data_type, bool is_nullable, bool is_unsigned, size_t length) { + DataTypePtr res; if (mysql_data_type == "tinyint") { if (is_unsigned) - return std::make_shared(); + res = std::make_shared(); else - return std::make_shared(); + res = std::make_shared(); } - if (mysql_data_type == "smallint") + else if (mysql_data_type == "smallint") { if (is_unsigned) - return std::make_shared(); + res = std::make_shared(); else - return std::make_shared(); + res = std::make_shared(); } - if (mysql_data_type == "int" || mysql_data_type == "mediumint") + else if (mysql_data_type == "int" || mysql_data_type == "mediumint") { if (is_unsigned) - return std::make_shared(); + res = std::make_shared(); else - return std::make_shared(); + res = std::make_shared(); } - if (mysql_data_type == "bigint") + else if (mysql_data_type == "bigint") { if (is_unsigned) - return std::make_shared(); + res = std::make_shared(); else - return std::make_shared(); + res = std::make_shared(); } - if (mysql_data_type == "float") - return std::make_shared(); - if (mysql_data_type == "double") - return std::make_shared(); - if (mysql_data_type == "date") - return std::make_shared(); - if (mysql_data_type == "datetime" || mysql_data_type == "timestamp") - return std::make_shared(); - if (mysql_data_type == "binary") - return std::make_shared(length); - - /// Also String is fallback for all unknown types. - return std::make_shared(); + else if (mysql_data_type == "float") + res = std::make_shared(); + else if (mysql_data_type == "double") + res = std::make_shared(); + else if (mysql_data_type == "date") + res = std::make_shared(); + else if (mysql_data_type == "datetime" || mysql_data_type == "timestamp") + res = std::make_shared(); + else if (mysql_data_type == "binary") + res = std::make_shared(length); + else + /// Also String is fallback for all unknown types. + res = std::make_shared(); + if(is_nullable) + res = std::make_shared(res); + return res; } @@ -153,10 +158,10 @@ StoragePtr TableFunctionMySQL::executeImpl(const ASTPtr & ast_function, const Co (*block.getByPosition(0).column)[i].safeGet(), getDataType( (*block.getByPosition(1).column)[i].safeGet(), + (*block.getByPosition(2).column)[i].safeGet(), (*block.getByPosition(3).column)[i].safeGet(), (*block.getByPosition(4).column)[i].safeGet())); - /// TODO is_nullable is ignored. } auto res = StorageMySQL::create(