/root/doris/be/src/vec/columns/column.cpp
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 | | // This file is copied from |
18 | | // https://github.com/ClickHouse/ClickHouse/blob/master/src/Columns/IColumn.cpp |
19 | | // and modified by Doris |
20 | | |
21 | | #include "vec/columns/column.h" |
22 | | |
23 | | #include "util/simd/bits.h" |
24 | | #include "vec/columns/column_const.h" |
25 | | #include "vec/columns/column_nullable.h" |
26 | | #include "vec/core/sort_block.h" |
27 | | #include "vec/data_types/data_type.h" |
28 | | |
29 | | namespace doris::vectorized { |
30 | | |
31 | 3.14k | std::string IColumn::dump_structure() const { |
32 | 3.14k | std::stringstream res; |
33 | 3.14k | res << get_name() << "(size = " << size(); |
34 | | |
35 | 3.14k | ColumnCallback callback = [&](ColumnPtr& subcolumn) { |
36 | 2.79k | res << ", " << subcolumn->dump_structure(); |
37 | 2.79k | }; |
38 | | |
39 | | // simply read using for_each_subcolumn without modification; const_cast can be used. |
40 | 3.14k | const_cast<IColumn*>(this)->for_each_subcolumn(callback); |
41 | | |
42 | 3.14k | res << ")"; |
43 | 3.14k | return res.str(); |
44 | 3.14k | } |
45 | | |
46 | 0 | void IColumn::insert_from(const IColumn& src, size_t n) { |
47 | 0 | insert(src[n]); |
48 | 0 | } |
49 | | |
50 | | void IColumn::sort_column(const ColumnSorter* sorter, EqualFlags& flags, |
51 | 0 | IColumn::Permutation& perms, EqualRange& range, bool last_column) const { |
52 | 0 | sorter->sort_column(static_cast<const IColumn&>(*this), flags, perms, range, last_column); |
53 | 0 | } |
54 | | |
55 | | void IColumn::compare_internal(size_t rhs_row_id, const IColumn& rhs, int nan_direction_hint, |
56 | | int direction, std::vector<uint8_t>& cmp_res, |
57 | 3 | uint8_t* __restrict filter) const { |
58 | 3 | auto sz = this->size(); |
59 | 3 | DCHECK(cmp_res.size() == sz); |
60 | 3 | size_t begin = simd::find_zero(cmp_res, 0); |
61 | 6 | while (begin < sz) { |
62 | 3 | size_t end = simd::find_one(cmp_res, begin + 1); |
63 | 6 | for (size_t row_id = begin; row_id < end; row_id++) { |
64 | 3 | int res = this->compare_at(row_id, rhs_row_id, rhs, nan_direction_hint); |
65 | 3 | if (res * direction < 0) { |
66 | 1 | filter[row_id] = 1; |
67 | 1 | cmp_res[row_id] = 1; |
68 | 2 | } else if (res * direction > 0) { |
69 | 1 | cmp_res[row_id] = 1; |
70 | 1 | } |
71 | 3 | } |
72 | 3 | begin = simd::find_zero(cmp_res, end + 1); |
73 | 3 | } |
74 | 3 | } |
75 | | |
76 | | void IColumn::serialize_with_nullable(StringRef* keys, size_t num_rows, const bool has_null, |
77 | 0 | const uint8_t* __restrict null_map) const { |
78 | 0 | if (has_null) { |
79 | 0 | for (size_t i = 0; i < num_rows; ++i) { |
80 | 0 | char* dest = const_cast<char*>(keys[i].data + keys[i].size); |
81 | 0 | if (null_map[i]) { |
82 | | // is null |
83 | 0 | *dest = true; |
84 | 0 | keys[i].size += sizeof(UInt8); |
85 | 0 | continue; |
86 | 0 | } |
87 | | // not null |
88 | 0 | *dest = false; |
89 | 0 | keys[i].size += sizeof(UInt8) + serialize_impl(dest + sizeof(UInt8), i); |
90 | 0 | } |
91 | 0 | } else { |
92 | 0 | for (size_t i = 0; i < num_rows; ++i) { |
93 | 0 | char* dest = const_cast<char*>(keys[i].data + keys[i].size); |
94 | 0 | *dest = false; |
95 | 0 | keys[i].size += sizeof(UInt8) + serialize_impl(dest + sizeof(UInt8), i); |
96 | 0 | } |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | | void IColumn::deserialize_with_nullable(StringRef* keys, const size_t num_rows, |
101 | 0 | PaddedPODArray<UInt8>& null_map) { |
102 | 0 | for (size_t i = 0; i != num_rows; ++i) { |
103 | 0 | UInt8 is_null = *reinterpret_cast<const UInt8*>(keys[i].data); |
104 | 0 | null_map.push_back(is_null); |
105 | 0 | keys[i].data += sizeof(UInt8); |
106 | 0 | keys[i].size -= sizeof(UInt8); |
107 | 0 | if (is_null) { |
108 | 0 | insert_default(); |
109 | 0 | continue; |
110 | 0 | } |
111 | 0 | auto sz = deserialize_impl(keys[i].data); |
112 | 0 | keys[i].data += sz; |
113 | 0 | keys[i].size -= sz; |
114 | 0 | } |
115 | 0 | } |
116 | | |
117 | 32.9k | bool is_column_nullable(const IColumn& column) { |
118 | 32.9k | return is_column<ColumnNullable>(column); |
119 | 32.9k | } |
120 | | |
121 | 72.1M | bool is_column_const(const IColumn& column) { |
122 | 72.1M | return is_column<ColumnConst>(column); |
123 | 72.1M | } |
124 | | |
125 | | } // namespace doris::vectorized |