-
Notifications
You must be signed in to change notification settings - Fork 452
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
liuneng1994
committed
Jul 2, 2024
1 parent
eb1b913
commit 89371e4
Showing
10 changed files
with
188 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include "ReplicateRowsStep.h" | ||
|
||
#include <iostream> | ||
|
||
#include <QueryPipeline/QueryPipelineBuilder.h> | ||
|
||
namespace DB | ||
{ | ||
namespace ErrorCodes | ||
{ | ||
extern const int LOGICAL_ERROR; | ||
} | ||
} | ||
|
||
namespace local_engine | ||
{ | ||
static DB::ITransformingStep::Traits getTraits() | ||
{ | ||
return DB::ITransformingStep::Traits | ||
{ | ||
{ | ||
.preserves_number_of_streams = true, | ||
.preserves_sorting = false, | ||
}, | ||
{ | ||
.preserves_number_of_rows = false, | ||
} | ||
}; | ||
} | ||
|
||
ReplicateRowsStep::ReplicateRowsStep(const DB::DataStream & input_stream) | ||
: ITransformingStep(input_stream, transformHeader(input_stream.header), getTraits()) | ||
{ | ||
} | ||
|
||
DB::Block ReplicateRowsStep::transformHeader(const DB::Block& input) | ||
{ | ||
DB::Block output; | ||
for (int i = 1; i < input.columns(); i++) | ||
{ | ||
output.insert(input.getByPosition(i)); | ||
} | ||
return output; | ||
} | ||
|
||
void ReplicateRowsStep::transformPipeline( | ||
DB::QueryPipelineBuilder & pipeline, | ||
const DB::BuildQueryPipelineSettings & /*settings*/) | ||
{ | ||
pipeline.addSimpleTransform( | ||
[&](const DB::Block & header) | ||
{ | ||
return std::make_shared<ReplicateRowsTransform>(header); | ||
}); | ||
} | ||
|
||
void ReplicateRowsStep::updateOutputStream() | ||
{ | ||
output_stream = createOutputStream(input_streams.front(), transformHeader(input_streams.front().header), getDataStreamTraits()); | ||
} | ||
|
||
ReplicateRowsTransform::ReplicateRowsTransform(const DB::Block & input_header_) | ||
: ISimpleTransform(input_header_, ReplicateRowsStep::transformHeader(input_header_), true) | ||
{ | ||
} | ||
|
||
void ReplicateRowsTransform::transform(DB::Chunk & chunk) | ||
{ | ||
auto replica_column = chunk.getColumns().front(); | ||
size_t total_rows = 0; | ||
for (int i = 0; i < replica_column->size(); i++) | ||
{ | ||
total_rows += replica_column->get64(i); | ||
} | ||
|
||
auto columns = chunk.detachColumns(); | ||
DB::MutableColumns mutable_columns; | ||
for (int i = 1; i < columns.size(); i++) | ||
{ | ||
mutable_columns.push_back(columns[i]->cloneEmpty()); | ||
mutable_columns.back()->reserve(total_rows); | ||
DB::ColumnPtr src_col = columns[i]; | ||
DB::MutableColumnPtr & cur = mutable_columns.back(); | ||
for (int j = 0; j < replica_column->size(); j++) | ||
{ | ||
cur->insertManyFrom(*src_col, j, replica_column->getUInt(j)); | ||
} | ||
} | ||
|
||
chunk.setColumns(std::move(mutable_columns), total_rows); | ||
} | ||
} |
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,32 @@ | ||
#pragma once | ||
|
||
#include <Processors/ISimpleTransform.h> | ||
#include <Processors/QueryPlan/ITransformingStep.h> | ||
|
||
namespace local_engine | ||
{ | ||
|
||
class ReplicateRowsStep : public DB::ITransformingStep | ||
{ | ||
public: | ||
ReplicateRowsStep(const DB::DataStream& input_stream); | ||
|
||
static DB::Block transformHeader(const DB::Block& input); | ||
|
||
String getName() const override { return "ReplicateRowsStep"; } | ||
void transformPipeline(DB::QueryPipelineBuilder& pipeline, | ||
const DB::BuildQueryPipelineSettings& settings) override; | ||
private: | ||
void updateOutputStream() override; | ||
}; | ||
|
||
class ReplicateRowsTransform : public DB::ISimpleTransform | ||
{ | ||
public: | ||
ReplicateRowsTransform(const DB::Block& input_header_); | ||
|
||
String getName() const override { return "ReplicateRowsTransform"; } | ||
void transform(DB::Chunk&) override; | ||
|
||
}; | ||
} |
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
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