forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_array_utils.h
More file actions
100 lines (89 loc) · 3.81 KB
/
Copy pathfunction_array_utils.h
File metadata and controls
100 lines (89 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// 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.
#pragma once
#include "core/column/column.h"
#include "core/column/column_array.h"
#include "core/column/column_nullable.h"
#include "core/data_type/data_type.h"
#include "core/types.h"
namespace doris {
class IColumn;
} // namespace doris
namespace doris {
struct ColumnArrayMutableData {
public:
MutableColumnPtr array_nested_col = nullptr;
ColumnUInt8::Container* nested_nullmap_data = nullptr;
MutableColumnPtr offsets_col = nullptr;
ColumnArray::Offsets64* offsets_ptr = nullptr;
IColumn* nested_col = nullptr;
};
struct ColumnArrayExecutionData {
public:
void reset() {
array_nullmap_data = nullptr;
array_col = nullptr;
offsets_ptr = nullptr;
nested_nullmap_data = nullptr;
nested_col = nullptr;
}
public:
const UInt8* array_nullmap_data = nullptr;
const ColumnArray* array_col = nullptr;
const ColumnArray::Offsets64* offsets_ptr = nullptr;
const UInt8* nested_nullmap_data = nullptr;
ColumnPtr nested_col = nullptr;
DataTypePtr nested_type = nullptr;
// wrap the nested column as variant column
bool output_as_variant = false;
// propagate enable_doc_mode when wrapping as variant
bool variant_enable_doc_mode = false;
ColumnArrayMutableData to_mutable_data() const {
ColumnArrayMutableData dst;
dst.offsets_col = ColumnArray::ColumnOffsets::create();
dst.offsets_ptr =
&reinterpret_cast<ColumnArray::ColumnOffsets*>(dst.offsets_col.get())->get_data();
dst.array_nested_col =
ColumnNullable::create(nested_col->clone_empty(), ColumnUInt8::create());
auto* nullable_col = reinterpret_cast<ColumnNullable*>(dst.array_nested_col.get());
dst.nested_nullmap_data = &nullable_col->get_null_map_data();
dst.nested_col = nullable_col->get_nested_column_ptr().get();
for (size_t row = 0; row < offsets_ptr->size(); ++row) {
dst.offsets_ptr->push_back((*offsets_ptr)[row]);
size_t off = (*offsets_ptr)[row - 1];
size_t len = (*offsets_ptr)[row] - off;
for (size_t start = off; start < off + len; ++start) {
if (nested_nullmap_data && nested_nullmap_data[start]) {
dst.nested_col->insert_default();
dst.nested_nullmap_data->push_back(1);
} else {
dst.nested_col->insert_from(*nested_col, start);
dst.nested_nullmap_data->push_back(0);
}
}
}
return dst;
}
};
bool extract_column_array_info(const IColumn& src, ColumnArrayExecutionData& data);
ColumnArrayMutableData create_mutable_data(const IColumn* nested_col, bool is_nullable);
MutableColumnPtr assemble_column_array(ColumnArrayMutableData& data);
// array[offset:length]
void slice_array(ColumnArrayMutableData& dst, ColumnArrayExecutionData& src,
const IColumn& offset_column, const IColumn* length_column);
using ColumnArrayExecutionDatas = std::vector<ColumnArrayExecutionData>;
} // namespace doris