-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
What changes were proposed in this pull request? Support expression ReplicateRows in spark How was this patch tested? unit tests
- Loading branch information
1 parent
d589aa3
commit 47fa44f
Showing
10 changed files
with
219 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,108 @@ | ||
/* | ||
* 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 "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,48 @@ | ||
/* | ||
* 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 <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