提交 667db6b5 编写于 作者: A alexey-milovidov 提交者: GitHub

Merge pull request #182 from artpaul/master

move function bodies to cpp
......@@ -829,6 +829,7 @@ add_library (dbms
src/Parsers/ASTIdentifier.cpp
src/Parsers/ASTSampleRatio.cpp
src/Parsers/ASTTablesInSelectQuery.cpp
src/Parsers/CommonParsers.cpp
src/Parsers/IAST.cpp
src/Parsers/IParserBase.cpp
src/Parsers/ExpressionElementParsers.cpp
......
#pragma once
#include <DB/DataStreams/IProfilingBlockInputStream.h>
#include <DB/Common/HashTable/HashSet.h>
#include <DB/Interpreters/AggregationCommon.h>
#include <DB/Common/SipHash.h>
#include <DB/Common/UInt128.h>
#include <DB/DataStreams/IProfilingBlockInputStream.h>
#include <DB/Interpreters/Limits.h>
namespace DB
{
......@@ -22,25 +22,13 @@ public:
String getName() const override { return "Distinct"; }
String getID() const override
{
std::stringstream res;
res << "Distinct(" << children.back()->getID() << ")";
return res.str();
}
String getID() const override;
protected:
Block readImpl() override;
private:
bool checkLimits() const
{
if (max_rows && set.size() > max_rows)
return false;
if (max_bytes && set.getBufferSizeInBytes() > max_bytes)
return false;
return true;
}
private:
bool checkLimits() const;
Names columns_names;
......
......@@ -1299,18 +1299,18 @@ private:
template <typename F>
void dispatchForSourceType(const IDataType & src_type, F && f) const
{
if (auto src_type_concrete = typeid_cast<const DataTypeUInt8 *>(&src_type)) f(UInt8());
else if (auto src_type_concrete = typeid_cast<const DataTypeUInt16 *>(&src_type)) f(UInt16());
else if (auto src_type_concrete = typeid_cast<const DataTypeUInt32 *>(&src_type)) f(UInt32());
else if (auto src_type_concrete = typeid_cast<const DataTypeUInt64 *>(&src_type)) f(UInt64());
else if (auto src_type_concrete = typeid_cast<const DataTypeInt8 *>(&src_type)) f(Int8());
else if (auto src_type_concrete = typeid_cast<const DataTypeInt16 *>(&src_type)) f(Int16());
else if (auto src_type_concrete = typeid_cast<const DataTypeInt32 *>(&src_type)) f(Int32());
else if (auto src_type_concrete = typeid_cast<const DataTypeInt64 *>(&src_type)) f(Int64());
else if (auto src_type_concrete = typeid_cast<const DataTypeFloat32 *>(&src_type)) f(Float32());
else if (auto src_type_concrete = typeid_cast<const DataTypeFloat64 *>(&src_type)) f(Float64());
else if (auto src_type_concrete = typeid_cast<const DataTypeDate *>(&src_type)) f(DataTypeDate::FieldType());
else if (auto src_type_concrete = typeid_cast<const DataTypeDateTime *>(&src_type)) f(DataTypeDateTime::FieldType());
if (typeid_cast<const DataTypeUInt8 *>(&src_type)) f(UInt8());
else if (typeid_cast<const DataTypeUInt16 *>(&src_type)) f(UInt16());
else if (typeid_cast<const DataTypeUInt32 *>(&src_type)) f(UInt32());
else if (typeid_cast<const DataTypeUInt64 *>(&src_type)) f(UInt64());
else if (typeid_cast<const DataTypeInt8 *>(&src_type)) f(Int8());
else if (typeid_cast<const DataTypeInt16 *>(&src_type)) f(Int16());
else if (typeid_cast<const DataTypeInt32 *>(&src_type)) f(Int32());
else if (typeid_cast<const DataTypeInt64 *>(&src_type)) f(Int64());
else if (typeid_cast<const DataTypeFloat32 *>(&src_type)) f(Float32());
else if (typeid_cast<const DataTypeFloat64 *>(&src_type)) f(Float64());
else if (typeid_cast<const DataTypeDate *>(&src_type)) f(DataTypeDate::FieldType());
else if (typeid_cast<const DataTypeDateTime *>(&src_type)) f(DataTypeDateTime::FieldType());
else
throw Exception("Argument for function " + getName() + " must have numeric type.",
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
......
......@@ -144,25 +144,11 @@ private:
void executeSubqueriesInSetsAndJoins(std::unordered_map<String, SubqueryForSet> & subqueries_for_sets);
template <typename Transform>
void transformStreams(Transform && transform)
{
for (auto & stream : streams)
transform(stream);
void transformStreams(Transform && transform);
if (stream_with_non_joined_data)
transform(stream_with_non_joined_data);
}
bool hasNoData() const
{
return streams.empty() && !stream_with_non_joined_data;
}
bool hasMoreThanOneStream() const
{
return streams.size() + (stream_with_non_joined_data ? 1 : 0) > 1;
}
bool hasNoData() const;
bool hasMoreThanOneStream() const;
void ignoreWithTotals();
......
#pragma once
#include <string.h> /// strncmp, strncasecmp
#include <DB/Parsers/IParserBase.h>
namespace DB
{
/** Если прямо сейчас не s, то ошибка.
* Если word_boundary установлен в true, и последний символ строки - словарный (\w),
* то проверяется, что последующий символ строки не словарный.
......@@ -22,26 +18,12 @@ private:
bool case_insensitive;
public:
ParserString(const char * s_, bool word_boundary_ = false, bool case_insensitive_ = false)
: s(s_), s_size(strlen(s)), word_boundary(word_boundary_), case_insensitive(case_insensitive_) {}
ParserString(const char * s_, bool word_boundary_ = false, bool case_insensitive_ = false);
protected:
const char * getName() const { return s; }
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
if (static_cast<ssize_t>(s_size) > end - pos || (case_insensitive ? strncasecmp : strncmp)(pos, s, s_size))
return false;
else
{
if (word_boundary && s_size && isWordCharASCII(s[s_size - 1])
&& pos + s_size != end && isWordCharASCII(pos[s_size]))
return false;
pos += s_size;
return true;
}
}
const char * getName() const override;
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected) override;
};
......@@ -50,74 +32,32 @@ protected:
class ParserWhiteSpace : public IParserBase
{
public:
ParserWhiteSpace(bool allow_newlines_ = true) : allow_newlines(allow_newlines_) {}
ParserWhiteSpace(bool allow_newlines_ = true);
protected:
bool allow_newlines;
const char * getName() const { return "white space"; }
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
Pos begin = pos;
while (pos < end && (*pos == ' ' || *pos == '\t' || (allow_newlines && *pos == '\n') || *pos == '\r' || *pos == '\f'))
++pos;
const char * getName() const override;
return pos != begin;
}
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected) override;
};
class ParserCStyleComment : public IParserBase
{
protected:
const char * getName() const { return "C-style comment"; }
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
if (end - pos >= 4 && pos[0] == '/' && pos[1] == '*')
{
pos += 2;
while (end - pos >= 2 && (pos[0] != '*' || pos[1] != '/'))
++pos;
if (end - pos < 2)
{
expected = "closing of C-style comment '*/'";
return false;
}
else
{
pos += 2;
return true;
}
}
else
return false;
}
const char * getName() const override;
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected) override;
};
class ParserSQLStyleComment : public IParserBase
{
protected:
const char * getName() const { return "SQL-style comment"; }
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
if (end - pos >= 2 && pos[0] == '-' && pos[1] == '-')
{
pos += 2;
while (pos != end && *pos != '\n')
++pos;
if (pos != end)
++pos;
return true;
}
else
return false;
}
const char * getName() const override;
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected) override;
};
......@@ -126,39 +66,23 @@ protected:
class ParserComment : public IParserBase
{
protected:
const char * getName() const { return "comment"; }
const char * getName() const override;
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
ParserCStyleComment p1;
ParserSQLStyleComment p2;
return p1.ignore(pos, end, max_parsed_pos, expected)
|| p2.ignore(pos, end, max_parsed_pos, expected);
}
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected) override;
};
class ParserWhiteSpaceOrComments : public IParserBase
{
public:
ParserWhiteSpaceOrComments(bool allow_newlines_outside_comments_ = true) : allow_newlines_outside_comments(allow_newlines_outside_comments_) {}
ParserWhiteSpaceOrComments(bool allow_newlines_outside_comments_ = true);
protected:
bool allow_newlines_outside_comments;
const char * getName() const { return "white space or comments"; }
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
ParserWhiteSpace p1(allow_newlines_outside_comments);
ParserComment p2;
const char * getName() const override;
bool res = false;
while (p1.ignore(pos, end, max_parsed_pos, expected) || p2.ignore(pos, end, max_parsed_pos, expected))
res = true;
return res;
}
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected) override;
};
}
......@@ -10,8 +10,8 @@ namespace DB
class ParserSelectQuery : public ParserQueryWithOutput
{
protected:
const char * getName() const { return "SELECT query"; }
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected);
const char * getName() const override { return "SELECT query"; }
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected) override;
};
}
......@@ -20,6 +20,12 @@ DistinctBlockInputStream::DistinctBlockInputStream(BlockInputStreamPtr input_, c
children.push_back(input_);
}
String DistinctBlockInputStream::getID() const
{
std::stringstream res;
res << "Distinct(" << children.back()->getID() << ")";
return res.str();
}
Block DistinctBlockInputStream::readImpl()
{
......@@ -114,4 +120,13 @@ Block DistinctBlockInputStream::readImpl()
}
}
bool DistinctBlockInputStream::checkLimits() const
{
if (max_rows && set.size() > max_rows)
return false;
if (max_bytes && set.getBufferSizeInBytes() > max_bytes)
return false;
return true;
}
}
......@@ -1229,6 +1229,28 @@ void InterpreterSelectQuery::executeSubqueriesInSetsAndJoins(SubqueriesForSets &
streams[0] = std::make_shared<CreatingSetsBlockInputStream>(streams[0], subqueries_for_sets, settings.limits);
}
template <typename Transform>
void InterpreterSelectQuery::transformStreams(Transform && transform)
{
for (auto & stream : streams)
transform(stream);
if (stream_with_non_joined_data)
transform(stream_with_non_joined_data);
}
bool InterpreterSelectQuery::hasNoData() const
{
return streams.empty() && !stream_with_non_joined_data;
}
bool InterpreterSelectQuery::hasMoreThanOneStream() const
{
return streams.size() + (stream_with_non_joined_data ? 1 : 0) > 1;
}
void InterpreterSelectQuery::ignoreWithTotals()
{
......
#include <DB/Parsers/CommonParsers.h>
#include <string.h> /// strncmp, strncasecmp
namespace DB {
ParserString::ParserString(const char * s_, bool word_boundary_, bool case_insensitive_)
: s(s_)
, s_size(strlen(s))
, word_boundary(word_boundary_)
, case_insensitive(case_insensitive_)
{
}
const char * ParserString::getName() const
{
return s;
}
bool ParserString::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
if (static_cast<ssize_t>(s_size) > end - pos || (case_insensitive ? strncasecmp : strncmp)(pos, s, s_size))
return false;
else
{
if (word_boundary && s_size && isWordCharASCII(s[s_size - 1])
&& pos + s_size != end && isWordCharASCII(pos[s_size]))
return false;
pos += s_size;
return true;
}
}
ParserWhiteSpace::ParserWhiteSpace(bool allow_newlines_)
: allow_newlines(allow_newlines_)
{
}
const char * ParserWhiteSpace::getName() const
{
return "white space";
}
bool ParserWhiteSpace::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
Pos begin = pos;
while (pos < end && (*pos == ' ' || *pos == '\t' || (allow_newlines && *pos == '\n') || *pos == '\r' || *pos == '\f'))
++pos;
return pos != begin;
}
const char * ParserCStyleComment::getName() const
{
return "C-style comment";
}
bool ParserCStyleComment::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
if (end - pos >= 4 && pos[0] == '/' && pos[1] == '*')
{
pos += 2;
while (end - pos >= 2 && (pos[0] != '*' || pos[1] != '/'))
++pos;
if (end - pos < 2)
{
expected = "closing of C-style comment '*/'";
return false;
}
else
{
pos += 2;
return true;
}
}
else
return false;
}
const char * ParserSQLStyleComment::getName() const
{
return "SQL-style comment";
}
bool ParserSQLStyleComment::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
if (end - pos >= 2 && pos[0] == '-' && pos[1] == '-')
{
pos += 2;
while (pos != end && *pos != '\n')
++pos;
if (pos != end)
++pos;
return true;
}
else
return false;
}
const char * ParserComment::getName() const
{
return "comment";
}
bool ParserComment::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
ParserCStyleComment p1;
ParserSQLStyleComment p2;
return p1.ignore(pos, end, max_parsed_pos, expected)
|| p2.ignore(pos, end, max_parsed_pos, expected);
}
ParserWhiteSpaceOrComments::ParserWhiteSpaceOrComments(bool allow_newlines_outside_comments_)
: allow_newlines_outside_comments(allow_newlines_outside_comments_)
{
}
const char * ParserWhiteSpaceOrComments::getName() const
{
return "white space or comments";
}
bool ParserWhiteSpaceOrComments::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
ParserWhiteSpace p1(allow_newlines_outside_comments);
ParserComment p2;
bool res = false;
while (p1.ignore(pos, end, max_parsed_pos, expected) || p2.ignore(pos, end, max_parsed_pos, expected))
res = true;
return res;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册