mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-23 10:10:50 +00:00
Merge
This commit is contained in:
commit
dddd40e3f2
@ -125,9 +125,6 @@ typedef std::list<Block> BlocksList;
|
||||
/// Сравнить типы столбцов у блоков. Порядок столбцов имеет значение. Имена не имеют значения.
|
||||
bool blocksHaveEqualStructure(const Block & lhs, const Block & rhs);
|
||||
|
||||
/// Проверить, что типы столбцов у блоков совместимые. Порядок имеет значение. Имена не имеют значения.
|
||||
bool blocksHaveCompatibleStructure(const Block& lhs, const Block& rhs);
|
||||
|
||||
}
|
||||
|
||||
namespace std
|
||||
|
@ -29,8 +29,6 @@ public:
|
||||
{
|
||||
return "FixedString(" + toString(n) + ")";
|
||||
}
|
||||
|
||||
bool behavesAsString() const { return true; }
|
||||
|
||||
DataTypePtr clone() const
|
||||
{
|
||||
|
@ -22,8 +22,6 @@ public:
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
|
||||
bool behavesAsString() const { return true; }
|
||||
|
||||
DataTypePtr clone() const
|
||||
{
|
||||
|
@ -31,9 +31,6 @@ public:
|
||||
/// true для чисел, false для даты и даты-с-временем.
|
||||
virtual bool behavesAsNumber() const { return false; }
|
||||
|
||||
/// Является ли тип строковым.
|
||||
virtual bool behavesAsString() const { return false; }
|
||||
|
||||
/// Клонировать
|
||||
virtual SharedPtr<IDataType> clone() const = 0;
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
struct InterpreterSelectQueryWithContext;
|
||||
|
||||
/** Интерпретирует запрос SELECT. Возвращает поток блоков с результатами выполнения запроса до стадии to_stage.
|
||||
*/
|
||||
@ -80,7 +81,8 @@ private:
|
||||
/// Выполнить один запрос SELECT из цепочки UNION ALL.
|
||||
void executeSingleQuery(bool should_perform_union_hint = true);
|
||||
|
||||
bool isFirstSelectInsideUnionAll() const;
|
||||
/// Является ли это первым запросом цепочки UNION ALL имеющей длниу >= 2.
|
||||
bool isFirstSelectInsideUnionAll() const;
|
||||
|
||||
/** Из какой таблицы читать. JOIN-ы не поддерживаются.
|
||||
*/
|
||||
@ -135,6 +137,8 @@ private:
|
||||
Logger * log;
|
||||
};
|
||||
|
||||
/** Интерпретатор SELECT вместе с контекстом.
|
||||
*/
|
||||
struct InterpreterSelectQueryWithContext
|
||||
{
|
||||
InterpreterSelectQueryWithContext(
|
||||
|
@ -16,24 +16,6 @@
|
||||
|
||||
#include <DB/Parsers/formatAST.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
bool typesAreCompatible(const DB::IDataType & lhs, const DB::IDataType & rhs)
|
||||
{
|
||||
if (lhs.behavesAsNumber() && rhs.behavesAsNumber())
|
||||
return true;
|
||||
|
||||
if (lhs.behavesAsString() && rhs.behavesAsString())
|
||||
return true;
|
||||
|
||||
if (lhs.getName() == rhs.getName())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -389,23 +371,6 @@ bool blocksHaveEqualStructure(const Block & lhs, const Block & rhs)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool blocksHaveCompatibleStructure(const Block & lhs, const Block & rhs)
|
||||
{
|
||||
size_t columns = lhs.columns();
|
||||
if (rhs.columns() != columns)
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < columns; ++i)
|
||||
{
|
||||
const IDataType & lhs_type = *lhs.getByPosition(i).type;
|
||||
const IDataType & rhs_type = *rhs.getByPosition(i).type;
|
||||
|
||||
if (!typesAreCompatible(lhs_type, rhs_type))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Block::clear()
|
||||
{
|
||||
|
@ -38,7 +38,8 @@ bool ParserSelectQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, Expected &
|
||||
ParserString s_order("ORDER", true, true);
|
||||
ParserString s_limit("LIMIT", true, true);
|
||||
ParserString s_format("FORMAT", true, true);
|
||||
ParserString s_union_all("UNION ALL", true, true);
|
||||
ParserString s_union("UNION", true, true);
|
||||
ParserString s_all("ALL", true, true);
|
||||
|
||||
ParserNotEmptyExpressionList exp_list;
|
||||
ParserExpressionWithOptionalAlias exp_elem;
|
||||
@ -291,17 +292,22 @@ bool ParserSelectQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, Expected &
|
||||
}
|
||||
|
||||
// UNION ALL select query
|
||||
if (s_union_all.ignore(pos, end, expected))
|
||||
if (s_union.ignore(pos, end, expected))
|
||||
{
|
||||
ws.ignore(pos, end);
|
||||
|
||||
ParserSelectQuery select_p;
|
||||
if (!select_p.parse(pos, end, select_query->next_union_all, expected))
|
||||
if (s_all.ignore(pos, end, expected))
|
||||
{
|
||||
ParserSelectQuery select_p;
|
||||
if (!select_p.parse(pos, end, select_query->next_union_all, expected))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
ws.ignore(pos, end);
|
||||
}
|
||||
|
||||
|
||||
select_query->children.push_back(select_query->select_expression_list);
|
||||
if (select_query->database)
|
||||
select_query->children.push_back(select_query->database);
|
||||
|
@ -239,16 +239,16 @@ void formatAST(const ASTSelectQuery & ast, std::ostream & s, size_t indent, bo
|
||||
formatAST(*ast.format, s, indent, hilite, one_line);
|
||||
}
|
||||
|
||||
if (!ast.next_union_all.isNull())
|
||||
{
|
||||
s << (hilite ? hilite_keyword : "") << nl_or_ws << indent_str << "UNION ALL " << nl_or_ws << (hilite ? hilite_none : "");
|
||||
if (ast.next_union_all)
|
||||
{
|
||||
s << (hilite ? hilite_keyword : "") << nl_or_ws << indent_str << "UNION ALL " << nl_or_ws << (hilite ? hilite_none : "");
|
||||
|
||||
// NOTE Мы можем безопасно применить static_cast вместо typeid_cast, потому что знаем, что в цепочке UNION ALL
|
||||
// имеются только деревья типа SELECT.
|
||||
const ASTSelectQuery & next_ast = static_cast<const ASTSelectQuery &>(*ast.next_union_all);
|
||||
// NOTE Мы можем безопасно применить static_cast вместо typeid_cast, потому что знаем, что в цепочке UNION ALL
|
||||
// имеются только деревья типа SELECT.
|
||||
const ASTSelectQuery & next_ast = static_cast<const ASTSelectQuery &>(*ast.next_union_all);
|
||||
|
||||
formatAST(next_ast, s, indent, hilite, one_line, need_parens);
|
||||
}
|
||||
formatAST(next_ast, s, indent, hilite, one_line, need_parens);
|
||||
}
|
||||
}
|
||||
|
||||
void formatAST(const ASTSubquery & ast, std::ostream & s, size_t indent, bool hilite, bool one_line, bool need_parens)
|
||||
|
@ -1,8 +1,8 @@
|
||||
DROP TABLE IF EXISTS data2013;
|
||||
DROP TABLE IF EXISTS data2014;
|
||||
|
||||
CREATE TABLE data2013 (name String, value UInt32) ENGINE = TinyLog;
|
||||
CREATE TABLE data2014 (name String, value UInt32) ENGINE = TinyLog;
|
||||
CREATE TABLE data2013 (name String, value UInt32) ENGINE = Memory;
|
||||
CREATE TABLE data2014 (name String, value UInt32) ENGINE = Memory;
|
||||
|
||||
INSERT INTO data2013(name,value) VALUES('Alice', 1000);
|
||||
INSERT INTO data2013(name,value) VALUES('Bob', 2000);
|
||||
|
Loading…
Reference in New Issue
Block a user