clickhouse: alter doesn't need quotes anymore [#METR-11063]

This commit is contained in:
Pavel Kartavyy 2014-05-20 20:46:33 +04:00
parent 5d1e8a5a3c
commit f2d2dd2739
5 changed files with 42 additions and 38 deletions

View File

@ -2,6 +2,9 @@
#include <DB/Parsers/IParserBase.h>
#include <DB/Parsers/ExpressionElementParsers.h>
#include <DB/Parsers/ASTNameTypePair.h>
#include <DB/Parsers/ASTIdentifier.h>
#include <DB/Parsers/CommonParsers.h>
namespace DB
@ -42,14 +45,44 @@ protected:
};
/** Имя и тип через пробел. Например, URL String. */
class ParserNameTypePair : public IParserBase
template <class NameParser>
class IParserNameTypePair : public IParserBase
{
protected:
const char * getName() const { return "name and type pair"; }
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, const char *& expected);
};
/** Имя и тип через пробел. Например, URL String. */
typedef IParserNameTypePair<ParserIdentifier> ParserNameTypePair;
/** Имя и тип через пробел. Имя может содержать точку. Например, Hits.URL String. */
typedef IParserNameTypePair<ParserCompoundIdentifier> ParserCompoundNameTypePair;
template <class NameParser>
bool IParserNameTypePair<NameParser>::parseImpl(Pos & pos, Pos end, ASTPtr & node, const char *& expected)
{
NameParser name_parser;
ParserIdentifierWithOptionalParameters type_parser;
ParserWhiteSpaceOrComments ws_parser;
Pos begin = pos;
ASTPtr name, type;
if (name_parser.parse(pos, end, name, expected)
&& ws_parser.ignore(pos, end, expected)
&& type_parser.parse(pos, end, type, expected))
{
ASTNameTypePair * name_type_pair = new ASTNameTypePair(StringRange(begin, pos));
node = name_type_pair;
name_type_pair->name = dynamic_cast<ASTIdentifier &>(*name).name;
name_type_pair->type = type;
name_type_pair->children.push_back(type);
return true;
}
pos = begin;
return false;
}
/** Список столбцов. */
class ParserNameTypePairList : public IParserBase

View File

@ -6,6 +6,7 @@
#include <boost/concept_check.hpp>
#include <DB/Parsers/ASTIdentifier.h>
#include <DB/Parsers/ExpressionElementParsers.h>
#include <DB/Parsers/ASTAlterQuery.h>
namespace DB
@ -27,8 +28,8 @@ bool ParserAlterQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, const char *
ParserString s_drop("DROP", true, true);
ParserString s_comma(",");
ParserIdentifier parser_name;
ParserNameTypePair parser_name_type;
ParserCompoundIdentifier parser_name;
ParserCompoundNameTypePair parser_name_type;
ASTPtr table;
ASTPtr database;

View File

@ -1,10 +1,7 @@
#include <DB/Parsers/ASTFunction.h>
#include <DB/Parsers/ASTIdentifier.h>
#include <DB/Parsers/ASTNameTypePair.h>
#include <DB/Parsers/ASTExpressionList.h>
#include <DB/Parsers/ASTCreateQuery.h>
#include <DB/Parsers/CommonParsers.h>
#include <DB/Parsers/ExpressionListParsers.h>
#include <DB/Parsers/ParserCreateQuery.h>
#include <DB/Parsers/ParserSelectQuery.h>
@ -101,33 +98,6 @@ bool ParserIdentifierWithOptionalParameters::parseImpl(Pos & pos, Pos end, ASTPt
return false;
}
bool ParserNameTypePair::parseImpl(Pos & pos, Pos end, ASTPtr & node, const char *& expected)
{
ParserIdentifier name_parser;
ParserIdentifierWithOptionalParameters type_parser;
ParserWhiteSpaceOrComments ws_parser;
Pos begin = pos;
ASTPtr name, type;
if (name_parser.parse(pos, end, name, expected)
&& ws_parser.ignore(pos, end, expected)
&& type_parser.parse(pos, end, type, expected))
{
ASTNameTypePair * name_type_pair = new ASTNameTypePair(StringRange(begin, pos));
node = name_type_pair;
name_type_pair->name = dynamic_cast<ASTIdentifier &>(*name).name;
name_type_pair->type = type;
name_type_pair->children.push_back(type);
return true;
}
pos = begin;
return false;
}
bool ParserNameTypePairList::parseImpl(Pos & pos, Pos end, ASTPtr & node, const char *& expected)
{
return ParserList(ParserPtr(new ParserNameTypePair), ParserPtr(new ParserString(",")), false).parse(pos, end, node, expected);

View File

@ -9,7 +9,7 @@ ALTER TABLE alter_test ADD COLUMN Added2 UInt32;
ALTER TABLE alter_test ADD COLUMN Added1 UInt32 AFTER Added0;
ALTER TABLE alter_test ADD COLUMN AddedNested1 Nested(A UInt32, B UInt64) AFTER Added2;
ALTER TABLE alter_test ADD COLUMN `AddedNested1.C` Array(String) AFTER `AddedNested1.B`;
ALTER TABLE alter_test ADD COLUMN AddedNested1.C Array(String) AFTER AddedNested1.B;
ALTER TABLE alter_test ADD COLUMN AddedNested2 Nested(A UInt32, B UInt64) AFTER AddedNested1;
DESC TABLE alter_test;

View File

@ -2,9 +2,9 @@ ALTER TABLE alter_test DROP COLUMN ToDrop;
ALTER TABLE alter_test MODIFY COLUMN Added0 String;
ALTER TABLE alter_test DROP COLUMN `NestedColumn.A`;
ALTER TABLE alter_test DROP COLUMN `NestedColumn.S`;
ALTER TABLE alter_test DROP COLUMN NestedColumn.A;
ALTER TABLE alter_test DROP COLUMN NestedColumn.S;
ALTER TABLE alter_test DROP COLUMN `AddedNested1.B`;
ALTER TABLE alter_test DROP COLUMN AddedNested1.B;
DESC TABLE alter_test;