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+ #include " exprs/rpc_fn_comm.h"
19+ namespace doris ::vectorized {
20+ void convert_nullable_col_to_pvalue (const vectorized::ColumnPtr& column,
21+ const vectorized::DataTypePtr& data_type,
22+ const vectorized::ColumnUInt8& null_col, PValues* arg,
23+ int start, int end) {
24+ int row_count = end - start;
25+ if (column->has_null (row_count)) {
26+ auto * null_map = arg->mutable_null_map ();
27+ null_map->Reserve (row_count);
28+ const auto * col = vectorized::check_and_get_column<vectorized::ColumnUInt8>(null_col);
29+ auto & data = col->get_data ();
30+ null_map->Add (data.begin () + start, data.begin () + end);
31+ convert_col_to_pvalue<true >(column, data_type, arg, start, end);
32+ } else {
33+ convert_col_to_pvalue<false >(column, data_type, arg, start, end);
34+ }
35+ }
36+
37+ void convert_block_to_proto (vectorized::Block& block, const vectorized::ColumnNumbers& arguments,
38+ size_t input_rows_count, PFunctionCallRequest* request) {
39+ size_t row_count = std::min (block.rows (), input_rows_count);
40+ for (size_t col_idx : arguments) {
41+ PValues* arg = request->add_args ();
42+ vectorized::ColumnWithTypeAndName& column = block.get_by_position (col_idx);
43+ arg->set_has_null (column.column ->has_null (row_count));
44+ auto col = column.column ->convert_to_full_column_if_const ();
45+ if (auto * nullable =
46+ vectorized::check_and_get_column<const vectorized::ColumnNullable>(*col)) {
47+ auto data_col = nullable->get_nested_column_ptr ();
48+ auto & null_col = nullable->get_null_map_column ();
49+ auto data_type =
50+ std::reinterpret_pointer_cast<const vectorized::DataTypeNullable>(column.type );
51+ convert_nullable_col_to_pvalue (data_col->convert_to_full_column_if_const (),
52+ data_type->get_nested_type (), null_col, arg, 0 ,
53+ row_count);
54+ } else {
55+ convert_col_to_pvalue<false >(col, column.type , arg, 0 , row_count);
56+ }
57+ }
58+ }
59+
60+ void convert_to_block (vectorized::Block& block, const PValues& result, size_t pos) {
61+ auto data_type = block.get_data_type (pos);
62+ if (data_type->is_nullable ()) {
63+ auto null_type =
64+ std::reinterpret_pointer_cast<const vectorized::DataTypeNullable>(data_type);
65+ auto data_col = null_type->get_nested_type ()->create_column ();
66+ convert_to_column<true >(data_col, result);
67+ auto null_col = vectorized::ColumnUInt8::create (data_col->size (), 0 );
68+ auto & null_map_data = null_col->get_data ();
69+ null_col->reserve (data_col->size ());
70+ null_col->resize (data_col->size ());
71+ if (result.has_null ()) {
72+ for (int i = 0 ; i < data_col->size (); ++i) {
73+ null_map_data[i] = result.null_map (i);
74+ }
75+ } else {
76+ for (int i = 0 ; i < data_col->size (); ++i) {
77+ null_map_data[i] = false ;
78+ }
79+ }
80+ block.replace_by_position (
81+ pos, vectorized::ColumnNullable::create (std::move (data_col), std::move (null_col)));
82+ } else {
83+ auto column = data_type->create_column ();
84+ convert_to_column<false >(column, result);
85+ block.replace_by_position (pos, std::move (column));
86+ }
87+ }
88+
89+ } // namespace doris::vectorized
0 commit comments