be/src/exec/table_connector.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 | | |
18 | | #include "exec/table_connector.h" |
19 | | |
20 | | // IWYU pragma: no_include <bthread/errno.h> |
21 | | #include <errno.h> // IWYU pragma: keep |
22 | | #include <gen_cpp/Metrics_types.h> |
23 | | #include <gen_cpp/Types_types.h> |
24 | | #include <glog/logging.h> |
25 | | #include <iconv.h> |
26 | | |
27 | | #include <memory> |
28 | | #include <string_view> |
29 | | #include <type_traits> |
30 | | |
31 | | #include "core/assert_cast.h" |
32 | | #include "core/binary_cast.hpp" |
33 | | #include "core/block/block.h" |
34 | | #include "core/column/column.h" |
35 | | #include "core/column/column_array.h" |
36 | | #include "core/column/column_nullable.h" |
37 | | #include "core/data_type/data_type.h" |
38 | | #include "core/data_type/data_type_array.h" |
39 | | #include "core/data_type/data_type_date_or_datetime_v2.h" |
40 | | #include "core/data_type/data_type_nullable.h" |
41 | | #include "core/data_type/define_primitive_type.h" |
42 | | #include "core/value/decimalv2_value.h" |
43 | | #include "core/value/vdatetime_value.h" |
44 | | |
45 | | namespace doris { |
46 | | #include "common/compile_check_begin.h" |
47 | | |
48 | | class TupleDescriptor; |
49 | | |
50 | | TableConnector::TableConnector(const TupleDescriptor* tuple_desc, bool use_transaction, |
51 | | std::string_view table_name, const std::string& sql_str) |
52 | 11 | : _is_open(false), |
53 | 11 | _use_tranaction(use_transaction), |
54 | 11 | _is_in_transaction(false), |
55 | 11 | _table_name(table_name), |
56 | 11 | _tuple_desc(tuple_desc), |
57 | 11 | _sql_str(sql_str) {} |
58 | | |
59 | 0 | void TableConnector::init_profile(doris::RuntimeProfile* operator_profile) { |
60 | 0 | RuntimeProfile* custom_profile = operator_profile->get_child("CustomCounters"); |
61 | 0 | _convert_tuple_timer = ADD_TIMER(custom_profile, "TupleConvertTime"); |
62 | 0 | _result_send_timer = ADD_TIMER(custom_profile, "ResultSendTime"); |
63 | 0 | _sent_rows_counter = ADD_COUNTER(custom_profile, "NumSentRows", TUnit::UNIT); |
64 | 0 | } |
65 | | |
66 | 0 | std::u16string TableConnector::utf8_to_u16string(const char* first, const char* last) { |
67 | 0 | auto deleter = [](auto convertor) { |
68 | 0 | if (convertor == reinterpret_cast<decltype(convertor)>(-1)) { |
69 | 0 | return; |
70 | 0 | } |
71 | 0 | iconv_close(convertor); |
72 | 0 | }; |
73 | 0 | std::unique_ptr<std::remove_pointer_t<iconv_t>, decltype(deleter)> convertor( |
74 | 0 | iconv_open("UTF-16LE", "UTF-8"), deleter); |
75 | | // The `first` variable remains unmodified; `const_cast` is used to adapt to third-party functions. |
76 | 0 | char* in = const_cast<char*>(first); |
77 | 0 | size_t inbytesleft = last - first; |
78 | |
|
79 | 0 | char16_t buffer[1024]; |
80 | 0 | char* out = reinterpret_cast<char*>(&buffer[0]); |
81 | 0 | size_t outbytesleft = sizeof(buffer); |
82 | |
|
83 | 0 | std::u16string result; |
84 | 0 | while (inbytesleft > 0) { |
85 | 0 | if (iconv(convertor.get(), &in, &inbytesleft, &out, &outbytesleft)) { |
86 | 0 | if (errno == E2BIG) { |
87 | 0 | result += std::u16string_view(buffer, |
88 | 0 | (sizeof(buffer) - outbytesleft) / sizeof(char16_t)); |
89 | 0 | out = reinterpret_cast<char*>(&buffer[0]); |
90 | 0 | outbytesleft = sizeof(buffer); |
91 | 0 | } else { |
92 | 0 | LOG(WARNING) << fmt::format("Failed to convert the UTF-8 string {} to UTF-16LE", |
93 | 0 | std::string(first, last)); |
94 | 0 | return result; |
95 | 0 | } |
96 | 0 | } |
97 | 0 | } |
98 | 0 | result += std::u16string_view(buffer, (sizeof(buffer) - outbytesleft) / sizeof(char16_t)); |
99 | 0 | return result; |
100 | 0 | } |
101 | | |
102 | | #include "common/compile_check_end.h" |
103 | | } // namespace doris |