Skip to content

Commit

Permalink
feat: Allow non standard partition functions in ScaleWriterPartitioni…
Browse files Browse the repository at this point in the history
…ngLocalPartition (facebookincubator#11762)

Summary:
Pull Request resolved: facebookincubator#11762

For example Hive connector partitioning function

Reviewed By: xiaoxmeng, Yuhta, tanjialiang

Differential Revision: D66833831

fbshipit-source-id: 9ee130ec5e90d2d31973ef14344cd769da63d06a
  • Loading branch information
arhimondr authored and facebook-github-bot committed Dec 9, 2024
1 parent 9a31f1c commit b9cce6d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
8 changes: 3 additions & 5 deletions velox/exec/LocalPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,13 @@ std::unique_ptr<Operator> createScaleWriterLocalPartition(
const std::shared_ptr<const core::LocalPartitionNode>& localPartitionNode,
int32_t operatorId,
DriverCtx* ctx) {
if (dynamic_cast<const HashPartitionFunctionSpec*>(
if (dynamic_cast<const RoundRobinPartitionFunctionSpec*>(
&localPartitionNode->partitionFunctionSpec())) {
return std::make_unique<ScaleWriterPartitioningLocalPartition>(
return std::make_unique<ScaleWriterLocalPartition>(
operatorId, ctx, localPartitionNode);
}

VELOX_CHECK_NOT_NULL(dynamic_cast<const RoundRobinPartitionFunctionSpec*>(
&localPartitionNode->partitionFunctionSpec()));
return std::make_unique<ScaleWriterLocalPartition>(
return std::make_unique<ScaleWriterPartitioningLocalPartition>(
operatorId, ctx, localPartitionNode);
}

Expand Down
4 changes: 0 additions & 4 deletions velox/exec/ScaleWriterLocalPartition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ ScaleWriterPartitioningLocalPartition::ScaleWriterPartitioningLocalPartition(
: planNode->partitionFunctionSpec().create(
numTablePartitions_,
/*localExchange=*/true);
if (partitionFunction_ != nullptr) {
VELOX_CHECK_NOT_NULL(
dynamic_cast<HashPartitionFunction*>(partitionFunction_.get()));
}
}

void ScaleWriterPartitioningLocalPartition::initialize() {
Expand Down
1 change: 1 addition & 0 deletions velox/exec/tests/PlanNodeSerdeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class PlanNodeSerdeTest : public testing::Test,
connector::hive::LocationHandle::registerSerDe();
connector::hive::HiveColumnHandle::registerSerDe();
connector::hive::HiveInsertTableHandle::registerSerDe();
connector::hive::registerHivePartitionFunctionSerDe();
core::PlanNode::registerSerDe();
core::ITypedExpr::registerSerDe();
registerPartitionFunctionSerDe();
Expand Down
18 changes: 13 additions & 5 deletions velox/exec/tests/utils/PlanBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,12 +1293,20 @@ PlanBuilder& PlanBuilder::localPartition(const std::vector<std::string>& keys) {

PlanBuilder& PlanBuilder::scaleWriterlocalPartition(
const std::vector<std::string>& keys) {
planNode_ = createLocalPartitionNode(
std::vector<column_index_t> keyIndices;
keyIndices.reserve(keys.size());
for (const auto& key : keys) {
keyIndices.push_back(planNode_->outputType()->getChildIdx(key));
}
auto hivePartitionFunctionFactory =
std::make_shared<HivePartitionFunctionSpec>(
1009, keyIndices, std::vector<VectorPtr>{});
planNode_ = std::make_shared<core::LocalPartitionNode>(
nextPlanNodeId(),
exprs(keys, planNode_->outputType()),
/*scaleWriter=*/true,
{planNode_},
pool_);
core::LocalPartitionNode::Type::kRepartition,
true,
hivePartitionFunctionFactory,
std::vector{planNode_});
return *this;
}

Expand Down

0 comments on commit b9cce6d

Please sign in to comment.