mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
Avoid generating named tuple for special keywords
This commit is contained in:
parent
2c54b5cab4
commit
eb129232ff
@ -1,5 +1,6 @@
|
||||
#include <Parsers/isUnquotedIdentifier.h>
|
||||
|
||||
#include <Parsers/CommonParsers.h>
|
||||
#include <Parsers/Lexer.h>
|
||||
|
||||
namespace DB
|
||||
@ -7,6 +8,18 @@ namespace DB
|
||||
|
||||
bool isUnquotedIdentifier(const String & name)
|
||||
{
|
||||
auto is_keyword = [&name](Keyword keyword)
|
||||
{
|
||||
auto s = toStringView(keyword);
|
||||
if (name.size() != s.size())
|
||||
return false;
|
||||
return strncasecmp(s.data(), name.data(), s.size()) == 0;
|
||||
};
|
||||
|
||||
/// Special keywords are parsed as literals instead of identifiers.
|
||||
if (is_keyword(Keyword::NULL_KEYWORD) || is_keyword(Keyword::TRUE_KEYWORD) || is_keyword(Keyword::FALSE_KEYWORD))
|
||||
return false;
|
||||
|
||||
Lexer lexer(name.data(), name.data() + name.size());
|
||||
|
||||
auto maybe_ident = lexer.nextToken();
|
||||
|
@ -5,6 +5,14 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
/// Checks if the input string @name is a valid unquoted identifier.
|
||||
///
|
||||
/// Example Usage:
|
||||
/// abc -> true (valid unquoted identifier)
|
||||
/// 123 -> false (identifiers cannot start with digits)
|
||||
/// `123` -> false (quoted identifiers are not considered)
|
||||
/// `abc` -> false (quoted identifiers are not considered)
|
||||
/// null -> false (reserved literal keyword)
|
||||
bool isUnquotedIdentifier(const String & name);
|
||||
|
||||
}
|
||||
|
@ -7,3 +7,4 @@ Tuple(\n k UInt8,\n j Int32)
|
||||
Tuple(Int32, Int32, Int32, Int32)
|
||||
['1','2','3','4']
|
||||
(1,2,3)
|
||||
Tuple(Nullable(Nothing)) Tuple(Bool) Tuple(Bool)
|
||||
|
@ -28,4 +28,7 @@ create table tbl (x Tuple(a Int32, b Int32, c Int32)) engine MergeTree order by
|
||||
insert into tbl values (tuple(1, 2, 3)); -- without tuple it's interpreted differently inside values block.
|
||||
select * from tbl;
|
||||
|
||||
drop table tbl
|
||||
drop table tbl;
|
||||
|
||||
-- Avoid generating named tuple for special keywords
|
||||
select toTypeName(tuple(null)), toTypeName(tuple(true)), toTypeName(tuple(false));
|
||||
|
Loading…
Reference in New Issue
Block a user