Less dependencies [#CLICKHOUSE-2].

This commit is contained in:
Alexey Milovidov 2017-04-16 08:40:17 +03:00
parent 189b58b6c6
commit 41e97787e3
35 changed files with 120 additions and 119 deletions

View File

@ -4,7 +4,7 @@
#include <algorithm> #include <algorithm>
#include <climits> #include <climits>
#include <sstream> #include <sstream>
#include <common/Common.h> #include <common/Types.h>
#include <IO/ReadBuffer.h> #include <IO/ReadBuffer.h>
#include <IO/ReadHelpers.h> #include <IO/ReadHelpers.h>
#include <IO/WriteHelpers.h> #include <IO/WriteHelpers.h>

View File

@ -5,7 +5,7 @@
#include <climits> #include <climits>
#include <sstream> #include <sstream>
#include <AggregateFunctions/ReservoirSampler.h> #include <AggregateFunctions/ReservoirSampler.h>
#include <common/Common.h> #include <common/Types.h>
#include <Common/HashTable/Hash.h> #include <Common/HashTable/Hash.h>
#include <IO/ReadBuffer.h> #include <IO/ReadBuffer.h>
#include <IO/ReadHelpers.h> #include <IO/ReadHelpers.h>

View File

@ -2,7 +2,7 @@
#include <math.h> #include <math.h>
#include <common/Common.h> #include <common/Types.h>
#include <IO/WriteBuffer.h> #include <IO/WriteBuffer.h>
#include <IO/WriteHelpers.h> #include <IO/WriteHelpers.h>
@ -14,7 +14,7 @@
#include <Common/HashTable/Hash.h> #include <Common/HashTable/Hash.h>
/** Approximate calculation of anything, as a rule, is constructed according to the following scheme: /** Approximate calculation of anything, as usual, is constructed according to the following scheme:
  * - some data structure is used to calculate the value of X;   * - some data structure is used to calculate the value of X;
  * - Not all values are added to the data structure, but only selected ones (according to some selectivity criteria);   * - Not all values are added to the data structure, but only selected ones (according to some selectivity criteria);
  * - after processing all elements, the data structure is in some state S;   * - after processing all elements, the data structure is in some state S;

View File

@ -9,7 +9,6 @@
#include <Common/Exception.h> #include <Common/Exception.h>
#include <IO/WriteHelpers.h> #include <IO/WriteHelpers.h>
#include <common/Common.h>
#include <Poco/String.h> #include <Poco/String.h>
Collator::Collator(const std::string & locale_) : locale(Poco::toLower(locale_)) Collator::Collator(const std::string & locale_) : locale(Poco::toLower(locale_))

View File

@ -17,7 +17,7 @@
#include <IO/ReadHelpers.h> #include <IO/ReadHelpers.h>
#include <IO/WriteHelpers.h> #include <IO/WriteHelpers.h>
#include <common/Common.h> #include <common/Types.h>
#define SMALL_READ_WRITE_BUFFER_SIZE 16 #define SMALL_READ_WRITE_BUFFER_SIZE 16

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <common/Common.h> #include <common/Types.h>
#include <Common/HyperLogLogBiasEstimator.h> #include <Common/HyperLogLogBiasEstimator.h>
#include <Common/CompactArray.h> #include <Common/CompactArray.h>
#include <Common/HashTable/Hash.h> #include <Common/HashTable/Hash.h>

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <atomic> #include <atomic>
#include <common/Common.h> #include <common/Types.h>
#include <Common/CurrentMetrics.h> #include <Common/CurrentMetrics.h>

View File

@ -3,7 +3,7 @@
#include <time.h> #include <time.h>
#include <mutex> #include <mutex>
#include <Poco/ScopedLock.h> #include <Poco/ScopedLock.h>
#include <common/Common.h> #include <common/Types.h>
#ifdef __APPLE__ #ifdef __APPLE__
#include <common/apple_rt.h> #include <common/apple_rt.h>

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <atomic> #include <atomic>
#include <common/Common.h> #include <common/Types.h>
#include <Core/Defines.h> #include <Core/Defines.h>

View File

@ -1,16 +1,18 @@
#pragma once #pragma once
#include <common/Common.h> /// VisitID_t #include <common/MetrikaTypes.h>
#include <common/LocalDate.h> #include <common/LocalDate.h>
#include <common/LocalDateTime.h> #include <common/LocalDateTime.h>
#include <Core/Field.h> #include <Core/Field.h>
#include <mysqlxx/Null.h> #include <mysqlxx/Null.h>
/// This is for Yandex.Metrica code.
namespace DB namespace DB
{ {
/// Перевести что угодно в Field. /// Перевести что угодно в Field.
template <typename T> template <typename T>
inline Field toField(const T & x) inline Field toField(const T & x)
@ -33,11 +35,4 @@ inline Field toField(const VisitID_t & x)
return toField(static_cast<UInt64>(x)); return toField(static_cast<UInt64>(x));
} }
template <typename T>
inline Field toField(const mysqlxx::Null<T> & x)
{
return x.isNull() ? Field(Null()) : toField(static_cast<const T &>(x));
}
} }

View File

@ -2,7 +2,7 @@
#include <vector> #include <vector>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <common/Common.h> #include <common/Types.h>
#include <common/singleton.h> #include <common/singleton.h>

View File

@ -3,7 +3,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <Poco/Exception.h> #include <Poco/Exception.h>
#include <common/Common.h> #include <common/Types.h>
#include <Core/StringRef.h> #include <Core/StringRef.h>

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <common/singleton.h> #include <common/singleton.h>
#include <common/Common.h> #include <common/Types.h>
/** @brief Класс, позволяющий узнавать, принадлежит ли поисковая система или операционная система /** @brief Класс, позволяющий узнавать, принадлежит ли поисковая система или операционная система

View File

@ -53,6 +53,8 @@ namespace mysqlxx
{ {
throw Poco::Exception("Cannot unquote Tuple with mysqlxx::unquote."); throw Poco::Exception("Cannot unquote Tuple with mysqlxx::unquote.");
} }
template <> inline VisitID_t Value::get<VisitID_t>() const { return VisitID_t(getUInt()); }
} }
@ -97,5 +99,12 @@ inline void writeQuoted(const mysqlxx::Null<T> & x, WriteBuffer & buf)
writeText(static_cast<const T &>(x), buf); writeText(static_cast<const T &>(x), buf);
} }
template <typename T>
inline Field toField(const mysqlxx::Null<T> & x)
{
return x.isNull() ? Field(Null()) : toField(static_cast<const T &>(x));
}
} }

View File

@ -11,7 +11,7 @@ namespace DB
class ReadBufferFromString : public ReadBufferFromMemory class ReadBufferFromString : public ReadBufferFromMemory
{ {
public: public:
/// std::string or mysqlxx::Value /// std::string or something similar
template <typename S> template <typename S>
ReadBufferFromString(const S & s) : ReadBufferFromMemory(s.data(), s.size()) {} ReadBufferFromString(const S & s) : ReadBufferFromMemory(s.data(), s.size()) {}
}; };

View File

@ -1,13 +1,12 @@
#include <sstream>
#include <mysqlxx/Manip.h>
#include <Core/Defines.h> #include <Core/Defines.h>
#include <Common/PODArray.h> #include <Common/PODArray.h>
#include <Common/StringUtils.h> #include <Common/StringUtils.h>
#include <IO/ReadHelpers.h> #include <IO/WriteHelpers.h>
#include <IO/WriteBufferFromString.h>
#include <IO/Operators.h>
#include <common/find_first_symbols.h> #include <common/find_first_symbols.h>
namespace DB namespace DB
{ {
@ -22,15 +21,18 @@ namespace ErrorCodes
static void __attribute__((__noinline__)) throwAtAssertionFailed(const char * s, ReadBuffer & buf) static void __attribute__((__noinline__)) throwAtAssertionFailed(const char * s, ReadBuffer & buf)
{ {
std::stringstream message; std::string message;
message << "Cannot parse input: expected " << mysqlxx::escape << s; {
WriteBufferFromString out(message);
out << "Cannot parse input: expected " << escape << s;
if (buf.eof()) if (buf.eof())
message << " at end of stream."; out << " at end of stream.";
else else
message << " before: " << mysqlxx::escape << String(buf.position(), std::min(SHOW_CHARS_ON_SYNTAX_ERROR, buf.buffer().end() - buf.position())); out << " before: " << escape << String(buf.position(), std::min(SHOW_CHARS_ON_SYNTAX_ERROR, buf.buffer().end() - buf.position()));
}
throw Exception(message.str(), ErrorCodes::CANNOT_PARSE_INPUT_ASSERTION_FAILED); throw Exception(message, ErrorCodes::CANNOT_PARSE_INPUT_ASSERTION_FAILED);
} }
@ -685,25 +687,28 @@ void readException(Exception & e, ReadBuffer & buf, const String & additional_me
readBinary(stack_trace, buf); readBinary(stack_trace, buf);
readBinary(has_nested, buf); readBinary(has_nested, buf);
std::stringstream message_stream; std::string new_message;
{
WriteBufferFromString out(new_message);
if (!additional_message.empty()) if (!additional_message.empty())
message_stream << additional_message << ". "; out << additional_message << ". ";
if (name != "DB::Exception") if (name != "DB::Exception")
message_stream << name << ". "; out << name << ". ";
message_stream << message out << message
<< ". Stack trace:\n\n" << stack_trace; << ". Stack trace:\n\n" << stack_trace;
}
if (has_nested) if (has_nested)
{ {
Exception nested; Exception nested;
readException(nested, buf); readException(nested, buf);
e = Exception(message_stream.str(), nested, code); e = Exception(new_message, nested, code);
} }
else else
e = Exception(message_stream.str(), code); e = Exception(new_message, code);
} }
void readAndThrowException(ReadBuffer & buf, const String & additional_message) void readAndThrowException(ReadBuffer & buf, const String & additional_message)

View File

@ -7,9 +7,7 @@
#include <type_traits> #include <type_traits>
#include <common/Common.h>
#include <common/DateLUT.h> #include <common/DateLUT.h>
#include <common/LocalDate.h> #include <common/LocalDate.h>
#include <common/LocalDateTime.h> #include <common/LocalDateTime.h>

View File

@ -5,7 +5,6 @@
#include <limits> #include <limits>
#include <algorithm> #include <algorithm>
#include <common/Common.h>
#include <common/DateLUT.h> #include <common/DateLUT.h>
#include <common/LocalDate.h> #include <common/LocalDate.h>
#include <common/LocalDateTime.h> #include <common/LocalDateTime.h>

View File

@ -1,7 +1,7 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <common/Common.h> #include <common/Types.h>
#include <IO/ReadHelpers.h> #include <IO/ReadHelpers.h>
#include <IO/WriteHelpers.h> #include <IO/WriteHelpers.h>

View File

@ -6,7 +6,7 @@
#include <Interpreters/executeQuery.h> #include <Interpreters/executeQuery.h>
#include <Interpreters/InterpreterShowTablesQuery.h> #include <Interpreters/InterpreterShowTablesQuery.h>
#include <mysqlxx/Manip.h> #include <iomanip>
namespace DB namespace DB
@ -36,10 +36,10 @@ String InterpreterShowTablesQuery::getRewrittenQuery()
context.assertDatabaseExists(database, false); context.assertDatabaseExists(database, false);
std::stringstream rewritten_query; std::stringstream rewritten_query;
rewritten_query << "SELECT name FROM system.tables WHERE database = " << mysqlxx::quote << database; rewritten_query << "SELECT name FROM system.tables WHERE database = " << std::quoted(database, '\'');
if (!query.like.empty()) if (!query.like.empty())
rewritten_query << " AND name " << (query.not_like ? "NOT " : "") << "LIKE " << mysqlxx::quote << query.like; rewritten_query << " AND name " << (query.not_like ? "NOT " : "") << "LIKE " << std::quoted(query.like, '\'');
return rewritten_query.str(); return rewritten_query.str();
} }

View File

@ -12,8 +12,6 @@
#include <Poco/Net/IPAddress.h> #include <Poco/Net/IPAddress.h>
#include <common/Common.h>
#include <Core/Types.h> #include <Core/Types.h>
#include <Common/Exception.h> #include <Common/Exception.h>
#include <IO/WriteHelpers.h> #include <IO/WriteHelpers.h>

View File

@ -1,5 +1,6 @@
#include <Parsers/ASTAlterQuery.h> #include <Parsers/ASTAlterQuery.h>
#include <mysqlxx/Manip.h> #include <iomanip>
namespace DB namespace DB
{ {
@ -137,7 +138,7 @@ void ASTAlterQuery::formatImpl(const FormatSettings & settings, FormatState & st
<< "PARTITION " << (settings.hilite ? hilite_none : ""); << "PARTITION " << (settings.hilite ? hilite_none : "");
p.partition->formatImpl(settings, state, frame); p.partition->formatImpl(settings, state, frame);
settings.ostr << (settings.hilite ? hilite_keyword : "") settings.ostr << (settings.hilite ? hilite_keyword : "")
<< " FROM " << (settings.hilite ? hilite_none : "") << mysqlxx::quote << p.from; << " FROM " << (settings.hilite ? hilite_none : "") << std::quoted(p.from, '\'');
} }
else if (p.type == ASTAlterQuery::FREEZE_PARTITION) else if (p.type == ASTAlterQuery::FREEZE_PARTITION)
{ {
@ -147,7 +148,7 @@ void ASTAlterQuery::formatImpl(const FormatSettings & settings, FormatState & st
if (!p.with_name.empty()) if (!p.with_name.empty())
{ {
settings.ostr << " " << (settings.hilite ? hilite_keyword : "") << "WITH NAME" << (settings.hilite ? hilite_none : "") settings.ostr << " " << (settings.hilite ? hilite_keyword : "") << "WITH NAME" << (settings.hilite ? hilite_none : "")
<< " " << mysqlxx::quote << p.with_name; << " " << std::quoted(p.with_name, '\'');
} }
} }
else if (p.type == ASTAlterQuery::RESHARD_PARTITION) else if (p.type == ASTAlterQuery::RESHARD_PARTITION)

View File

@ -1,4 +1,4 @@
#include <mysqlxx/Manip.h> #include <iomanip>
#include <Parsers/ASTInsertQuery.h> #include <Parsers/ASTInsertQuery.h>
@ -14,7 +14,7 @@ void ASTInsertQuery::formatImpl(const FormatSettings & settings, FormatState & s
if (!insert_id.empty()) if (!insert_id.empty())
settings.ostr << (settings.hilite ? hilite_keyword : "") << " ID = " << (settings.hilite ? hilite_none : "") settings.ostr << (settings.hilite ? hilite_keyword : "") << " ID = " << (settings.hilite ? hilite_none : "")
<< mysqlxx::quote << insert_id; << std::quoted(insert_id, '\'');
if (columns) if (columns)
{ {

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <mysqlxx/Manip.h> #include <iomanip>
#include <Parsers/IAST.h> #include <Parsers/IAST.h>
#include <Parsers/ASTQueryWithOutput.h> #include <Parsers/ASTQueryWithOutput.h>
@ -50,7 +50,7 @@ protected:
if (!like.empty()) if (!like.empty())
settings.ostr << (settings.hilite ? hilite_keyword : "") << " LIKE " << (settings.hilite ? hilite_none : "") settings.ostr << (settings.hilite ? hilite_keyword : "") << " LIKE " << (settings.hilite ? hilite_none : "")
<< mysqlxx::quote << like; << std::quoted(like, '\'');
} }
} }
}; };

View File

@ -2,7 +2,7 @@
#include <Parsers/IAST.h> #include <Parsers/IAST.h>
#include <Core/Types.h> #include <Core/Types.h>
#include <mysqlxx/Manip.h> #include <iomanip>
namespace DB namespace DB
@ -24,7 +24,7 @@ protected:
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
{ {
std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' '); std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' ');
settings.ostr << settings.nl_or_ws << indent_str << mysqlxx::quote << path << " WEIGHT " << weight; settings.ostr << settings.nl_or_ws << indent_str << std::quoted(path, '\'') << " WEIGHT " << weight;
} }
}; };

View File

@ -28,7 +28,8 @@ add_library (common
src/JSON.cpp src/JSON.cpp
include/common/ApplicationServerExt.h include/common/ApplicationServerExt.h
include/common/Common.h include/common/Types.h
include/common/MetrikaTypes.h
include/common/DateLUT.h include/common/DateLUT.h
include/common/DateLUTImpl.h include/common/DateLUTImpl.h
include/common/LocalDate.h include/common/LocalDate.h

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <common/Common.h> #include <common/Types.h>
#include <common/singleton.h> #include <common/singleton.h>
#include <common/likely.h> #include <common/likely.h>
#include <common/strong_typedef.h> #include <common/strong_typedef.h>

View File

@ -3,7 +3,7 @@
#include <typeinfo> #include <typeinfo>
#include <Poco/Exception.h> #include <Poco/Exception.h>
#include <Core/StringRef.h> #include <Core/StringRef.h>
#include <common/Common.h> #include <common/Types.h>
/** Очень простой класс для чтения JSON (или его кусочков). /** Очень простой класс для чтения JSON (или его кусочков).

View File

@ -1,31 +1,9 @@
#pragma once #pragma once
#include <string>
#include <functional> #include <functional>
#include <common/Types.h>
#include <Poco/Types.h>
#include <common/strong_typedef.h> #include <common/strong_typedef.h>
using Int8 = Poco::Int8;
using Int16 = Poco::Int16;
using Int32 = Poco::Int32;
using Int64 = Poco::Int64;
using UInt8 = Poco::UInt8;
using UInt16 = Poco::UInt16;
using UInt32 = Poco::UInt32;
using UInt64 = Poco::UInt64;
/// Обход проблемы с тем, что KDevelop не видит time_t и size_t (для подсветки синтаксиса).
#ifdef IN_KDEVELOP_PARSER
using time_t = Int64;
using size_t = UInt64;
#endif
/// The following is for Yandex.Metrika code. Not used by ClickHouse. /// The following is for Yandex.Metrika code. Not used by ClickHouse.

View File

@ -0,0 +1,20 @@
#pragma once
#include <Poco/Types.h>
using Int8 = Poco::Int8;
using Int16 = Poco::Int16;
using Int32 = Poco::Int32;
using Int64 = Poco::Int64;
using UInt8 = Poco::UInt8;
using UInt16 = Poco::UInt16;
using UInt32 = Poco::UInt32;
using UInt64 = Poco::UInt64;
/// Обход проблемы с тем, что KDevelop не видит time_t и size_t (для подсветки синтаксиса).
#ifdef IN_KDEVELOP_PARSER
using time_t = Int64;
using size_t = UInt64;
#endif

View File

@ -19,7 +19,7 @@
#include <Poco/FileChannel.h> #include <Poco/FileChannel.h>
#include <Poco/SyslogChannel.h> #include <Poco/SyslogChannel.h>
#include <Poco/Version.h> #include <Poco/Version.h>
#include <common/Common.h> #include <common/Types.h>
#include <common/logger_useful.h> #include <common/logger_useful.h>
#include <daemon/GraphiteWriter.h> #include <daemon/GraphiteWriter.h>
#include <Common/ConfigProcessor.h> #include <Common/ConfigProcessor.h>

View File

@ -9,7 +9,7 @@
#include <limits> #include <limits>
#include <common/exp10.h> #include <common/exp10.h>
#include <common/Common.h> #include <common/Types.h>
#include <common/DateLUT.h> #include <common/DateLUT.h>
#include <mysqlxx/Types.h> #include <mysqlxx/Types.h>
@ -257,8 +257,6 @@ template <> inline std::string Value::get<std::string >()
template <> inline LocalDate Value::get<LocalDate >() const { return getDate(); } template <> inline LocalDate Value::get<LocalDate >() const { return getDate(); }
template <> inline LocalDateTime Value::get<LocalDateTime >() const { return getDateTime(); } template <> inline LocalDateTime Value::get<LocalDateTime >() const { return getDateTime(); }
template <> inline VisitID_t Value::get<VisitID_t >() const { return VisitID_t(getUInt()); }
template <typename T> inline T Value::get() const { return T(*this); } template <typename T> inline T Value::get() const { return T(*this); }

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include <common/Common.h> #include <common/Types.h>
#include <future> #include <future>
#include <memory> #include <memory>
#include <vector> #include <vector>

View File

@ -5,7 +5,7 @@
#include <emmintrin.h> #include <emmintrin.h>
#endif #endif
#include <common/Common.h> #include <common/Types.h>
#include <Poco/NumberParser.h> #include <Poco/NumberParser.h>
#include <IO/ReadBufferFromFileDescriptor.h> #include <IO/ReadBufferFromFileDescriptor.h>