-
Notifications
You must be signed in to change notification settings - Fork 4k
[feature](external) Add generic connector write framework prerequisites #68320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
120e530
d044729
40bac37
2c7c39b
363ab1e
d6dc2e8
e347874
85393f8
0aa897f
5da0e9c
fece437
70d3c43
eff1499
7b62991
2f2a3fd
75e31b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,13 +28,15 @@ | |
| #include <random> | ||
| #include <string> | ||
|
|
||
| #include "agent/be_exec_version_manager.h" | ||
| #include "common/status.h" | ||
| #include "core/column/column_const.h" | ||
| #include "exec/exchange/exchange_writer.h" | ||
| #include "exec/exchange/local_exchange_sink_operator.h" | ||
| #include "exec/operator/exchange_sink_buffer.h" | ||
| #include "exec/operator/operator.h" | ||
| #include "exec/operator/sort_source_operator.h" | ||
| #include "exec/partitioner/external/external_table_sink_hash_partitioner.h" | ||
| #include "exec/pipeline/dependency.h" | ||
| #include "exec/pipeline/pipeline_fragment_context.h" | ||
| #include "exec/sink/scale_writer_partitioning_exchanger.hpp" | ||
|
|
@@ -98,7 +100,8 @@ Status ExchangeSinkLocalState::init(RuntimeState* state, LocalSinkStateInfo& inf | |
| _part_type = p._part_type; | ||
| // Shuffle the channels randomly | ||
| if (_part_type == TPartitionType::UNPARTITIONED || _part_type == TPartitionType::RANDOM || | ||
| _part_type == TPartitionType::HIVE_TABLE_SINK_UNPARTITIONED) { | ||
| _part_type == TPartitionType::HIVE_TABLE_SINK_UNPARTITIONED || | ||
| _part_type == TPartitionType::EXTERNAL_TABLE_SINK_UNPARTITIONED) { | ||
| std::random_device rd; | ||
| std::mt19937 g(rd()); | ||
| shuffle(channels.begin(), channels.end(), g); | ||
|
|
@@ -175,6 +178,27 @@ Status ExchangeSinkLocalState::init(RuntimeState* state, LocalSinkStateInfo& inf | |
| RETURN_IF_ERROR(_partitioner->prepare(state, p._row_desc)); | ||
| custom_profile()->add_info_string( | ||
| "Partitioner", fmt::format("ScaleWriterPartitioner({})", _partition_count)); | ||
| } else if (_part_type == TPartitionType::EXTERNAL_TABLE_SINK_HASH_PARTITIONED) { | ||
| if (state->be_exec_version() < SUPPORT_EXTERNAL_TABLE_SINK_HASH_VERSION) { | ||
| return Status::NotSupported( | ||
| "External table sink hash exchange requires BE execution version {}, actual {}", | ||
| SUPPORT_EXTERNAL_TABLE_SINK_HASH_VERSION, state->be_exec_version()); | ||
| } | ||
| if (!p._has_external_table_sink_hash_partition_info) { | ||
| return Status::InternalError("External table sink hash partition info is missing"); | ||
| } | ||
| _partition_count = channels.size(); | ||
| const bool use_crc32c = _state->query_options().__isset.enable_new_shuffle_hash_method && | ||
| _state->query_options().enable_new_shuffle_hash_method; | ||
| const ShuffleHashMethod hash_method = | ||
| use_crc32c ? ShuffleHashMethod::CRC32C : ShuffleHashMethod::CRC32; | ||
| _partitioner = std::make_unique<ExternalTableSinkHashPartitioner>( | ||
| _partition_count, hash_method, p._external_table_sink_hash_partition_info); | ||
| RETURN_IF_ERROR(_partitioner->init(p._texprs)); | ||
| RETURN_IF_ERROR(_partitioner->prepare(state, p._row_desc)); | ||
| custom_profile()->add_info_string( | ||
| "Partitioner", | ||
| fmt::format("ExternalTableSinkHashPartitioner({})", _partition_count)); | ||
| } else if (_part_type == TPartitionType::MERGE_PARTITIONED) { | ||
| if (!p._has_merge_partition_info) { | ||
| return Status::InternalError("Merge partition info is missing"); | ||
|
|
@@ -272,6 +296,7 @@ Status ExchangeSinkLocalState::open(RuntimeState* state) { | |
| if (_part_type == TPartitionType::HASH_PARTITIONED || | ||
| _part_type == TPartitionType::BUCKET_SHFFULE_HASH_PARTITIONED || | ||
| _part_type == TPartitionType::HIVE_TABLE_SINK_HASH_PARTITIONED || | ||
| _part_type == TPartitionType::EXTERNAL_TABLE_SINK_HASH_PARTITIONED || | ||
| _part_type == TPartitionType::OLAP_TABLE_SINK_HASH_PARTITIONED || | ||
| _part_type == TPartitionType::MERGE_PARTITIONED) { | ||
| RETURN_IF_ERROR(_partitioner->open(state)); | ||
|
|
@@ -322,6 +347,8 @@ ExchangeSinkOperatorX::ExchangeSinkOperatorX( | |
| sink.output_partition.type == TPartitionType::BUCKET_SHFFULE_HASH_PARTITIONED || | ||
| sink.output_partition.type == TPartitionType::HIVE_TABLE_SINK_HASH_PARTITIONED || | ||
| sink.output_partition.type == TPartitionType::HIVE_TABLE_SINK_UNPARTITIONED || | ||
| sink.output_partition.type == TPartitionType::EXTERNAL_TABLE_SINK_HASH_PARTITIONED || | ||
| sink.output_partition.type == TPartitionType::EXTERNAL_TABLE_SINK_UNPARTITIONED || | ||
| sink.output_partition.type == TPartitionType::MERGE_PARTITIONED); | ||
| #endif | ||
| _name = "ExchangeSinkOperatorX"; | ||
|
|
@@ -333,6 +360,11 @@ ExchangeSinkOperatorX::ExchangeSinkOperatorX( | |
| _merge_partition_info = sink.output_partition.merge_partition_info; | ||
| _has_merge_partition_info = true; | ||
| } | ||
| if (sink.output_partition.__isset.external_table_sink_hash_partition_info) { | ||
| _external_table_sink_hash_partition_info = | ||
| sink.output_partition.external_table_sink_hash_partition_info; | ||
| _has_external_table_sink_hash_partition_info = true; | ||
| } | ||
|
|
||
| if (_part_type != TPartitionType::UNPARTITIONED) { | ||
| // if the destinations only one dest, we need to use broadcast | ||
|
|
@@ -535,20 +567,16 @@ Status ExchangeSinkOperatorX::sink_impl(RuntimeState* state, Block* block, bool | |
| _part_type == TPartitionType::BUCKET_SHFFULE_HASH_PARTITIONED || | ||
| _part_type == TPartitionType::OLAP_TABLE_SINK_HASH_PARTITIONED || | ||
| _part_type == TPartitionType::HIVE_TABLE_SINK_HASH_PARTITIONED || | ||
| _part_type == TPartitionType::EXTERNAL_TABLE_SINK_HASH_PARTITIONED || | ||
| _part_type == TPartitionType::MERGE_PARTITIONED) { | ||
| RETURN_IF_ERROR(local_state._writer->write(state, block, eos)); | ||
| } else if (_part_type == TPartitionType::HIVE_TABLE_SINK_UNPARTITIONED) { | ||
| } else if (_part_type == TPartitionType::HIVE_TABLE_SINK_UNPARTITIONED || | ||
| _part_type == TPartitionType::EXTERNAL_TABLE_SINK_UNPARTITIONED) { | ||
| // Control the number of channels according to the flow, thereby controlling the number of table sink writers. | ||
| RETURN_IF_ERROR(send_to_current_channel()); | ||
| _data_processed += block->bytes(); | ||
| if (_writer_count < local_state.channels.size()) { | ||
| if (_data_processed >= | ||
| _writer_count * | ||
| config::table_sink_non_partition_write_scaling_data_processed_threshold) { | ||
| _writer_count++; | ||
| } | ||
| } | ||
| local_state.current_channel_idx = (local_state.current_channel_idx + 1) % _writer_count; | ||
| const auto writer_count = | ||
| _update_writer_scaling(block->bytes(), local_state.channels.size()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Snapshot the block size before sending it. A local |
||
| local_state.current_channel_idx = (local_state.current_channel_idx + 1) % writer_count; | ||
| } else { | ||
| // Range partition | ||
| // 1. calculate range | ||
|
|
@@ -587,6 +615,18 @@ Status ExchangeSinkOperatorX::sink_impl(RuntimeState* state, Block* block, bool | |
| return final_st; | ||
| } | ||
|
|
||
| size_t ExchangeSinkOperatorX::_update_writer_scaling(size_t block_bytes, size_t max_writer_count) { | ||
| LockGuard lock(_writer_scaling_mutex); | ||
| _data_processed += block_bytes; | ||
| if (_writer_count < max_writer_count && | ||
| _data_processed >= | ||
| _writer_count * | ||
| config::table_sink_non_partition_write_scaling_data_processed_threshold) { | ||
| ++_writer_count; | ||
| } | ||
| return _writer_count; | ||
| } | ||
|
|
||
| void ExchangeSinkLocalState::register_channels(ExchangeSinkBuffer* buffer) { | ||
| for (auto& channel : channels) { | ||
| channel->set_exchange_buffer(buffer); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // 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 "exec/partitioner/external/external_partition_function_factory.h" | ||
|
|
||
| #include "common/status.h" | ||
|
|
||
| namespace doris { | ||
|
|
||
| Status create_external_partition_function(const TExternalTableSinkHashPartitionInfo& partition_info, | ||
| PartitionerBase::HashValType logical_partition_count, | ||
| ShuffleHashMethod hash_method, | ||
| const std::vector<TExpr>& partition_exprs, | ||
| std::unique_ptr<PartitionFunction>* partition_function) { | ||
| if (partition_function == nullptr) { | ||
| return Status::InvalidArgument("External partition function output is null"); | ||
| } | ||
| if (partition_info.partition_function != "direct_hash") { | ||
| return Status::NotSupported("Unsupported external sink partition function '{}'", | ||
| partition_info.partition_function); | ||
| } | ||
| if (partition_info.__isset.partition_function_options && | ||
| !partition_info.partition_function_options.empty()) { | ||
| return Status::InvalidArgument("Direct hash partition function does not accept options"); | ||
| } | ||
| auto function = std::make_unique<HashPartitionFunction>(logical_partition_count, hash_method); | ||
| RETURN_IF_ERROR(function->init(partition_exprs)); | ||
| *partition_function = std::move(function); | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| } // namespace doris |
Uh oh!
There was an error while loading. Please reload this page.