|
| 1 | +// Copyright 2021 Datafuse Labs |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +use databend_common_exception::Result; |
| 16 | +use databend_common_expression::TableSchemaRef; |
| 17 | +use databend_common_pipeline::core::Pipeline; |
| 18 | +use databend_storages_common_stage::CopyIntoLocationInfo; |
| 19 | +use opendal::Operator; |
| 20 | + |
| 21 | +use super::writer_processor::AvroFileWriter; |
| 22 | +use crate::append::file_size::resolve_file_size_options; |
| 23 | + |
| 24 | +#[allow(clippy::too_many_arguments)] |
| 25 | +pub(crate) fn append_data_to_avro_files( |
| 26 | + pipeline: &mut Pipeline, |
| 27 | + info: CopyIntoLocationInfo, |
| 28 | + schema: TableSchemaRef, |
| 29 | + op: Operator, |
| 30 | + query_id: String, |
| 31 | + group_id: &std::sync::atomic::AtomicUsize, |
| 32 | + mem_limit: usize, |
| 33 | + max_threads: usize, |
| 34 | +) -> Result<()> { |
| 35 | + let (target_file_size, max_threads) = |
| 36 | + resolve_file_size_options(mem_limit, max_threads, &info.options); |
| 37 | + pipeline.try_resize(max_threads)?; |
| 38 | + pipeline.add_transform(|input, output| { |
| 39 | + let gid = group_id.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 40 | + AvroFileWriter::try_create( |
| 41 | + input, |
| 42 | + output, |
| 43 | + info.clone(), |
| 44 | + schema.clone(), |
| 45 | + op.clone(), |
| 46 | + query_id.clone(), |
| 47 | + gid, |
| 48 | + target_file_size, |
| 49 | + ) |
| 50 | + })?; |
| 51 | + Ok(()) |
| 52 | +} |
0 commit comments