Skip to content

Commit ba67acb

Browse files
committed
Use separate structure with IColumn for Dynamic/Variant/Object types
1 parent f718a7e commit ba67acb

File tree

8 files changed

+230
-67
lines changed

8 files changed

+230
-67
lines changed

src/AggregateFunctions/AggregateFunctionAnyHeavy.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct AggregateFunctionAnyHeavyData
3636
throw Exception(ErrorCodes::LOGICAL_ERROR, "AggregateFunctionAnyHeavyData initialized empty");
3737
}
3838

39-
explicit AggregateFunctionAnyHeavyData(TypeIndex value_type) { generateSingleValueFromTypeIndex(value_type, v_data); }
39+
explicit AggregateFunctionAnyHeavyData(const DataTypePtr & value_type) { generateSingleValueFromType(value_type, v_data); }
4040

4141
~AggregateFunctionAnyHeavyData() { data().~SingleValueDataBase(); }
4242

@@ -102,17 +102,15 @@ class AggregateFunctionAnyHeavy final : public IAggregateFunctionDataHelper<Aggr
102102
{
103103
private:
104104
SerializationPtr serialization;
105-
const TypeIndex value_type_index;
106105

107106
public:
108107
explicit AggregateFunctionAnyHeavy(const DataTypePtr & type)
109108
: IAggregateFunctionDataHelper<AggregateFunctionAnyHeavyData, AggregateFunctionAnyHeavy>({type}, {}, type)
110109
, serialization(type->getDefaultSerialization())
111-
, value_type_index(WhichDataType(type).idx)
112110
{
113111
}
114112

115-
void create(AggregateDataPtr __restrict place) const override { new (place) AggregateFunctionAnyHeavyData(value_type_index); }
113+
void create(AggregateDataPtr __restrict place) const override { new (place) AggregateFunctionAnyHeavyData(result_type); }
116114

117115
String getName() const override { return "anyHeavy"; }
118116

@@ -141,7 +139,7 @@ class AggregateFunctionAnyHeavy final : public IAggregateFunctionDataHelper<Aggr
141139
data(place).read(buf, *serialization, result_type, arena);
142140
}
143141

144-
bool allocatesMemoryInArena() const override { return singleValueTypeAllocatesMemoryInArena(value_type_index); }
142+
bool allocatesMemoryInArena() const override { return singleValueTypeAllocatesMemoryInArena(result_type->getTypeId()); }
145143

146144
void insertResultInto(AggregateDataPtr __restrict place, IColumn & to, Arena *) const override
147145
{

src/AggregateFunctions/AggregateFunctionSingleValueOrNull.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct AggregateFunctionSingleValueOrNullData
3838
throw Exception(ErrorCodes::LOGICAL_ERROR, "AggregateFunctionSingleValueOrNullData initialized empty");
3939
}
4040

41-
explicit AggregateFunctionSingleValueOrNullData(TypeIndex value_type) { generateSingleValueFromTypeIndex(value_type, v_data); }
41+
explicit AggregateFunctionSingleValueOrNullData(const DataTypePtr & value_type) { generateSingleValueFromType(value_type, v_data); }
4242

4343
~AggregateFunctionSingleValueOrNullData() { data().~SingleValueDataBase(); }
4444

@@ -103,18 +103,18 @@ class AggregateFunctionSingleValueOrNull final
103103
{
104104
private:
105105
SerializationPtr serialization;
106-
const TypeIndex value_type_index;
106+
const DataTypePtr value_type;
107107

108108
public:
109109
explicit AggregateFunctionSingleValueOrNull(const DataTypePtr & type)
110110
: IAggregateFunctionDataHelper<AggregateFunctionSingleValueOrNullData, AggregateFunctionSingleValueOrNull>(
111111
{type}, {}, makeNullable(type))
112112
, serialization(type->getDefaultSerialization())
113-
, value_type_index(WhichDataType(type).idx)
113+
, value_type(type)
114114
{
115115
}
116116

117-
void create(AggregateDataPtr __restrict place) const override { new (place) AggregateFunctionSingleValueOrNullData(value_type_index); }
117+
void create(AggregateDataPtr __restrict place) const override { new (place) AggregateFunctionSingleValueOrNullData(value_type); }
118118

119119
String getName() const override { return "singleValueOrNull"; }
120120

@@ -172,7 +172,7 @@ class AggregateFunctionSingleValueOrNull final
172172
data(place).read(buf, *serialization, result_type, arena);
173173
}
174174

175-
bool allocatesMemoryInArena() const override { return singleValueTypeAllocatesMemoryInArena(value_type_index); }
175+
bool allocatesMemoryInArena() const override { return singleValueTypeAllocatesMemoryInArena(value_type->getTypeId()); }
176176

177177
void insertResultInto(AggregateDataPtr __restrict place, IColumn & to, Arena *) const override
178178
{

src/AggregateFunctions/AggregateFunctionsArgMinArgMax.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct AggregateFunctionArgMinMaxData
3535
const ValueType & value() const { return value_data; }
3636

3737
AggregateFunctionArgMinMaxData() = default;
38-
explicit AggregateFunctionArgMinMaxData(TypeIndex) {}
38+
explicit AggregateFunctionArgMinMaxData(const DataTypePtr &) {}
3939

4040
static bool allocatesMemoryInArena(TypeIndex)
4141
{
@@ -61,9 +61,9 @@ struct AggregateFunctionArgMinMaxDataGeneric
6161
throw Exception(ErrorCodes::LOGICAL_ERROR, "AggregateFunctionArgMinMaxData initialized empty");
6262
}
6363

64-
explicit AggregateFunctionArgMinMaxDataGeneric(TypeIndex result_type) : value_data()
64+
explicit AggregateFunctionArgMinMaxDataGeneric(const DataTypePtr & result_type) : value_data()
6565
{
66-
generateSingleValueFromTypeIndex(result_type, result_data);
66+
generateSingleValueFromType(result_type, result_data);
6767
}
6868

6969
static bool allocatesMemoryInArena(TypeIndex result_type_index)
@@ -122,7 +122,7 @@ class AggregateFunctionArgMinMax final
122122

123123
void create(AggregateDataPtr __restrict place) const override /// NOLINT
124124
{
125-
new (place) Data(result_type_index);
125+
new (place) Data(data_type_res);
126126
}
127127

128128
String getName() const override
@@ -371,7 +371,9 @@ AggregateFunctionPtr createAggregateFunctionArgMinMax(const std::string & name,
371371
if (which.idx == TypeIndex::String)
372372
return AggregateFunctionPtr(new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxDataGeneric<SingleValueDataString>, isMin>(argument_types));
373373

374-
return AggregateFunctionPtr(new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxDataGeneric<SingleValueDataGeneric>, isMin>(argument_types));
374+
if (canUseFieldForValueData(value_type))
375+
return AggregateFunctionPtr(new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxDataGeneric<SingleValueDataGeneric>, isMin>(argument_types));
376+
return AggregateFunctionPtr(new AggregateFunctionArgMinMax<AggregateFunctionArgMinMaxDataGeneric<SingleValueDataGenericWithColumn>, isMin>(argument_types));
375377
}
376378
return result;
377379
}

src/AggregateFunctions/Combinators/AggregateFunctionCombinatorsArgMinArgMax.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct AggregateFunctionCombinatorArgMinArgMaxData
1919
SingleValueDataBaseMemoryBlock v_data;
2020

2121
public:
22-
explicit AggregateFunctionCombinatorArgMinArgMaxData(TypeIndex value_type) { generateSingleValueFromTypeIndex(value_type, v_data); }
22+
explicit AggregateFunctionCombinatorArgMinArgMaxData(const DataTypePtr & value_type) { generateSingleValueFromType(value_type, v_data); }
2323

2424
~AggregateFunctionCombinatorArgMinArgMaxData() { data().~SingleValueDataBase(); }
2525

@@ -38,7 +38,7 @@ class AggregateFunctionCombinatorArgMinArgMax final : public IAggregateFunctionH
3838
SerializationPtr serialization;
3939
const size_t key_col;
4040
const size_t key_offset;
41-
const TypeIndex key_type_index;
41+
const DataTypePtr key_type;
4242

4343
AggregateFunctionCombinatorArgMinArgMaxData & data(AggregateDataPtr __restrict place) const /// NOLINT
4444
{
@@ -57,7 +57,7 @@ class AggregateFunctionCombinatorArgMinArgMax final : public IAggregateFunctionH
5757
, serialization(arguments.back()->getDefaultSerialization())
5858
, key_col{arguments.size() - 1}
5959
, key_offset{((nested_function->sizeOfData() + alignof(Key) - 1) / alignof(Key)) * alignof(Key)}
60-
, key_type_index(WhichDataType(arguments[key_col]).idx)
60+
, key_type(arguments[key_col])
6161
{
6262
if (!arguments[key_col]->isComparable())
6363
throw Exception(
@@ -93,7 +93,7 @@ class AggregateFunctionCombinatorArgMinArgMax final : public IAggregateFunctionH
9393

9494
bool allocatesMemoryInArena() const override
9595
{
96-
return nested_function->allocatesMemoryInArena() || singleValueTypeAllocatesMemoryInArena(key_type_index);
96+
return nested_function->allocatesMemoryInArena() || singleValueTypeAllocatesMemoryInArena(key_type->getTypeId());
9797
}
9898

9999
bool hasTrivialDestructor() const override
@@ -108,7 +108,7 @@ class AggregateFunctionCombinatorArgMinArgMax final : public IAggregateFunctionH
108108
void create(AggregateDataPtr __restrict place) const override
109109
{
110110
nested_function->create(place);
111-
new (place + key_offset) Key(key_type_index);
111+
new (place + key_offset) Key(key_type);
112112
}
113113

114114
void destroy(AggregateDataPtr __restrict place) const noexcept override

0 commit comments

Comments
 (0)