mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Merge pull request #36058 from xiedeyantu/master
This commit is contained in:
commit
1a604cd279
@ -54,6 +54,7 @@
|
||||
#include <DataTypes/DataTypeNullable.h>
|
||||
#include <DataTypes/DataTypeAggregateFunction.h>
|
||||
#include <DataTypes/ObjectUtils.h>
|
||||
#include <DataTypes/hasNullable.h>
|
||||
|
||||
#include <Databases/DatabaseFactory.h>
|
||||
#include <Databases/DatabaseReplicated.h>
|
||||
@ -480,6 +481,21 @@ ColumnsDescription InterpreterCreateQuery::getColumnsDescription(
|
||||
{
|
||||
column_type = makeNullable(column_type);
|
||||
}
|
||||
else if (!hasNullable(column_type) &&
|
||||
col_decl.default_specifier == "DEFAULT" &&
|
||||
col_decl.default_expression &&
|
||||
col_decl.default_expression->as<ASTLiteral>() &&
|
||||
col_decl.default_expression->as<ASTLiteral>()->value.isNull())
|
||||
{
|
||||
if (column_type->lowCardinality())
|
||||
{
|
||||
const auto * low_cardinality_type = typeid_cast<const DataTypeLowCardinality *>(column_type.get());
|
||||
assert(low_cardinality_type);
|
||||
column_type = std::make_shared<DataTypeLowCardinality>(makeNullable(low_cardinality_type->getDictionaryType()));
|
||||
}
|
||||
else
|
||||
column_type = makeNullable(column_type);
|
||||
}
|
||||
|
||||
column_names_and_types.emplace_back(col_decl.name, column_type);
|
||||
}
|
||||
|
@ -0,0 +1,6 @@
|
||||
val0 Nullable(Int8) DEFAULT NULL
|
||||
val1 Nullable(Int8) DEFAULT NULL
|
||||
val2 Nullable(UInt8) DEFAULT NULL
|
||||
val3 Nullable(String) DEFAULT NULL
|
||||
val4 LowCardinality(Nullable(Int8)) DEFAULT NULL
|
||||
val5 LowCardinality(Nullable(Int8)) DEFAULT NULL
|
17
tests/queries/0_stateless/02266_auto_add_nullable.sql
Normal file
17
tests/queries/0_stateless/02266_auto_add_nullable.sql
Normal file
@ -0,0 +1,17 @@
|
||||
SET allow_suspicious_low_cardinality_types = 1;
|
||||
DROP TABLE IF EXISTS 02266_auto_add_nullable;
|
||||
|
||||
CREATE TABLE 02266_auto_add_nullable
|
||||
(
|
||||
val0 Int8 DEFAULT NULL,
|
||||
val1 Nullable(Int8) DEFAULT NULL,
|
||||
val2 UInt8 DEFAULT NUll,
|
||||
val3 String DEFAULT null,
|
||||
val4 LowCardinality(Int8) DEFAULT NULL,
|
||||
val5 LowCardinality(Nullable(Int8)) DEFAULT NULL
|
||||
)
|
||||
ENGINE = MergeTree order by tuple();
|
||||
|
||||
DESCRIBE TABLE 02266_auto_add_nullable;
|
||||
|
||||
DROP TABLE IF EXISTS 02266_auto_add_nullable;
|
Loading…
Reference in New Issue
Block a user