mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-04 21:42:39 +00:00
clickhouse: alter doesn't need quotes anymore [#METR-11063]
This commit is contained in:
parent
5d1e8a5a3c
commit
f2d2dd2739
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
#include <DB/Parsers/IParserBase.h>
|
#include <DB/Parsers/IParserBase.h>
|
||||||
#include <DB/Parsers/ExpressionElementParsers.h>
|
#include <DB/Parsers/ExpressionElementParsers.h>
|
||||||
|
#include <DB/Parsers/ASTNameTypePair.h>
|
||||||
|
#include <DB/Parsers/ASTIdentifier.h>
|
||||||
|
#include <DB/Parsers/CommonParsers.h>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
@ -42,14 +45,44 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** Имя и тип через пробел. Например, URL String. */
|
template <class NameParser>
|
||||||
class ParserNameTypePair : public IParserBase
|
class IParserNameTypePair : public IParserBase
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
const char * getName() const { return "name and type pair"; }
|
const char * getName() const { return "name and type pair"; }
|
||||||
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, const char *& expected);
|
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
|
class ParserNameTypePairList : public IParserBase
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <boost/concept_check.hpp>
|
#include <boost/concept_check.hpp>
|
||||||
|
|
||||||
#include <DB/Parsers/ASTIdentifier.h>
|
#include <DB/Parsers/ASTIdentifier.h>
|
||||||
|
#include <DB/Parsers/ExpressionElementParsers.h>
|
||||||
#include <DB/Parsers/ASTAlterQuery.h>
|
#include <DB/Parsers/ASTAlterQuery.h>
|
||||||
|
|
||||||
namespace DB
|
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_drop("DROP", true, true);
|
||||||
ParserString s_comma(",");
|
ParserString s_comma(",");
|
||||||
|
|
||||||
ParserIdentifier parser_name;
|
ParserCompoundIdentifier parser_name;
|
||||||
ParserNameTypePair parser_name_type;
|
ParserCompoundNameTypePair parser_name_type;
|
||||||
|
|
||||||
ASTPtr table;
|
ASTPtr table;
|
||||||
ASTPtr database;
|
ASTPtr database;
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
#include <DB/Parsers/ASTFunction.h>
|
#include <DB/Parsers/ASTFunction.h>
|
||||||
#include <DB/Parsers/ASTIdentifier.h>
|
#include <DB/Parsers/ASTIdentifier.h>
|
||||||
#include <DB/Parsers/ASTNameTypePair.h>
|
|
||||||
#include <DB/Parsers/ASTExpressionList.h>
|
#include <DB/Parsers/ASTExpressionList.h>
|
||||||
#include <DB/Parsers/ASTCreateQuery.h>
|
#include <DB/Parsers/ASTCreateQuery.h>
|
||||||
|
|
||||||
#include <DB/Parsers/CommonParsers.h>
|
|
||||||
#include <DB/Parsers/ExpressionListParsers.h>
|
#include <DB/Parsers/ExpressionListParsers.h>
|
||||||
#include <DB/Parsers/ParserCreateQuery.h>
|
#include <DB/Parsers/ParserCreateQuery.h>
|
||||||
#include <DB/Parsers/ParserSelectQuery.h>
|
#include <DB/Parsers/ParserSelectQuery.h>
|
||||||
@ -101,33 +98,6 @@ bool ParserIdentifierWithOptionalParameters::parseImpl(Pos & pos, Pos end, ASTPt
|
|||||||
return false;
|
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)
|
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);
|
return ParserList(ParserPtr(new ParserNameTypePair), ParserPtr(new ParserString(",")), false).parse(pos, end, node, expected);
|
||||||
|
@ -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 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 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;
|
ALTER TABLE alter_test ADD COLUMN AddedNested2 Nested(A UInt32, B UInt64) AFTER AddedNested1;
|
||||||
|
|
||||||
DESC TABLE alter_test;
|
DESC TABLE alter_test;
|
||||||
|
@ -2,9 +2,9 @@ ALTER TABLE alter_test DROP COLUMN ToDrop;
|
|||||||
|
|
||||||
ALTER TABLE alter_test MODIFY COLUMN Added0 String;
|
ALTER TABLE alter_test MODIFY COLUMN Added0 String;
|
||||||
|
|
||||||
ALTER TABLE alter_test DROP COLUMN `NestedColumn.A`;
|
ALTER TABLE alter_test DROP COLUMN NestedColumn.A;
|
||||||
ALTER TABLE alter_test DROP COLUMN `NestedColumn.S`;
|
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;
|
DESC TABLE alter_test;
|
||||||
|
Loading…
Reference in New Issue
Block a user