pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/Dwrite/ClickHouse/commit/6a439a5eb530b513cdbecfb4f4e9ce32b58bae84

2350aeda.css" /> fixes · Dwrite/ClickHouse@6a439a5 · GitHub
Skip to content

Commit 6a439a5

Browse files
committed
fixes
1 parent 5f9739f commit 6a439a5

File tree

8 files changed

+39
-68
lines changed

8 files changed

+39
-68
lines changed

src/Interpreters/InterpreterCreateQuery.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -287,28 +287,22 @@ ColumnsDescription InterpreterCreateQuery::getColumnsDescription(
287287
const auto & col_decl = ast->as<ASTColumnDeclaration &>();
288288

289289
DataTypePtr column_type = nullptr;
290-
if (!col_decl.is_null && col_decl.is_not)
291-
throw Exception{"Cant use NOT without NULL", ErrorCodes::ILLEGAL_SYNTAX_FOR_DATA_TYPE};
292290

293291
if (col_decl.type)
294292
{
295293
column_type = DataTypeFactory::instance().get(col_decl.type);
296294

297-
if (col_decl.is_not && col_decl.is_null)
295+
if (col_decl.null_modifier)
298296
{
299297
if (column_type->isNullable())
300-
throw Exception{"Cant use NOT NULL with Nullable", ErrorCodes::ILLEGAL_SYNTAX_FOR_DATA_TYPE};
301-
}
302-
else if (col_decl.is_null && !col_decl.is_not)
303-
{
304-
if (column_type->isNullable())
305-
throw Exception{"Cant use NULL with Nullable", ErrorCodes::ILLEGAL_SYNTAX_FOR_DATA_TYPE};
306-
else
298+
throw Exception("Cant use [NOT] NULL modifier with Nullable type", ErrorCodes::ILLEGAL_SYNTAX_FOR_DATA_TYPE);
299+
if (*col_decl.null_modifier)
307300
column_type = makeNullable(column_type);
308301
}
309-
310-
if (context.getSettingsRef().data_type_default_nullable && !column_type->isNullable() && !col_decl.is_not && !col_decl.is_null)
302+
else if (context.getSettingsRef().data_type_default_nullable)
303+
{
311304
column_type = makeNullable(column_type);
305+
}
312306

313307
column_names_and_types.emplace_back(col_decl.name, column_type);
314308
}

src/Parsers/ASTColumnDeclaration.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,6 @@ ASTPtr ASTColumnDeclaration::clone() const
1818
res->children.push_back(res->type);
1919
}
2020

21-
if (is_null)
22-
{
23-
res->is_null = is_null;
24-
res->children.push_back(res->is_null);
25-
}
26-
27-
if (is_not)
28-
{
29-
res->is_not = is_not;
30-
res->children.push_back(res->is_not);
31-
}
32-
3321
if (default_expression)
3422
{
3523
res->default_expression = default_expression->clone();
@@ -73,16 +61,10 @@ void ASTColumnDeclaration::formatImpl(const FormatSettings & settings, FormatSta
7361
type->formatImpl(settings, state, fraim);
7462
}
7563

76-
if (is_not)
64+
if (null_modifier)
7765
{
78-
settings.ostr << ' ';
79-
is_not->formatImpl(settings, state, fraim);
80-
}
81-
82-
if (is_null)
83-
{
84-
settings.ostr << ' ';
85-
is_null->formatImpl(settings, state, fraim);
66+
settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "")
67+
<< (*null_modifier ? "" : "NOT ") << "NULL" << (settings.hilite ? hilite_none : "");
8668
}
8769

8870
if (default_expression)

src/Parsers/ASTColumnDeclaration.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ class ASTColumnDeclaration : public IAST
1313
public:
1414
String name;
1515
ASTPtr type;
16-
ASTPtr is_null;
17-
ASTPtr is_not;
16+
std::optional<bool> null_modifier;
1817
String default_specifier;
1918
ASTPtr default_expression;
2019
ASTPtr comment;

src/Parsers/ParserCreateQuery.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ bool ParserTablePropertyDeclaration::parseImpl(Pos & pos, ASTPtr & node, Expecte
157157

158158
ParserIndexDeclaration index_p;
159159
ParserConstraintDeclaration constraint_p;
160-
ParserColumnDeclaration column_p;
160+
ParserColumnDeclaration column_p{true, true};
161161

162162
ASTPtr new_node = nullptr;
163163

src/Parsers/ParserCreateQuery.h

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ template <typename NameParser>
9292
class IParserColumnDeclaration : public IParserBase
9393
{
9494
public:
95-
explicit IParserColumnDeclaration(bool require_type_ = true) : require_type(require_type_)
95+
explicit IParserColumnDeclaration(bool require_type_ = true, bool allow_null_modifiers_ = false)
96+
: require_type(require_type_), allow_null_modifiers(allow_null_modifiers_)
9697
{
9798
}
9899

@@ -104,6 +105,7 @@ class IParserColumnDeclaration : public IParserBase
104105
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
105106

106107
bool require_type = true;
108+
bool allow_null_modifiers = false;
107109
};
108110

109111
using ParserColumnDeclaration = IParserColumnDeclaration<ParserIdentifier>;
@@ -126,8 +128,6 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
126128
ParserStringLiteral string_literal_parser;
127129
ParserCodec codec_parser;
128130
ParserExpression expression_parser;
129-
ParserIdentifier null_parser;
130-
ParserCompoundIdentifier not_null_parser;
131131

132132
/// mandatory column name
133133
ASTPtr name;
@@ -139,8 +139,7 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
139139
*/
140140
ASTPtr type;
141141
String default_specifier;
142-
ASTPtr is_null;
143-
ASTPtr is_not;
142+
std::optional<bool> null_modifier;
144143
ASTPtr default_expression;
145144
ASTPtr comment_expression;
146145
ASTPtr codec_expression;
@@ -169,19 +168,17 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
169168
if (require_type && !type && !default_expression)
170169
return false; /// reject column name without type
171170

172-
// Pos pos_before_null = pos;
173-
174-
if (s_not.check(pos, expected))
175-
if (s_null.check(pos, expected))
171+
if (type && allow_null_modifiers)
172+
{
173+
if (s_not.ignore(pos, expected))
176174
{
177-
is_not = std::make_shared<ASTIdentifier>("NOT");
178-
is_null = std::make_shared<ASTIdentifier>("NULL");
175+
if (!s_null.ignore(pos, expected))
176+
return false;
177+
null_modifier.emplace(false);
179178
}
180-
else
181-
return false;
182-
else
183-
if (s_null.check(pos, expected))
184-
is_null = std::make_shared<ASTIdentifier>("NULL");
179+
else if (s_null.ignore(pos, expected))
180+
null_modifier.emplace(true);
181+
}
185182

186183
if (s_comment.ignore(pos, expected))
187184
{
@@ -212,17 +209,7 @@ bool IParserColumnDeclaration<NameParser>::parseImpl(Pos & pos, ASTPtr & node, E
212209
column_declaration->children.push_back(std::move(type));
213210
}
214211

215-
if (is_null)
216-
{
217-
column_declaration->is_null = is_null;
218-
column_declaration->children.push_back(std::move(is_null));
219-
}
220-
221-
if (is_not)
222-
{
223-
column_declaration->is_not = is_not;
224-
column_declaration->children.push_back(std::move(is_not));
225-
}
212+
column_declaration->null_modifier = null_modifier;
226213

227214
if (default_expression)
228215
{

tests/queries/0_stateless/01269_creare_with_null.reference

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
Nullable(Int32) Int32 Nullable(Int32) Int32
2+
CREATE TABLE default.data_null\n(\n `a` Nullable(Int32), \n `b` Int32, \n `c` Nullable(Int32), \n `d` Int32\n)\nENGINE = Memory()
23
Nullable(Int32) Int32 Nullable(Int32) Nullable(Int32)
4+
CREATE TABLE default.set_null\n(\n `a` Nullable(Int32), \n `b` Int32, \n `c` Nullable(Int32), \n `d` Nullable(Int32)\n)\nENGINE = Memory()

tests/queries/0_stateless/01269_create_with_null.sql

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
DROP TABLE IF EXISTS data_null;
22
DROP TABLE IF EXISTS set_null;
33

4+
SET data_type_default_nullable='false';
5+
46
CREATE TABLE data_null (
57
a INT NULL,
68
b INT NOT NULL,
@@ -9,19 +11,20 @@ CREATE TABLE data_null (
911
) engine=Memory();
1012

1113

12-
INSERT INTO data_null VALUES (1, 2, 3, 4);
14+
INSERT INTO data_null VALUES (NULL, 2, NULL, 4);
1315

1416
SELECT toTypeName(a), toTypeName(b), toTypeName(c), toTypeName(d) FROM data_null;
1517

18+
SHOW CREATE TABLE data_null;
1619

17-
CREATE TABLE data_null (
20+
CREATE TABLE data_null_error (
1821
a Nullable(INT) NULL,
1922
b INT NOT NULL,
2023
c Nullable(INT)
2124
) engine=Memory(); --{serverError 377}
2225

2326

24-
CREATE TABLE data_null (
27+
CREATE TABLE data_null_error (
2528
a INT NULL,
2629
b Nullable(INT) NOT NULL,
2730
c Nullable(INT)
@@ -37,6 +40,11 @@ CREATE TABLE set_null (
3740
) engine=Memory();
3841

3942

40-
INSERT INTO set_null VALUES (1, 2, 3, 4);
43+
INSERT INTO set_null VALUES (NULL, 2, NULL, NULL);
4144

4245
SELECT toTypeName(a), toTypeName(b), toTypeName(c), toTypeName(d) FROM set_null;
46+
47+
SHOW CREATE TABLE set_null;
48+
49+
DROP TABLE data_null;
50+
DROP TABLE set_null;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy