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

Backport #52659 to 23.3: Fix crash in function tuple with one sparse column argument #52782

Merged
merged 1 commit into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/DataTypes/DataTypeTuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class DataTypeTuple final : public IDataType

bool canBeInsideNullable() const override { return false; }
bool supportsSparseSerialization() const override { return true; }
bool canBeInsideSparseColumns() const override { return false; }

MutableColumnPtr createColumn() const override;
MutableColumnPtr createColumn(const ISerialization & serialization) const override;
Expand Down
1 change: 1 addition & 0 deletions src/DataTypes/IDataType.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class IDataType : private boost::noncopyable, public std::enable_shared_from_thi

/// TODO: support more types.
virtual bool supportsSparseSerialization() const { return !haveSubtypes(); }
virtual bool canBeInsideSparseColumns() const { return supportsSparseSerialization(); }

SerializationPtr getDefaultSerialization() const;
SerializationPtr getSparseSerialization() const;
Expand Down
2 changes: 1 addition & 1 deletion src/Functions/IFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ ColumnPtr IExecutableFunction::execute(const ColumnsWithTypeAndName & arguments,
/// If default of sparse column is changed after execution of function, convert to full column.
/// If there are any default in non-zero position after execution of function, convert to full column.
/// Currently there is no easy way to rebuild sparse column with new offsets.
if (!result_type->supportsSparseSerialization() || !res->isDefaultAt(0) || res->getNumberOfDefaultRows() != 1)
if (!result_type->canBeInsideSparseColumns() || !res->isDefaultAt(0) || res->getNumberOfDefaultRows() != 1)
{
const auto & offsets_data = assert_cast<const ColumnVector<UInt64> &>(*sparse_offsets).getData();
return res->createWithOffsets(offsets_data, (*res)[0], input_rows_count, /*shift=*/ 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(0,0)
(0,0)
(0,1)
(0,NULL)
14 changes: 14 additions & 0 deletions tests/queries/0_stateless/02833_sparse_columns_tuple_function.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
drop table if exists t_tuple_sparse;

create table t_tuple_sparse (a UInt64, b UInt64)
ENGINE = MergeTree ORDER BY tuple()
SETTINGS ratio_of_defaults_for_sparse_serialization = 0.0;

insert into t_tuple_sparse values (0, 0);

select (a, b) from t_tuple_sparse;
select (a, 0) from t_tuple_sparse;
select (a, 1) from t_tuple_sparse;
select (a, NULL) from t_tuple_sparse;

drop table if exists t_tuple_sparse;