Coverage Report

Created: 2026-03-12 17:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/mysql_row_buffer.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 <stdint.h>
21
22
namespace cctz {
23
class time_zone;
24
}
25
namespace doris {
26
27
/**
28
// Now only support text protocol
29
 * helper for construct MySQL send row
30
 * The MYSQL protocol:
31
 *
32
 * | flag | (length) | value | flag | (length) | value | ......
33
 * <--------A column--------><--------A column--------><-.....->
34
 *
35
 * The flag means value's length or null value:
36
 * If value is nullptr, flag is 251
37
 * If value's length < 251, flag is the value's length
38
 * If 251 <= value's length < 65536, flag is 252 and the next two bytes is length
39
 * If 65536 <= value's length < 16777216 , flag is 253 and the next three bytes is length
40
 * If 16777216 <= value's length, flag is 254 and the next eighth bytes is length
41
 *
42
 * the code example:
43
 *     mrb.push_null();
44
 *     mrb.push_tinyint(5);
45
 *     mrb.push_int(120);
46
 *     mrb.push_string("...my length is 65536...");
47
 *
48
 * the protocol contents:
49
 *
50
 *  251-1-'5'-3-'120'-253-65536-"...my length is 65536..."
51
 *
52
 */
53
using int128_t = __int128;
54
class DecimalV2Value;
55
class IPv4Value;
56
class IPv6Value;
57
class TimestampTzValue;
58
59
class MysqlRowBuffer {
60
public:
61
    MysqlRowBuffer();
62
    ~MysqlRowBuffer();
63
64
299
    void reset() { _pos = _buf; }
65
66
    // Prepare for binary row buffer
67
    // init bitmap
68
    void start_binary_row(uint64_t num_cols);
69
70
    // TODO(zhaochun): add signed/unsigned support
71
    int push_tinyint(int8_t data);
72
    int push_smallint(int16_t data);
73
    int push_int(int32_t data);
74
    int push_bigint(int64_t data);
75
    int push_unsigned_bigint(uint64_t data);
76
    int push_largeint(int128_t data);
77
    int push_float(float data);
78
    int push_double(double data);
79
    int push_timev2(double data, int scale);
80
    template <typename DateType>
81
    int push_datetime(const DateType& data, int scale);
82
    int push_decimal(const DecimalV2Value& data, int round_scale);
83
    int push_ipv4(const IPv4Value& ipv4_val);
84
    int push_ipv6(const IPv6Value& ipv6_val);
85
    int push_timestamptz(const TimestampTzValue& tz, const cctz::time_zone& local_time_zone,
86
                         int scale);
87
    int push_string(const char* str, int64_t length);
88
    int push_null();
89
90
    template <typename DateType>
91
    int push_vec_datetime(DateType& data, int scale = -1);
92
93
310
    const char* buf() const { return _buf; }
94
0
    const char* pos() const { return _pos; }
95
600
    int64_t length() const { return _pos - _buf; }
96
97
private:
98
    int reserve(int64_t size);
99
100
    // append data into buffer
101
    int append(const char* data, int64_t len);
102
    // the same as mysql net_store_data
103
    // the first few bytes is length, followed by data
104
    int append_var_string(const char* data, int64_t len);
105
106
    char* _pos = nullptr;
107
    char* _buf = nullptr;
108
    int64_t _buf_size;
109
110
    uint32_t _field_pos = 0;
111
112
    char _default_buf[4096];
113
};
114
115
using MysqlRowBinaryBuffer = MysqlRowBuffer;
116
117
} // namespace doris