be/src/format/partition_column_reader.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <cstddef> |
21 | | #include <cstdint> |
22 | | #include <memory> |
23 | | |
24 | | #include "format/count_reader.h" |
25 | | #include "format/table/table_format_reader.h" |
26 | | |
27 | | namespace doris { |
28 | | |
29 | | // Decorates an initialized Hive reader after its footer proves the range cardinality. |
30 | | // Partition-only duplicate-insensitive aggregates need one row from a nonempty range, |
31 | | // but a valid empty file must contribute no partition value. |
32 | | class PartitionColumnReader final : public CountReader { |
33 | | public: |
34 | | // V1 keeps the whole-file requirement on purpose. Splitting is planned without knowing whether |
35 | | // this reader will accept the pushdown (a retained filter or a pending runtime filter can both |
36 | | // refuse it), so a file may arrive split; the row count of a partial range is only dependable |
37 | | // when the Parquet reader actually filters row groups by range, and ORC's count is 0 until its |
38 | | // row reader exists. Requiring the whole range keeps the count authoritative; the cost is that |
39 | | // V1 skips the shortcut on files the connector split (FileScannerV2 has no such requirement). |
40 | 13 | static bool supports_range(const TFileRangeDesc& range, TFileFormatType::type format_type) { |
41 | 13 | return range.__isset.table_format_params && |
42 | 13 | range.table_format_params.table_format_type == "hive" && |
43 | 13 | (format_type == TFileFormatType::FORMAT_PARQUET || |
44 | 9 | format_type == TFileFormatType::FORMAT_ORC) && |
45 | 13 | range.start_offset == 0 && range.file_size >= 0 && range.size == range.file_size; |
46 | 13 | } |
47 | | |
48 | | PartitionColumnReader(int64_t total_rows, std::unique_ptr<TableFormatReader> inner_reader) |
49 | 3 | : CountReader(total_rows > 0 ? 1 : 0, 1, std::move(inner_reader)) { |
50 | 3 | DORIS_CHECK(total_rows >= 0); |
51 | 3 | DORIS_CHECK(this->inner_reader() != nullptr); |
52 | 3 | set_push_down_agg_type(TPushAggOp::type::PARTITION_VALUE); |
53 | 3 | } |
54 | | |
55 | | protected: |
56 | 6 | Status on_after_read_block(Block* block, size_t* read_rows) override { |
57 | 6 | if (*read_rows > 0) { |
58 | | // CountReader supplies cardinality; the initialized reader owns typed partition values. |
59 | | // Fill helpers append, so discard the default cells before materializing constants. |
60 | 2 | block->clear_column_data(); |
61 | 2 | RETURN_IF_ERROR(static_cast<TableFormatReader*>(inner_reader()) |
62 | 2 | ->fill_remaining_columns(block, *read_rows)); |
63 | 2 | } |
64 | 6 | return Status::OK(); |
65 | 6 | } |
66 | | }; |
67 | | |
68 | | } // namespace doris |