Allow to disable ICU (#711)

* Allow to disable ICU [#CLICKHOUSE-2].

* Addition to prev. revision [#CLICKHOUSE-2].

* Addition to prev. revision [#CLICKHOUSE-2].

* Addition to prev. revision [#CLICKHOUSE-2].
This commit is contained in:
alexey-milovidov 2017-04-19 04:06:29 +03:00 committed by GitHub
parent 3ad87ec820
commit 35abae95c8
6 changed files with 77 additions and 30 deletions

View File

@ -1,10 +1,21 @@
set (ICU_PATHS "/usr/local/opt/icu4c/lib") option (ENABLE_ICU "Enable ICU" ON)
set (ICU_INCLUDE_PATHS "/usr/local/opt/icu4c/include")
find_library (ICUI18N icui18n PATHS ${ICU_PATHS})
find_library (ICUUC icuuc PATHS ${ICU_PATHS})
find_library (ICUDATA icudata PATHS ${ICU_PATHS})
set (ICU_LIBS ${ICUI18N} ${ICUUC} ${ICUDATA})
find_path (ICU_INCLUDE_DIR NAMES unicode/unistr.h PATHS ${ICU_INCLUDE_PATHS}) if (ENABLE_ICU)
message (STATUS "Using icu: ${ICU_INCLUDE_DIR} : ${ICU_LIBS}") set (ICU_PATHS "/usr/local/opt/icu4c/lib")
include_directories (${ICU_INCLUDE_DIR}) set (ICU_INCLUDE_PATHS "/usr/local/opt/icu4c/include")
find_library (ICUI18N icui18n PATHS ${ICU_PATHS})
find_library (ICUUC icuuc PATHS ${ICU_PATHS})
find_library (ICUDATA icudata PATHS ${ICU_PATHS})
set (ICU_LIBS ${ICUI18N} ${ICUUC} ${ICUDATA})
find_path (ICU_INCLUDE_DIR NAMES unicode/unistr.h PATHS ${ICU_INCLUDE_PATHS})
include_directories (${ICU_INCLUDE_DIR})
set(USE_ICU 1)
endif ()
if (USE_ICU)
message (STATUS "Using icu=${USE_ICU}: ${ICU_INCLUDE_DIR} : ${ICU_LIBS}")
else ()
message (STATUS "Build without ICU (support for collations and charset conversion functions will be disabled)")
endif ()

View File

@ -1,18 +1,36 @@
#include <Common/Collator.h> #include <Common/Collator.h>
#pragma GCC diagnostic push #include <Common/config.h>
#ifdef __APPLE__ #if USE_ICU
#pragma GCC diagnostic ignored "-Wold-style-cast" #pragma GCC diagnostic push
#ifdef __APPLE__
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#include <unicode/ucol.h>
#pragma GCC diagnostic pop
#else
#pragma GCC diagnostic ignored "-Wunused-private-field"
#endif #endif
#include <unicode/ucol.h>
#pragma GCC diagnostic pop
#include <Common/Exception.h> #include <Common/Exception.h>
#include <IO/WriteHelpers.h> #include <IO/WriteHelpers.h>
#include <Poco/String.h> #include <Poco/String.h>
namespace DB
{
namespace ErrorCodes
{
extern const int UNSUPPORTED_COLLATION_LOCALE;
extern const int COLLATION_COMPARISON_FAILED;
extern const int SUPPORT_IS_DISABLED;
}
}
Collator::Collator(const std::string & locale_) : locale(Poco::toLower(locale_)) Collator::Collator(const std::string & locale_) : locale(Poco::toLower(locale_))
{ {
#if USE_ICU
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
collator = ucol_open(locale.c_str(), &status); collator = ucol_open(locale.c_str(), &status);
@ -21,15 +39,22 @@ Collator::Collator(const std::string & locale_) : locale(Poco::toLower(locale_))
ucol_close(collator); ucol_close(collator);
throw DB::Exception("Unsupported collation locale: " + locale, DB::ErrorCodes::UNSUPPORTED_COLLATION_LOCALE); throw DB::Exception("Unsupported collation locale: " + locale, DB::ErrorCodes::UNSUPPORTED_COLLATION_LOCALE);
} }
#else
throw DB::Exception("Collations support is disabled, because ClickHouse was built without ICU library", DB::ErrorCodes::SUPPORT_IS_DISABLED);
#endif
} }
Collator::~Collator() Collator::~Collator()
{ {
#if USE_ICU
ucol_close(collator); ucol_close(collator);
#endif
} }
int Collator::compare(const char * str1, size_t length1, const char * str2, size_t length2) const int Collator::compare(const char * str1, size_t length1, const char * str2, size_t length2) const
{ {
#if USE_ICU
UCharIterator iter1, iter2; UCharIterator iter1, iter2;
uiter_setUTF8(&iter1, str1, length1); uiter_setUTF8(&iter1, str1, length1);
uiter_setUTF8(&iter2, str2, length2); uiter_setUTF8(&iter2, str2, length2);
@ -47,6 +72,9 @@ int Collator::compare(const char * str1, size_t length1, const char * str2, size
* UCOL_LESS = -1 * UCOL_LESS = -1
*/ */
return compare_result; return compare_result;
#else
return 0;
#endif
} }
const std::string & Collator::getLocale() const const std::string & Collator::getLocale() const

View File

@ -5,16 +5,6 @@
struct UCollator; struct UCollator;
namespace DB
{
namespace ErrorCodes
{
extern const int UNSUPPORTED_COLLATION_LOCALE;
extern const int COLLATION_COMPARISON_FAILED;
}
}
class Collator : private boost::noncopyable class Collator : private boost::noncopyable
{ {
public: public:

View File

@ -2,6 +2,7 @@
// .h autogenerated by cmake ! // .h autogenerated by cmake !
#cmakedefine01 USE_ICU
#cmakedefine01 USE_MYSQL #cmakedefine01 USE_MYSQL
#cmakedefine01 USE_RE2_ST #cmakedefine01 USE_RE2_ST
#cmakedefine01 USE_VECTORCLASS #cmakedefine01 USE_VECTORCLASS

View File

@ -1,3 +1,6 @@
#include <Common/config.h>
#if USE_ICU
#include <Functions/IFunction.h> #include <Functions/IFunction.h>
#include <Functions/ObjectPool.h> #include <Functions/ObjectPool.h>
#include <Functions/FunctionFactory.h> #include <Functions/FunctionFactory.h>
@ -216,3 +219,14 @@ void registerFunctionsCharset(FunctionFactory & factory)
} }
} }
#else
namespace DB
{
class FunctionFactory;
void registerFunctionsCharset(FunctionFactory & factory) {}
}
#endif

View File

@ -1,7 +1,6 @@
option (ENABLE_MYSQL "Enable MySQL" ON) option (ENABLE_MYSQL "Enable MySQL" ON)
if (ENABLE_MYSQL) if (ENABLE_MYSQL)
set (MYSQL_LIB_PATHS set (MYSQL_LIB_PATHS
"/usr/local/opt/mysql/lib" "/usr/local/opt/mysql/lib"
"/usr/local/lib/mysql/" "/usr/local/lib/mysql/"
@ -12,15 +11,13 @@ if (ENABLE_MYSQL)
"/usr/lib/mysql" "/usr/lib/mysql"
"/usr/lib64/mysql" "/usr/lib64/mysql"
"/lib/mysql" "/lib/mysql"
"/lib64/mysql" "/lib64/mysql")
)
set (MYSQL_INCLUDE_PATHS set (MYSQL_INCLUDE_PATHS
"/usr/local/opt/mysql/include" "/usr/local/opt/mysql/include"
"/usr/mysql/include/mysql" "/usr/mysql/include/mysql"
"/usr/local/include/mysql" "/usr/local/include/mysql"
"/usr/include/mysql" "/usr/include/mysql")
)
find_path (MYSQL_INCLUDE_DIR NAMES mysql/mysql.h PATHS ${MYSQL_INCLUDE_PATHS}) find_path (MYSQL_INCLUDE_DIR NAMES mysql/mysql.h PATHS ${MYSQL_INCLUDE_PATHS})
@ -38,7 +35,13 @@ if (ENABLE_MYSQL)
if (MYSQL_FOUND) if (MYSQL_FOUND)
set(USE_MYSQL 1) set(USE_MYSQL 1)
set(MYSQLXX_LIBRARY mysqlxx) set(MYSQLXX_LIBRARY mysqlxx)
else ()
endif () endif ()
endif () endif ()
message (STATUS "Using mysqlclient=${MYSQL_FOUND}: ${MYSQL_INCLUDE_DIR} : ${MYSQLCLIENT_LIB}; static=${STATIC_MYSQLCLIENT_LIB}") if (USE_MYSQL)
message (STATUS "Using mysqlclient=${MYSQL_FOUND}: ${MYSQL_INCLUDE_DIR} : ${MYSQLCLIENT_LIB}; static=${STATIC_MYSQLCLIENT_LIB}")
else ()
message (STATUS "Build without mysqlclient (support for MYSQL dictionary source will be disabled)")
endif ()