mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +00:00
dbms: Code cleanup [#METR-19266]
This commit is contained in:
parent
8ebbc141eb
commit
c74ee4e478
@ -275,7 +275,7 @@ protected:
|
||||
size_t pre_bytes = res.bytes();
|
||||
|
||||
ColumnPtr observed_column;
|
||||
if (column.get()->isNullable())
|
||||
if (column->isNullable())
|
||||
{
|
||||
ColumnNullable & nullable_col = static_cast<ColumnNullable &>(*column);
|
||||
observed_column = nullable_col.getNestedColumn();
|
||||
|
@ -190,7 +190,7 @@ private:
|
||||
const auto pre_bytes = res.bytes();
|
||||
|
||||
ColumnPtr observed_column;
|
||||
if (column.get()->isNullable())
|
||||
if (column->isNullable())
|
||||
{
|
||||
ColumnNullable & nullable_col = static_cast<ColumnNullable &>(*column);
|
||||
observed_column = nullable_col.getNestedColumn();
|
||||
|
@ -13,7 +13,7 @@ extern const int LOGICAL_ERROR;
|
||||
ColumnNullable::ColumnNullable(ColumnPtr nested_column_)
|
||||
: nested_column{nested_column_}
|
||||
{
|
||||
if (nested_column.get()->isNullable())
|
||||
if (nested_column->isNullable())
|
||||
throw Exception{"A nullable column cannot contain another nullable column", ErrorCodes::LOGICAL_ERROR};
|
||||
}
|
||||
|
||||
@ -21,32 +21,32 @@ ColumnNullable::ColumnNullable(ColumnPtr nested_column_, bool fill_with_nulls)
|
||||
: nested_column{nested_column_},
|
||||
null_map{std::make_shared<ColumnUInt8>()}
|
||||
{
|
||||
if (nested_column.get()->isNullable())
|
||||
if (nested_column->isNullable())
|
||||
throw Exception{"A nullable column cannot contain another nullable column", ErrorCodes::LOGICAL_ERROR};
|
||||
|
||||
size_t n = nested_column.get()->size();
|
||||
size_t n = nested_column->size();
|
||||
if (n > 0)
|
||||
getNullMapContent().getData().resize_fill(n, (fill_with_nulls ? 1 : 0));
|
||||
}
|
||||
|
||||
std::string ColumnNullable::getName() const
|
||||
{
|
||||
return "ColumnNullable(" + nested_column.get()->getName() + ")";
|
||||
return "ColumnNullable(" + nested_column->getName() + ")";
|
||||
}
|
||||
|
||||
bool ColumnNullable::isNumeric() const
|
||||
{
|
||||
return nested_column.get()->isNumeric();
|
||||
return nested_column->isNumeric();
|
||||
}
|
||||
|
||||
bool ColumnNullable::isConst() const
|
||||
{
|
||||
return nested_column.get()->isConst();
|
||||
return nested_column->isConst();
|
||||
}
|
||||
|
||||
bool ColumnNullable::isFixed() const
|
||||
{
|
||||
return nested_column.get()->isFixed();
|
||||
return nested_column->isFixed();
|
||||
}
|
||||
|
||||
bool ColumnNullable::isNullable() const
|
||||
@ -58,7 +58,7 @@ ColumnPtr ColumnNullable::convertToFullColumnIfConst() const
|
||||
{
|
||||
ColumnPtr new_col_holder;
|
||||
|
||||
if (auto full_col = nested_column.get()->convertToFullColumnIfConst())
|
||||
if (auto full_col = nested_column->convertToFullColumnIfConst())
|
||||
{
|
||||
new_col_holder = std::make_shared<ColumnNullable>(full_col);
|
||||
ColumnNullable & new_col = static_cast<ColumnNullable &>(*new_col_holder);
|
||||
@ -67,7 +67,7 @@ ColumnPtr ColumnNullable::convertToFullColumnIfConst() const
|
||||
new_col.null_map = null_map;
|
||||
else
|
||||
{
|
||||
size_t n = nested_column.get()->size();
|
||||
size_t n = nested_column->size();
|
||||
if (n > 0)
|
||||
{
|
||||
new_col.null_map = std::make_shared<ColumnUInt8>();
|
||||
@ -92,13 +92,13 @@ void ColumnNullable::updateHashWithValue(size_t n, SipHash & hash) const
|
||||
{
|
||||
UInt8 tag = 0;
|
||||
hash.update(reinterpret_cast<const char *>(&tag), sizeof(tag));
|
||||
nested_column.get()->updateHashWithValue(n, hash);
|
||||
nested_column->updateHashWithValue(n, hash);
|
||||
}
|
||||
}
|
||||
|
||||
ColumnPtr ColumnNullable::cloneResized(size_t size) const
|
||||
{
|
||||
ColumnPtr new_col_holder = std::make_shared<ColumnNullable>(nested_column.get()->cloneResized(size));
|
||||
ColumnPtr new_col_holder = std::make_shared<ColumnNullable>(nested_column->cloneResized(size));
|
||||
auto & new_col = static_cast<ColumnNullable &>(*new_col_holder);
|
||||
|
||||
/// Create a new null byte map for the cloned column.
|
||||
@ -112,7 +112,7 @@ ColumnPtr ColumnNullable::cloneResized(size_t size) const
|
||||
|
||||
ColumnPtr ColumnNullable::cloneEmpty() const
|
||||
{
|
||||
ColumnPtr new_col_holder = std::make_shared<ColumnNullable>(nested_column.get()->cloneEmpty());
|
||||
ColumnPtr new_col_holder = std::make_shared<ColumnNullable>(nested_column->cloneEmpty());
|
||||
auto & new_col = static_cast<ColumnNullable &>(*new_col_holder);
|
||||
new_col.null_map = null_map.get()->cloneEmpty();
|
||||
return new_col_holder;
|
||||
@ -120,7 +120,7 @@ ColumnPtr ColumnNullable::cloneEmpty() const
|
||||
|
||||
size_t ColumnNullable::size() const
|
||||
{
|
||||
return nested_column.get()->size();
|
||||
return nested_column->size();
|
||||
}
|
||||
|
||||
Field ColumnNullable::operator[](size_t n) const
|
||||
@ -139,7 +139,7 @@ void ColumnNullable::get(size_t n, Field & res) const
|
||||
if (isNullAt(n))
|
||||
res = Field{};
|
||||
else
|
||||
nested_column.get()->get(n, res);
|
||||
nested_column->get(n, res);
|
||||
}
|
||||
|
||||
UInt64 ColumnNullable::get64(size_t n) const
|
||||
@ -171,7 +171,7 @@ StringRef ColumnNullable::serializeValueIntoArena(size_t n, Arena & arena, char
|
||||
const UInt8 tag = 0;
|
||||
auto pos = arena.allocContinue(sizeof(tag), begin);
|
||||
memcpy(pos, &tag, sizeof(tag));
|
||||
return nested_column.get()->serializeValueIntoArena(n, arena, begin);
|
||||
return nested_column->serializeValueIntoArena(n, arena, begin);
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,7 +188,7 @@ const char * ColumnNullable::deserializeAndInsertFromArena(const char * pos)
|
||||
else
|
||||
{
|
||||
getNullMapContent().insert(0);
|
||||
return nested_column.get()->deserializeAndInsertFromArena(pos + sizeof(next_pos));
|
||||
return nested_column->deserializeAndInsertFromArena(pos + sizeof(next_pos));
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,38 +207,38 @@ void ColumnNullable::insertRangeFrom(const IColumn & src, size_t start, size_t l
|
||||
ErrorCodes::PARAMETER_OUT_OF_BOUND};
|
||||
|
||||
getNullMapContent().insertRangeFrom(*concrete_src.null_map, start, length);
|
||||
nested_column.get()->insertRangeFrom(*concrete_src.nested_column, start, length);
|
||||
nested_column->insertRangeFrom(*concrete_src.nested_column, start, length);
|
||||
}
|
||||
|
||||
void ColumnNullable::insert(const Field & x)
|
||||
{
|
||||
if (x.isNull())
|
||||
{
|
||||
nested_column.get()->insertDefault();
|
||||
nested_column->insertDefault();
|
||||
getNullMapContent().insert(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
nested_column.get()->insert(x);
|
||||
nested_column->insert(x);
|
||||
getNullMapContent().insert(0);
|
||||
}
|
||||
}
|
||||
|
||||
void ColumnNullable::insertDefault()
|
||||
{
|
||||
nested_column.get()->insertDefault();
|
||||
nested_column->insertDefault();
|
||||
getNullMapContent().insert(0);
|
||||
}
|
||||
|
||||
void ColumnNullable::popBack(size_t n)
|
||||
{
|
||||
nested_column.get()->popBack(n);
|
||||
nested_column->popBack(n);
|
||||
getNullMapContent().popBack(n);
|
||||
}
|
||||
|
||||
ColumnPtr ColumnNullable::filter(const Filter & filt, ssize_t result_size_hint) const
|
||||
{
|
||||
ColumnPtr new_data = nested_column.get()->filter(filt, result_size_hint);
|
||||
ColumnPtr new_data = nested_column->filter(filt, result_size_hint);
|
||||
ColumnPtr filtered_col_holder = std::make_shared<ColumnNullable>(new_data);
|
||||
ColumnNullable & filtered_col = static_cast<ColumnNullable &>(*filtered_col_holder);
|
||||
filtered_col.null_map = getNullMapContent().filter(filt, result_size_hint);
|
||||
@ -247,7 +247,7 @@ ColumnPtr ColumnNullable::filter(const Filter & filt, ssize_t result_size_hint)
|
||||
|
||||
ColumnPtr ColumnNullable::permute(const Permutation & perm, size_t limit) const
|
||||
{
|
||||
ColumnPtr new_data = nested_column.get()->permute(perm, limit);
|
||||
ColumnPtr new_data = nested_column->permute(perm, limit);
|
||||
ColumnPtr permuted_col_holder = std::make_shared<ColumnNullable>(new_data);
|
||||
ColumnNullable & permuted_col = static_cast<ColumnNullable &>(*permuted_col_holder);
|
||||
permuted_col.null_map = getNullMapContent().permute(perm, limit);
|
||||
@ -272,12 +272,12 @@ int ColumnNullable::compareAt(size_t n, size_t m, const IColumn & rhs_, int nan_
|
||||
return 1;
|
||||
|
||||
const IColumn & nested_rhs = *(nullable_rhs.getNestedColumn());
|
||||
return nested_column.get()->compareAt(n, m, nested_rhs, nan_direction_hint);
|
||||
return nested_column->compareAt(n, m, nested_rhs, nan_direction_hint);
|
||||
}
|
||||
|
||||
void ColumnNullable::getPermutation(bool reverse, size_t limit, Permutation & res) const
|
||||
{
|
||||
nested_column.get()->getPermutation(reverse, limit, res);
|
||||
nested_column->getPermutation(reverse, limit, res);
|
||||
size_t s = res.size();
|
||||
|
||||
/// Since we have created a permutation "res" that sorts a subset of the column values
|
||||
@ -342,13 +342,13 @@ void ColumnNullable::getPermutation(bool reverse, size_t limit, Permutation & re
|
||||
|
||||
void ColumnNullable::reserve(size_t n)
|
||||
{
|
||||
nested_column.get()->reserve(n);
|
||||
nested_column->reserve(n);
|
||||
getNullMapContent().reserve(n);
|
||||
}
|
||||
|
||||
size_t ColumnNullable::byteSize() const
|
||||
{
|
||||
return nested_column.get()->byteSize() + getNullMapContent().byteSize();
|
||||
return nested_column->byteSize() + getNullMapContent().byteSize();
|
||||
}
|
||||
|
||||
void ColumnNullable::getExtremes(Field & min, Field & max) const
|
||||
@ -374,12 +374,12 @@ void ColumnNullable::getExtremes(Field & min, Field & max) const
|
||||
else if (auto col = typeid_cast<ColumnFloat64 *>(nested_column.get()))
|
||||
col->getExtremesFromNullableContent(min, max, &getNullMapContent().getData());
|
||||
else
|
||||
nested_column.get()->getExtremes(min, max);
|
||||
nested_column->getExtremes(min, max);
|
||||
}
|
||||
|
||||
ColumnPtr ColumnNullable::replicate(const Offsets_t & offsets) const
|
||||
{
|
||||
ColumnPtr replicated_col_holder = std::make_shared<ColumnNullable>(nested_column.get()->replicate(offsets));
|
||||
ColumnPtr replicated_col_holder = std::make_shared<ColumnNullable>(nested_column->replicate(offsets));
|
||||
ColumnNullable & replicated_col = static_cast<ColumnNullable &>(*replicated_col_holder);
|
||||
replicated_col.null_map = getNullMapContent().replicate(offsets);
|
||||
return replicated_col_holder;
|
||||
|
@ -78,7 +78,7 @@ Block FilterBlockInputStream::readImpl()
|
||||
|
||||
if (column)
|
||||
{
|
||||
if (column.get()->isNullable())
|
||||
if (column->isNullable())
|
||||
{
|
||||
ColumnNullable & nullable_col = static_cast<ColumnNullable &>(*column);
|
||||
column = nullable_col.getNestedColumn();
|
||||
@ -117,7 +117,7 @@ Block FilterBlockInputStream::readImpl()
|
||||
|
||||
size_t columns = res.columns();
|
||||
ColumnPtr column = res.getByPosition(filter_column).column;
|
||||
bool is_nullable_column = column.get()->isNullable();
|
||||
bool is_nullable_column = column->isNullable();
|
||||
|
||||
auto init_observed_column = [&column, &is_nullable_column]()
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ void PrettyBlockOutputStream::calculateWidths(Block & block, Widths_t & max_widt
|
||||
};
|
||||
|
||||
IColumn * observed_col;
|
||||
if (column.column.get()->isNullable())
|
||||
if (column.column->isNullable())
|
||||
{
|
||||
ColumnNullable & nullable_col = static_cast<ColumnNullable &>(*column.column);
|
||||
observed_col = nullable_col.getNestedColumn().get();
|
||||
|
@ -24,7 +24,7 @@ bool hasNullableBranches(const Block & block, const ColumnNumbers & args)
|
||||
auto check = [](const Block & block, size_t arg)
|
||||
{
|
||||
const auto & elem = block.unsafeGetByPosition(arg);
|
||||
return (elem.column && (elem.column.get()->isNullable() || elem.column.get()->isNull()));
|
||||
return (elem.column && (elem.column->isNullable() || elem.column->isNull()));
|
||||
};
|
||||
|
||||
size_t else_arg = Conditional::elseArg(args);
|
||||
@ -179,7 +179,7 @@ void FunctionMultiIf::executeImpl(Block & block, const ColumnNumbers & args, siz
|
||||
const ColumnWithTypeAndName & source_col = non_nullable_block.unsafeGetByPosition(result);
|
||||
ColumnWithTypeAndName & dest_col = block.unsafeGetByPosition(result);
|
||||
|
||||
if (source_col.column.get()->isNull())
|
||||
if (source_col.column->isNull())
|
||||
{
|
||||
/// Degenerate case: the result is a null column.
|
||||
dest_col.column = source_col.column;
|
||||
@ -459,7 +459,7 @@ bool FunctionMultiIf::performTrivialCase(Block & block, const ColumnNumbers & ar
|
||||
{
|
||||
first_type_name = name;
|
||||
type = block.getByPosition(args[i]).type;
|
||||
block.getByPosition(args[i]).column.get()->get(0, sample);
|
||||
block.getByPosition(args[i]).column->get(0, sample);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -474,7 +474,7 @@ bool FunctionMultiIf::performTrivialCase(Block & block, const ColumnNumbers & ar
|
||||
if (first_type_name.empty())
|
||||
{
|
||||
type = block.getByPosition(args[else_arg]).type;
|
||||
block.getByPosition(args[else_arg]).column.get()->get(0, sample);
|
||||
block.getByPosition(args[else_arg]).column->get(0, sample);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -26,7 +26,7 @@ void createNullValuesByteMap(Block & block, const ColumnNumbers & args, size_t r
|
||||
continue;
|
||||
|
||||
const ColumnWithTypeAndName & elem = block.unsafeGetByPosition(arg);
|
||||
if (elem.column && elem.column.get()->isNullable())
|
||||
if (elem.column && elem.column->isNullable())
|
||||
{
|
||||
const ColumnNullable & nullable_col = static_cast<const ColumnNullable &>(*elem.column);
|
||||
res_col.updateNullValuesByteMap(nullable_col);
|
||||
@ -40,7 +40,7 @@ bool hasNullColumns(const Block & block, const ColumnNumbers & arguments)
|
||||
for (const auto & arg : arguments)
|
||||
{
|
||||
const auto & elem = block.unsafeGetByPosition(arg);
|
||||
if (elem.column && elem.column.get()->isNull())
|
||||
if (elem.column && elem.column->isNull())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -76,7 +76,7 @@ bool hasNullableColumns(const Block & block, const ColumnNumbers & arguments)
|
||||
for (const auto & arg : arguments)
|
||||
{
|
||||
const auto & elem = block.unsafeGetByPosition(arg);
|
||||
if (elem.column && elem.column.get()->isNullable())
|
||||
if (elem.column && elem.column->isNullable())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -217,7 +217,7 @@ Block IFunction::extractNonNullableBlock(const Block & block, ColumnNumbers args
|
||||
|
||||
bool found = std::binary_search(args.begin(), args.end(), i) && col.column && col.type;
|
||||
|
||||
if (found && col.column.get()->isNullable())
|
||||
if (found && col.column->isNullable())
|
||||
{
|
||||
auto nullable_col = static_cast<const ColumnNullable *>(col.column.get());
|
||||
ColumnPtr nested_col = nullable_col->getNestedColumn();
|
||||
@ -239,6 +239,7 @@ void IFunction::perform(Block & block, const ColumnNumbers & arguments, size_t r
|
||||
{
|
||||
if (!hasSpecialSupportForNulls() && hasNullColumns(block, arguments))
|
||||
{
|
||||
/// We have found at least one NULL argument. Therefore we return NULL.
|
||||
ColumnWithTypeAndName & dest_col = block.getByPosition(result);
|
||||
dest_col.column = std::make_shared<ColumnNull>(block.rowsInFirstColumn(), Null());
|
||||
return;
|
||||
@ -248,9 +249,11 @@ void IFunction::perform(Block & block, const ColumnNumbers & arguments, size_t r
|
||||
{
|
||||
Block non_nullable_block = extractNonNullableBlock(block, arguments);
|
||||
performer(non_nullable_block, arguments, result);
|
||||
|
||||
const ColumnWithTypeAndName & source_col = non_nullable_block.getByPosition(result);
|
||||
ColumnWithTypeAndName & dest_col = block.getByPosition(result);
|
||||
dest_col.column = std::make_shared<ColumnNullable>(source_col.column);
|
||||
|
||||
ColumnNullable & nullable_col = static_cast<ColumnNullable &>(*dest_col.column);
|
||||
nullable_col.getNullValuesByteMap() = std::make_shared<ColumnUInt8>(dest_col.column->size(), 0);
|
||||
createNullValuesByteMap(block, arguments, result);
|
||||
|
Loading…
Reference in New Issue
Block a user