Merge pull request #36058 from xiedeyantu/master

This commit is contained in:
Vladimir C 2022-04-11 10:45:50 +02:00 committed by GitHub
commit 1a604cd279
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

View File

@ -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);
}

View File

@ -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

View 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;