Skip to content

Commit f3b6d35

Browse files
Removed setting "strict_insert_defaults" [#CLICKHOUSE-2]
1 parent 1f985cc commit f3b6d35

File tree

4 files changed

+44
-54
lines changed

4 files changed

+44
-54
lines changed

dbms/src/DataStreams/AddingDefaultBlockOutputStream.cpp

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,55 @@ void AddingDefaultBlockOutputStream::write(const Block & block)
1515
Block res = block;
1616

1717
/// Adds not specified default values.
18-
/// @todo this may be moved before `evaluateMissingDefaults` with passing {required_columns - explicitly-defaulted columns}
19-
if (!only_explicit_column_defaults)
20-
{
21-
size_t rows = res.rows();
18+
size_t rows = res.rows();
2219

23-
/// For missing columns of nested structure, you need to create not a column of empty arrays, but a column of arrays of correct lengths.
24-
/// First, remember the offset columns for all arrays in the block.
25-
std::map<String, ColumnPtr> offset_columns;
20+
/// For missing columns of nested structure, you need to create not a column of empty arrays, but a column of arrays of correct lengths.
21+
/// First, remember the offset columns for all arrays in the block.
22+
std::map<String, ColumnPtr> offset_columns;
2623

27-
for (size_t i = 0, size = res.columns(); i < size; ++i)
28-
{
29-
const auto & elem = res.getByPosition(i);
24+
for (size_t i = 0, size = res.columns(); i < size; ++i)
25+
{
26+
const auto & elem = res.getByPosition(i);
3027

31-
if (const ColumnArray * array = typeid_cast<const ColumnArray *>(&*elem.column))
32-
{
33-
String offsets_name = Nested::extractTableName(elem.name);
34-
auto & offsets_column = offset_columns[offsets_name];
28+
if (const ColumnArray * array = typeid_cast<const ColumnArray *>(&*elem.column))
29+
{
30+
String offsets_name = Nested::extractTableName(elem.name);
31+
auto & offsets_column = offset_columns[offsets_name];
3532

36-
/// If for some reason there are different offset columns for one nested structure, then we take nonempty.
37-
if (!offsets_column || offsets_column->empty())
38-
offsets_column = array->getOffsetsPtr();
39-
}
33+
/// If for some reason there are different offset columns for one nested structure, then we take nonempty.
34+
if (!offsets_column || offsets_column->empty())
35+
offsets_column = array->getOffsetsPtr();
4036
}
37+
}
38+
39+
for (const auto & requested_column : required_columns)
40+
{
41+
if (res.has(requested_column.name) || column_defaults.count(requested_column.name))
42+
continue;
43+
44+
ColumnWithTypeAndName column_to_add;
45+
column_to_add.name = requested_column.name;
46+
column_to_add.type = requested_column.type;
47+
48+
String offsets_name = Nested::extractTableName(column_to_add.name);
49+
if (offset_columns.count(offsets_name))
50+
{
51+
ColumnPtr offsets_column = offset_columns[offsets_name];
52+
DataTypePtr nested_type = typeid_cast<const DataTypeArray &>(*column_to_add.type).getNestedType();
53+
UInt64 nested_rows = rows ? get<UInt64>((*offsets_column)[rows - 1]) : 0;
4154

42-
for (const auto & requested_column : required_columns)
55+
ColumnPtr nested_column = nested_type->createColumnConstWithDefaultValue(nested_rows)->convertToFullColumnIfConst();
56+
column_to_add.column = ColumnArray::create(nested_column, offsets_column);
57+
}
58+
else
4359
{
44-
if (res.has(requested_column.name) || column_defaults.count(requested_column.name))
45-
continue;
46-
47-
ColumnWithTypeAndName column_to_add;
48-
column_to_add.name = requested_column.name;
49-
column_to_add.type = requested_column.type;
50-
51-
String offsets_name = Nested::extractTableName(column_to_add.name);
52-
if (offset_columns.count(offsets_name))
53-
{
54-
ColumnPtr offsets_column = offset_columns[offsets_name];
55-
DataTypePtr nested_type = typeid_cast<const DataTypeArray &>(*column_to_add.type).getNestedType();
56-
UInt64 nested_rows = rows ? get<UInt64>((*offsets_column)[rows - 1]) : 0;
57-
58-
ColumnPtr nested_column = nested_type->createColumnConstWithDefaultValue(nested_rows)->convertToFullColumnIfConst();
59-
column_to_add.column = ColumnArray::create(nested_column, offsets_column);
60-
}
61-
else
62-
{
63-
/** It is necessary to turn a constant column into a full column, since in part of blocks (from other parts),
64-
* it can be full (or the interpreter may decide that it is constant everywhere).
65-
*/
66-
column_to_add.column = column_to_add.type->createColumnConstWithDefaultValue(rows)->convertToFullColumnIfConst();
67-
}
68-
69-
res.insert(std::move(column_to_add));
60+
/** It is necessary to turn a constant column into a full column, since in part of blocks (from other parts),
61+
* it can be full (or the interpreter may decide that it is constant everywhere).
62+
*/
63+
column_to_add.column = column_to_add.type->createColumnConstWithDefaultValue(rows)->convertToFullColumnIfConst();
7064
}
65+
66+
res.insert(std::move(column_to_add));
7167
}
7268

7369
/// Computes explicitly specified values (in column_defaults) by default.

dbms/src/DataStreams/AddingDefaultBlockOutputStream.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ class AddingDefaultBlockOutputStream : public IBlockOutputStream
2222
const Block & header_,
2323
NamesAndTypesList required_columns_,
2424
const ColumnDefaults & column_defaults_,
25-
const Context & context_,
26-
bool only_explicit_column_defaults_)
25+
const Context & context_)
2726
: output(output_), header(header_), required_columns(required_columns_),
28-
column_defaults(column_defaults_), context(context_),
29-
only_explicit_column_defaults(only_explicit_column_defaults_)
27+
column_defaults(column_defaults_), context(context_)
3028
{
3129
}
3230

@@ -44,7 +42,6 @@ class AddingDefaultBlockOutputStream : public IBlockOutputStream
4442
NamesAndTypesList required_columns;
4543
const ColumnDefaults column_defaults;
4644
const Context & context;
47-
bool only_explicit_column_defaults;
4845
};
4946

5047

dbms/src/Interpreters/InterpreterInsertQuery.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ BlockIO InterpreterInsertQuery::execute()
103103
out = std::make_shared<PushingToViewsBlockOutputStream>(query.database, query.table, table, context, query_ptr, query.no_destination);
104104

105105
out = std::make_shared<AddingDefaultBlockOutputStream>(
106-
out, getSampleBlock(query, table), required_columns, table->column_defaults, context,
107-
static_cast<bool>(context.getSettingsRef().strict_insert_defaults));
106+
out, getSampleBlock(query, table), required_columns, table->column_defaults, context);
108107

109108
out = std::make_shared<SquashingBlockOutputStream>(
110109
out, context.getSettingsRef().min_insert_block_size_rows, context.getSettingsRef().min_insert_block_size_bytes);

dbms/src/Interpreters/Settings.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ struct Settings
9494
M(SettingBool, force_index_by_date, 0, "Throw an exception if there is a partition key in a table, and it is not used.") \
9595
M(SettingBool, force_primary_key, 0, "Throw an exception if there is primary key in a table, and it is not used.") \
9696
\
97-
M(SettingBool, strict_insert_defaults, 0, "In the INSERT query with specified columns, fill in the default values only for columns with explicit DEFAULTs.") \
98-
\
9997
M(SettingUInt64, mark_cache_min_lifetime, 10000, "If the maximum size of mark_cache is exceeded, delete only records older than mark_cache_min_lifetime seconds.") \
10098
\
10199
M(SettingFloat, max_streams_to_max_threads_ratio, 1, "Allows you to use more sources than the number of threads - to more evenly distribute work across threads. It is assumed that this is a temporary solution, since it will be possible in the future to make the number of sources equal to the number of threads, but for each source to dynamically select available work for itself.") \

0 commit comments

Comments
 (0)