Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of sparse serialization for Nullable columns #44539

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
57 changes: 57 additions & 0 deletions src/AggregateFunctions/AggregateFunctionNull.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,63 @@ class AggregateFunctionNullUnary final
this->setFlag(place);
}

void addManyDefaults(
AggregateDataPtr __restrict /*place*/,
const IColumn ** /*columns*/,
size_t /*length*/,
Arena * /*arena*/) const override
{
}

void addBatchSparseSinglePlace(
size_t row_begin,
size_t row_end,
AggregateDataPtr __restrict place,
const IColumn ** columns,
Arena * arena) const override
{
const auto & column_sparse = assert_cast<const ColumnSparse &>(*columns[0]);
const auto & offsets = column_sparse.getOffsetsData();
const auto & values = column_sparse.getValuesColumn();
const auto * nested_column = &assert_cast<const ColumnNullable &>(values).getNestedColumn();

auto from = std::lower_bound(offsets.begin(), offsets.end(), row_begin) - offsets.begin() + 1;
auto to = std::lower_bound(offsets.begin(), offsets.end(), row_end) - offsets.begin() + 1;

this->setFlag(place);
this->nested_function->addBatchSinglePlace(from, to, this->nestedPlace(place), &nested_column, arena, -1);
}

void addBatchSparse(
size_t row_begin,
size_t row_end,
AggregateDataPtr * places,
size_t place_offset,
const IColumn ** columns,
Arena * arena) const override
{
const auto & column_sparse = assert_cast<const ColumnSparse &>(*columns[0]);
const auto & offsets = column_sparse.getOffsetsData();
const auto & values = column_sparse.getValuesColumn();
const auto * nested_column = &assert_cast<const ColumnNullable &>(values).getNestedColumn();

size_t from = std::lower_bound(offsets.begin(), offsets.end(), row_begin) - offsets.begin();
size_t to = std::lower_bound(offsets.begin(), offsets.end(), row_end) - offsets.begin();

for (size_t i = from; i < to; ++i)
{
size_t offset = offsets[i];
if (places[offset])
{
this->nested_function->add(
this->nestedPlace(places[offset] + place_offset),
&nested_column, i + 1, arena);

this->setFlag(places[offset] + place_offset);
}
}
}

#if USE_EMBEDDED_COMPILER

void compileAdd(llvm::IRBuilderBase & builder, llvm::Value * aggregate_data_ptr, const DataTypes & arguments_types, const std::vector<llvm::Value *> & argument_values) const override
Expand Down
2 changes: 2 additions & 0 deletions src/AggregateFunctions/AggregateFunctionSum.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ struct AggregateFunctionSumData
), addManyConditionalInternalImpl, MULTITARGET_FUNCTION_BODY((const Value * __restrict ptr, const UInt8 * __restrict condition_map, size_t start, size_t end) /// NOLINT
{
ptr += start;
condition_map += start;

size_t count = end - start;
const auto * end_ptr = ptr + count;

Expand Down
8 changes: 4 additions & 4 deletions src/Columns/ColumnNullable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,16 +761,16 @@ void ColumnNullable::checkConsistency() const

ColumnPtr ColumnNullable::createWithOffsets(const IColumn::Offsets & offsets, const Field & default_field, size_t total_rows, size_t shift) const
{
if (empty())
return cloneEmpty();

ColumnPtr new_values;
ColumnPtr new_null_map;

if (default_field.getType() == Field::Types::Null)
{
auto default_column = nested_column->cloneEmpty();
default_column->insertDefault();

/// Value in main column, when null map is 1 is implementation defined. So, take any value.
new_values = nested_column->createWithOffsets(offsets, (*default_column)[0], total_rows, shift);
new_values = nested_column->createWithOffsets(offsets, (*nested_column)[0], total_rows, shift);
new_null_map = null_map->createWithOffsets(offsets, Field(1u), total_rows, shift);
}
else
Expand Down
1 change: 1 addition & 0 deletions src/DataTypes/DataTypeNullable.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class DataTypeNullable final : public IDataType
bool onlyNull() const override;
bool canBeInsideLowCardinality() const override { return nested_data_type->canBeInsideLowCardinality(); }
bool canBePromoted() const override { return nested_data_type->canBePromoted(); }
bool supportsSparseSerialization() const override { return true; }

const DataTypePtr & getNestedType() const { return nested_data_type; }
private:
Expand Down
2 changes: 2 additions & 0 deletions src/DataTypes/Serializations/SerializationNullable.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class SerializationNullable : public ISerialization
public:
explicit SerializationNullable(const SerializationPtr & nested_) : nested(nested_) {}

const SerializationPtr & getNested() const { return nested; }

void enumerateStreams(
EnumerateStreamsSettings & settings,
const StreamCallback & callback,
Expand Down
Loading