-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
049928f
commit 93b76aa
Showing
7 changed files
with
148 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
cpp-ch/local-engine/Storages/IO/AggregateSerializationUtils.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "AggregateSerializationUtils.h" | ||
#include <Common/Arena.h> | ||
|
||
#include <Columns/ColumnAggregateFunction.h> | ||
#include <DataTypes/DataTypeAggregateFunction.h> | ||
#include <DataTypes/DataTypeFixedString.h> | ||
|
||
|
||
using namespace DB; | ||
|
||
namespace local_engine | ||
{ | ||
DB::ColumnWithTypeAndName convertAggregateStateToFixedString(DB::ColumnWithTypeAndName col) | ||
{ | ||
if (!isAggregateFunction(col.type)) | ||
{ | ||
return col; | ||
} | ||
const auto *aggregate_col = checkAndGetColumn<ColumnAggregateFunction>(*col.column); | ||
size_t state_size = aggregate_col->getAggregateFunction()->sizeOfData(); | ||
auto res_type = std::make_shared<DataTypeFixedString>(state_size); | ||
auto res_col = res_type->createColumn(); | ||
res_col->reserve(aggregate_col->size()); | ||
for (const auto & item : aggregate_col->getData()) | ||
{ | ||
res_col->insertData(item, state_size); | ||
} | ||
return DB::ColumnWithTypeAndName(std::move(res_col), res_type, col.name); | ||
} | ||
DB::ColumnWithTypeAndName convertFixedStringToAggregateState(DB::ColumnWithTypeAndName col, DB::DataTypePtr type) | ||
{ | ||
chassert(isAggregateFunction(type)); | ||
auto res_col = type->createColumn(); | ||
const auto * agg_type = checkAndGetDataType<DataTypeAggregateFunction>(type.get()); | ||
ColumnAggregateFunction & real_column = typeid_cast<ColumnAggregateFunction &>(*res_col); | ||
auto & arena = real_column.createOrGetArena(); | ||
ColumnAggregateFunction::Container & vec = real_column.getData(); | ||
|
||
vec.reserve(col.column->size()); | ||
auto agg_function = agg_type->getFunction(); | ||
size_t size_of_state = agg_function->sizeOfData(); | ||
size_t align_of_state = agg_function->alignOfData(); | ||
|
||
for (size_t i = 0; i < col.column->size(); ++i) | ||
{ | ||
AggregateDataPtr place = arena.alignedAlloc(size_of_state, align_of_state); | ||
|
||
agg_function->create(place); | ||
|
||
auto value = col.column->getDataAt(i); | ||
memcpy(place, value.data, value.size); | ||
|
||
vec.push_back(place); | ||
} | ||
return DB::ColumnWithTypeAndName(std::move(res_col), type, col.name); | ||
} | ||
DB::Block convertAggregateStateInBlock(DB::Block block) | ||
{ | ||
ColumnsWithTypeAndName columns; | ||
for (const auto & item : block.getColumnsWithTypeAndName()) | ||
{ | ||
columns.emplace_back(convertAggregateStateToFixedString(item)); | ||
} | ||
return columns; | ||
} | ||
} | ||
|
30 changes: 30 additions & 0 deletions
30
cpp-ch/local-engine/Storages/IO/AggregateSerializationUtils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#pragma once | ||
#include <Core/Block.h> | ||
#include <DataTypes/IDataType.h> | ||
|
||
namespace local_engine { | ||
|
||
DB::Block convertAggregateStateInBlock(DB::Block block); | ||
|
||
DB::ColumnWithTypeAndName convertAggregateStateToFixedString(DB::ColumnWithTypeAndName col); | ||
|
||
DB::ColumnWithTypeAndName convertFixedStringToAggregateState(DB::ColumnWithTypeAndName col, DB::DataTypePtr type); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters