Coverage Report

Created: 2026-08-16 15:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/parse/variant_string_parse.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 <array>
21
#include <cmath>
22
#include <cstddef>
23
#include <cstdint>
24
#include <memory>
25
#include <string>
26
27
#include "common/status.h"
28
#include "core/value/variant/variant_batch_builder.h"
29
#include "core/value/variant/variant_value.h"
30
31
namespace cctz {
32
class time_zone;
33
}
34
35
namespace doris {
36
37
// Formatting state supplied by the column adapter. A null time zone means UTC.
38
struct VariantJsonFormatOptions {
39
    const cctz::time_zone* timezone = nullptr;
40
};
41
42
struct JsonToVariantOptions {
43
    uint32_t max_json_key_length = 255;
44
    bool throw_on_invalid_json = false;
45
    bool check_duplicate_json_path = false;
46
47
    // Takes a value snapshot. Later changes to mutable config do not affect an encoder.
48
    static JsonToVariantOptions current_config();
49
};
50
51
// Reuses one JSON parser and one batch builder. Each add_json() collects into a stack-only row;
52
// finish_batch() performs pass 2. A failed add_json() is terminal, as is a successful
53
// finish_batch(). try_add_json() rolls back invalid input rows and keeps collecting.
54
class JsonStringToVariantEncoder {
55
public:
56
    JsonStringToVariantEncoder();
57
    explicit JsonStringToVariantEncoder(JsonToVariantOptions options);
58
    ~JsonStringToVariantEncoder();
59
60
    JsonStringToVariantEncoder(const JsonStringToVariantEncoder&) = delete;
61
    JsonStringToVariantEncoder& operator=(const JsonStringToVariantEncoder&) = delete;
62
    JsonStringToVariantEncoder(JsonStringToVariantEncoder&&) noexcept;
63
    JsonStringToVariantEncoder& operator=(JsonStringToVariantEncoder&&) noexcept;
64
65
    void add_json(StringRef json);
66
    Status try_add_json(StringRef json);
67
    VariantBatchBuilder finish_batch();
68
69
private:
70
    struct Impl;
71
    std::unique_ptr<Impl> _impl;
72
};
73
74
namespace variant_json {
75
76
struct FormattedScalar {
77
    std::array<char, 128> bytes {};
78
    size_t size = 0;
79
};
80
81
void require_json_depth(uint32_t depth);
82
void require_exact_json_value(VariantRef value);
83
void require_valid_json_utf8(StringRef value, const char* description);
84
void require_json_object_key(StringRef key, StringRef previous_key, uint32_t field_index);
85
[[noreturn]] void throw_unsupported_json_primitive(VariantPrimitiveId id);
86
87
FormattedScalar format_json_int(int64_t value);
88
FormattedScalar format_json_float(float value);
89
FormattedScalar format_json_double(double value);
90
FormattedScalar format_json_decimal(VariantDecimal value);
91
FormattedScalar format_json_date(int32_t days_since_epoch);
92
FormattedScalar format_json_timestamp(int64_t value, uint8_t fractional_digits, bool utc_adjusted,
93
                                      const cctz::time_zone* timezone);
94
FormattedScalar format_json_time_micros(int64_t value);
95
FormattedScalar format_json_uuid(const std::array<uint8_t, 16>& value);
96
97
template <typename Writer, size_t N>
98
144k
void write_literal(Writer& out, const char (&value)[N]) {
99
144k
    out.write(value, N - 1);
100
144k
}
column_variant_v2_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_110JsonWriterELm2EEEvRT_RAT0__Kc
Line
Count
Source
98
567
void write_literal(Writer& out, const char (&value)[N]) {
99
567
    out.write(value, N - 1);
100
567
}
Unexecuted instantiation: column_variant_v2_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_110JsonWriterELm5EEEvRT_RAT0__Kc
Unexecuted instantiation: column_variant_v2_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_110JsonWriterELm6EEEvRT_RAT0__Kc
Unexecuted instantiation: column_variant_v2_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_110JsonWriterELm11EEEvRT_RAT0__Kc
Unexecuted instantiation: column_variant_v2_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_110JsonWriterELm12EEEvRT_RAT0__Kc
function_variant_parse_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_112StringWriterELm2EEEvRT_RAT0__Kc
Line
Count
Source
98
35
void write_literal(Writer& out, const char (&value)[N]) {
99
35
    out.write(value, N - 1);
100
35
}
function_variant_parse_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_112StringWriterELm5EEEvRT_RAT0__Kc
Line
Count
Source
98
4
void write_literal(Writer& out, const char (&value)[N]) {
99
4
    out.write(value, N - 1);
100
4
}
Unexecuted instantiation: function_variant_parse_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_112StringWriterELm6EEEvRT_RAT0__Kc
Unexecuted instantiation: function_variant_parse_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_112StringWriterELm11EEEvRT_RAT0__Kc
Unexecuted instantiation: function_variant_parse_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_112StringWriterELm12EEEvRT_RAT0__Kc
_ZN5doris12variant_json13write_literalI17VariantJsonWriterLm2EEEvRT_RAT0__Kc
Line
Count
Source
98
31
void write_literal(Writer& out, const char (&value)[N]) {
99
31
    out.write(value, N - 1);
100
31
}
_ZN5doris12variant_json13write_literalI17VariantJsonWriterLm5EEEvRT_RAT0__Kc
Line
Count
Source
98
6
void write_literal(Writer& out, const char (&value)[N]) {
99
6
    out.write(value, N - 1);
100
6
}
Unexecuted instantiation: _ZN5doris12variant_json13write_literalI17VariantJsonWriterLm6EEEvRT_RAT0__Kc
Unexecuted instantiation: _ZN5doris12variant_json13write_literalI17VariantJsonWriterLm11EEEvRT_RAT0__Kc
Unexecuted instantiation: _ZN5doris12variant_json13write_literalI17VariantJsonWriterLm12EEEvRT_RAT0__Kc
variant_assembler_legacy_test.cpp:_ZN5doris12variant_json13write_literalINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterELm2EEEvRT_RAT0__Kc
Line
Count
Source
98
520
void write_literal(Writer& out, const char (&value)[N]) {
99
520
    out.write(value, N - 1);
100
520
}
variant_assembler_legacy_test.cpp:_ZN5doris12variant_json13write_literalINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterELm5EEEvRT_RAT0__Kc
Line
Count
Source
98
47
void write_literal(Writer& out, const char (&value)[N]) {
99
47
    out.write(value, N - 1);
100
47
}
variant_assembler_legacy_test.cpp:_ZN5doris12variant_json13write_literalINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterELm6EEEvRT_RAT0__Kc
Line
Count
Source
98
1
void write_literal(Writer& out, const char (&value)[N]) {
99
1
    out.write(value, N - 1);
100
1
}
Unexecuted instantiation: variant_assembler_legacy_test.cpp:_ZN5doris12variant_json13write_literalINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterELm11EEEvRT_RAT0__Kc
Unexecuted instantiation: variant_assembler_legacy_test.cpp:_ZN5doris12variant_json13write_literalINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterELm12EEEvRT_RAT0__Kc
variant_string_parse_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_112StringWriterELm2EEEvRT_RAT0__Kc
Line
Count
Source
98
575
void write_literal(Writer& out, const char (&value)[N]) {
99
575
    out.write(value, N - 1);
100
575
}
variant_string_parse_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_112StringWriterELm5EEEvRT_RAT0__Kc
Line
Count
Source
98
9
void write_literal(Writer& out, const char (&value)[N]) {
99
9
    out.write(value, N - 1);
100
9
}
variant_string_parse_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_112StringWriterELm6EEEvRT_RAT0__Kc
Line
Count
Source
98
3
void write_literal(Writer& out, const char (&value)[N]) {
99
3
    out.write(value, N - 1);
100
3
}
variant_string_parse_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_112StringWriterELm11EEEvRT_RAT0__Kc
Line
Count
Source
98
1
void write_literal(Writer& out, const char (&value)[N]) {
99
1
    out.write(value, N - 1);
100
1
}
variant_string_parse_test.cpp:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_112StringWriterELm12EEEvRT_RAT0__Kc
Line
Count
Source
98
1
void write_literal(Writer& out, const char (&value)[N]) {
99
1
    out.write(value, N - 1);
100
1
}
_ZN5doris12variant_json13write_literalINS_14BufferWritableELm2EEEvRT_RAT0__Kc
Line
Count
Source
98
70.9k
void write_literal(Writer& out, const char (&value)[N]) {
99
70.9k
    out.write(value, N - 1);
100
70.9k
}
_ZN5doris12variant_json13write_literalINS_14BufferWritableELm5EEEvRT_RAT0__Kc
Line
Count
Source
98
26
void write_literal(Writer& out, const char (&value)[N]) {
99
26
    out.write(value, N - 1);
100
26
}
_ZN5doris12variant_json13write_literalINS_14BufferWritableELm6EEEvRT_RAT0__Kc
Line
Count
Source
98
6
void write_literal(Writer& out, const char (&value)[N]) {
99
6
    out.write(value, N - 1);
100
6
}
_ZN5doris12variant_json13write_literalINS_14BufferWritableELm11EEEvRT_RAT0__Kc
Line
Count
Source
98
6
void write_literal(Writer& out, const char (&value)[N]) {
99
6
    out.write(value, N - 1);
100
6
}
_ZN5doris12variant_json13write_literalINS_14BufferWritableELm12EEEvRT_RAT0__Kc
Line
Count
Source
98
6
void write_literal(Writer& out, const char (&value)[N]) {
99
6
    out.write(value, N - 1);
100
6
}
unity_5_cxx.cxx:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_114CountingWriterELm2EEEvRT_RAT0__Kc
Line
Count
Source
98
70.9k
void write_literal(Writer& out, const char (&value)[N]) {
99
70.9k
    out.write(value, N - 1);
100
70.9k
}
unity_5_cxx.cxx:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_114CountingWriterELm5EEEvRT_RAT0__Kc
Line
Count
Source
98
31
void write_literal(Writer& out, const char (&value)[N]) {
99
31
    out.write(value, N - 1);
100
31
}
unity_5_cxx.cxx:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_114CountingWriterELm6EEEvRT_RAT0__Kc
Line
Count
Source
98
10
void write_literal(Writer& out, const char (&value)[N]) {
99
10
    out.write(value, N - 1);
100
10
}
unity_5_cxx.cxx:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_114CountingWriterELm11EEEvRT_RAT0__Kc
Line
Count
Source
98
10
void write_literal(Writer& out, const char (&value)[N]) {
99
10
    out.write(value, N - 1);
100
10
}
unity_5_cxx.cxx:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_114CountingWriterELm12EEEvRT_RAT0__Kc
Line
Count
Source
98
10
void write_literal(Writer& out, const char (&value)[N]) {
99
10
    out.write(value, N - 1);
100
10
}
unity_5_cxx.cxx:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_111FixedWriterELm2EEEvRT_RAT0__Kc
Line
Count
Source
98
115
void write_literal(Writer& out, const char (&value)[N]) {
99
115
    out.write(value, N - 1);
100
115
}
unity_5_cxx.cxx:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_111FixedWriterELm5EEEvRT_RAT0__Kc
Line
Count
Source
98
14
void write_literal(Writer& out, const char (&value)[N]) {
99
14
    out.write(value, N - 1);
100
14
}
unity_5_cxx.cxx:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_111FixedWriterELm6EEEvRT_RAT0__Kc
Line
Count
Source
98
8
void write_literal(Writer& out, const char (&value)[N]) {
99
8
    out.write(value, N - 1);
100
8
}
unity_5_cxx.cxx:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_111FixedWriterELm11EEEvRT_RAT0__Kc
Line
Count
Source
98
8
void write_literal(Writer& out, const char (&value)[N]) {
99
8
    out.write(value, N - 1);
100
8
}
unity_5_cxx.cxx:_ZN5doris12variant_json13write_literalINS_12_GLOBAL__N_111FixedWriterELm12EEEvRT_RAT0__Kc
Line
Count
Source
98
8
void write_literal(Writer& out, const char (&value)[N]) {
99
8
    out.write(value, N - 1);
100
8
}
101
102
template <typename Writer>
103
17.5k
void write_scalar(Writer& out, const FormattedScalar& value) {
104
17.5k
    out.write(value.bytes.data(), value.size);
105
17.5k
}
column_variant_v2_test.cpp:_ZN5doris12variant_json12write_scalarINS_12_GLOBAL__N_110JsonWriterEEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
103
119
void write_scalar(Writer& out, const FormattedScalar& value) {
104
119
    out.write(value.bytes.data(), value.size);
105
119
}
function_variant_parse_test.cpp:_ZN5doris12variant_json12write_scalarINS_12_GLOBAL__N_112StringWriterEEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
103
9
void write_scalar(Writer& out, const FormattedScalar& value) {
104
9
    out.write(value.bytes.data(), value.size);
105
9
}
_ZN5doris12variant_json12write_scalarI17VariantJsonWriterEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
103
1
void write_scalar(Writer& out, const FormattedScalar& value) {
104
1
    out.write(value.bytes.data(), value.size);
105
1
}
variant_assembler_legacy_test.cpp:_ZN5doris12variant_json12write_scalarINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
103
112
void write_scalar(Writer& out, const FormattedScalar& value) {
104
112
    out.write(value.bytes.data(), value.size);
105
112
}
variant_string_parse_test.cpp:_ZN5doris12variant_json12write_scalarINS_12_GLOBAL__N_112StringWriterEEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
103
41
void write_scalar(Writer& out, const FormattedScalar& value) {
104
41
    out.write(value.bytes.data(), value.size);
105
41
}
_ZN5doris12variant_json12write_scalarINS_14BufferWritableEEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
103
8.59k
void write_scalar(Writer& out, const FormattedScalar& value) {
104
8.59k
    out.write(value.bytes.data(), value.size);
105
8.59k
}
unity_5_cxx.cxx:_ZN5doris12variant_json12write_scalarINS_12_GLOBAL__N_114CountingWriterEEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
103
8.61k
void write_scalar(Writer& out, const FormattedScalar& value) {
104
8.61k
    out.write(value.bytes.data(), value.size);
105
8.61k
}
unity_5_cxx.cxx:_ZN5doris12variant_json12write_scalarINS_12_GLOBAL__N_111FixedWriterEEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
103
37
void write_scalar(Writer& out, const FormattedScalar& value) {
104
37
    out.write(value.bytes.data(), value.size);
105
37
}
106
107
template <typename Writer>
108
101
void write_quoted_scalar(Writer& out, const FormattedScalar& value) {
109
101
    write_literal(out, "\"");
110
101
    write_scalar(out, value);
111
101
    write_literal(out, "\"");
112
101
}
Unexecuted instantiation: column_variant_v2_test.cpp:_ZN5doris12variant_json19write_quoted_scalarINS_12_GLOBAL__N_110JsonWriterEEEvRT_RKNS0_15FormattedScalarE
Unexecuted instantiation: function_variant_parse_test.cpp:_ZN5doris12variant_json19write_quoted_scalarINS_12_GLOBAL__N_112StringWriterEEEvRT_RKNS0_15FormattedScalarE
Unexecuted instantiation: _ZN5doris12variant_json19write_quoted_scalarI17VariantJsonWriterEEvRT_RKNS0_15FormattedScalarE
variant_assembler_legacy_test.cpp:_ZN5doris12variant_json19write_quoted_scalarINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
108
50
void write_quoted_scalar(Writer& out, const FormattedScalar& value) {
109
50
    write_literal(out, "\"");
110
50
    write_scalar(out, value);
111
50
    write_literal(out, "\"");
112
50
}
variant_string_parse_test.cpp:_ZN5doris12variant_json19write_quoted_scalarINS_12_GLOBAL__N_112StringWriterEEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
108
13
void write_quoted_scalar(Writer& out, const FormattedScalar& value) {
109
13
    write_literal(out, "\"");
110
13
    write_scalar(out, value);
111
13
    write_literal(out, "\"");
112
13
}
_ZN5doris12variant_json19write_quoted_scalarINS_14BufferWritableEEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
108
6
void write_quoted_scalar(Writer& out, const FormattedScalar& value) {
109
6
    write_literal(out, "\"");
110
6
    write_scalar(out, value);
111
6
    write_literal(out, "\"");
112
6
}
unity_5_cxx.cxx:_ZN5doris12variant_json19write_quoted_scalarINS_12_GLOBAL__N_114CountingWriterEEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
108
18
void write_quoted_scalar(Writer& out, const FormattedScalar& value) {
109
18
    write_literal(out, "\"");
110
18
    write_scalar(out, value);
111
18
    write_literal(out, "\"");
112
18
}
unity_5_cxx.cxx:_ZN5doris12variant_json19write_quoted_scalarINS_12_GLOBAL__N_111FixedWriterEEEvRT_RKNS0_15FormattedScalarE
Line
Count
Source
108
14
void write_quoted_scalar(Writer& out, const FormattedScalar& value) {
109
14
    write_literal(out, "\"");
110
14
    write_scalar(out, value);
111
14
    write_literal(out, "\"");
112
14
}
113
114
template <typename Writer>
115
41.4k
void write_escaped_json_string(Writer& out, StringRef value) {
116
41.4k
    write_literal(out, "\"");
117
41.4k
    size_t plain_begin = 0;
118
41.4k
    size_t index = 0;
119
2.31M
    while (index < value.size) {
120
2.27M
        const auto byte = static_cast<uint8_t>(value.data[index]);
121
2.27M
        const char* escaped = nullptr;
122
2.27M
        size_t escaped_size = 0;
123
2.27M
        size_t consumed = 1;
124
2.27M
        switch (byte) {
125
57
        case '"':
126
57
            escaped = "\\\"";
127
57
            escaped_size = 2;
128
57
            break;
129
3
        case '\\':
130
3
            escaped = "\\\\";
131
3
            escaped_size = 2;
132
3
            break;
133
0
        case '\b':
134
0
            escaped = "\\b";
135
0
            escaped_size = 2;
136
0
            break;
137
0
        case '\f':
138
0
            escaped = "\\f";
139
0
            escaped_size = 2;
140
0
            break;
141
21
        case '\n':
142
21
            escaped = "\\n";
143
21
            escaped_size = 2;
144
21
            break;
145
0
        case '\r':
146
0
            escaped = "\\r";
147
0
            escaped_size = 2;
148
0
            break;
149
1
        case '\t':
150
1
            escaped = "\\t";
151
1
            escaped_size = 2;
152
1
            break;
153
2.27M
        default:
154
2.27M
            if (byte < 0x20) {
155
0
                static constexpr char HEX[] = "0123456789ABCDEF";
156
0
                char unicode_escape[] = {'\\', 'u', '0', '0', HEX[byte >> 4], HEX[byte & 0x0F]};
157
0
                if (index != plain_begin) {
158
0
                    out.write(value.data + plain_begin, index - plain_begin);
159
0
                }
160
0
                out.write(unicode_escape, sizeof(unicode_escape));
161
0
                ++index;
162
0
                plain_begin = index;
163
0
                continue;
164
0
            }
165
2.27M
            if (index + 2 < value.size && byte == 0xE2 &&
166
2.27M
                static_cast<uint8_t>(value.data[index + 1]) == 0x80 &&
167
2.27M
                (static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ||
168
1
                 static_cast<uint8_t>(value.data[index + 2]) == 0xA9)) {
169
1
                escaped =
170
1
                        static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ? "\\u2028" : "\\u2029";
171
1
                escaped_size = 6;
172
1
                consumed = 3;
173
1
            }
174
2.27M
            break;
175
2.27M
        }
176
2.27M
        if (escaped == nullptr) {
177
2.27M
            ++index;
178
2.27M
            continue;
179
2.27M
        }
180
83
        if (index != plain_begin) {
181
62
            out.write(value.data + plain_begin, index - plain_begin);
182
62
        }
183
83
        out.write(escaped, escaped_size);
184
83
        index += consumed;
185
83
        plain_begin = index;
186
83
    }
187
41.4k
    if (plain_begin != value.size) {
188
41.4k
        out.write(value.data + plain_begin, value.size - plain_begin);
189
41.4k
    }
190
41.4k
    write_literal(out, "\"");
191
41.4k
}
column_variant_v2_test.cpp:_ZN5doris12variant_json25write_escaped_json_stringINS_12_GLOBAL__N_110JsonWriterEEEvRT_NS_9StringRefE
Line
Count
Source
115
97
void write_escaped_json_string(Writer& out, StringRef value) {
116
97
    write_literal(out, "\"");
117
97
    size_t plain_begin = 0;
118
97
    size_t index = 0;
119
202
    while (index < value.size) {
120
105
        const auto byte = static_cast<uint8_t>(value.data[index]);
121
105
        const char* escaped = nullptr;
122
105
        size_t escaped_size = 0;
123
105
        size_t consumed = 1;
124
105
        switch (byte) {
125
0
        case '"':
126
0
            escaped = "\\\"";
127
0
            escaped_size = 2;
128
0
            break;
129
0
        case '\\':
130
0
            escaped = "\\\\";
131
0
            escaped_size = 2;
132
0
            break;
133
0
        case '\b':
134
0
            escaped = "\\b";
135
0
            escaped_size = 2;
136
0
            break;
137
0
        case '\f':
138
0
            escaped = "\\f";
139
0
            escaped_size = 2;
140
0
            break;
141
0
        case '\n':
142
0
            escaped = "\\n";
143
0
            escaped_size = 2;
144
0
            break;
145
0
        case '\r':
146
0
            escaped = "\\r";
147
0
            escaped_size = 2;
148
0
            break;
149
0
        case '\t':
150
0
            escaped = "\\t";
151
0
            escaped_size = 2;
152
0
            break;
153
105
        default:
154
105
            if (byte < 0x20) {
155
0
                static constexpr char HEX[] = "0123456789ABCDEF";
156
0
                char unicode_escape[] = {'\\', 'u', '0', '0', HEX[byte >> 4], HEX[byte & 0x0F]};
157
0
                if (index != plain_begin) {
158
0
                    out.write(value.data + plain_begin, index - plain_begin);
159
0
                }
160
0
                out.write(unicode_escape, sizeof(unicode_escape));
161
0
                ++index;
162
0
                plain_begin = index;
163
0
                continue;
164
0
            }
165
105
            if (index + 2 < value.size && byte == 0xE2 &&
166
105
                static_cast<uint8_t>(value.data[index + 1]) == 0x80 &&
167
105
                (static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ||
168
0
                 static_cast<uint8_t>(value.data[index + 2]) == 0xA9)) {
169
0
                escaped =
170
0
                        static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ? "\\u2028" : "\\u2029";
171
0
                escaped_size = 6;
172
0
                consumed = 3;
173
0
            }
174
105
            break;
175
105
        }
176
105
        if (escaped == nullptr) {
177
105
            ++index;
178
105
            continue;
179
105
        }
180
0
        if (index != plain_begin) {
181
0
            out.write(value.data + plain_begin, index - plain_begin);
182
0
        }
183
0
        out.write(escaped, escaped_size);
184
0
        index += consumed;
185
0
        plain_begin = index;
186
0
    }
187
97
    if (plain_begin != value.size) {
188
97
        out.write(value.data + plain_begin, value.size - plain_begin);
189
97
    }
190
97
    write_literal(out, "\"");
191
97
}
function_variant_parse_test.cpp:_ZN5doris12variant_json25write_escaped_json_stringINS_12_GLOBAL__N_112StringWriterEEEvRT_NS_9StringRefE
Line
Count
Source
115
6
void write_escaped_json_string(Writer& out, StringRef value) {
116
6
    write_literal(out, "\"");
117
6
    size_t plain_begin = 0;
118
6
    size_t index = 0;
119
16
    while (index < value.size) {
120
10
        const auto byte = static_cast<uint8_t>(value.data[index]);
121
10
        const char* escaped = nullptr;
122
10
        size_t escaped_size = 0;
123
10
        size_t consumed = 1;
124
10
        switch (byte) {
125
0
        case '"':
126
0
            escaped = "\\\"";
127
0
            escaped_size = 2;
128
0
            break;
129
0
        case '\\':
130
0
            escaped = "\\\\";
131
0
            escaped_size = 2;
132
0
            break;
133
0
        case '\b':
134
0
            escaped = "\\b";
135
0
            escaped_size = 2;
136
0
            break;
137
0
        case '\f':
138
0
            escaped = "\\f";
139
0
            escaped_size = 2;
140
0
            break;
141
0
        case '\n':
142
0
            escaped = "\\n";
143
0
            escaped_size = 2;
144
0
            break;
145
0
        case '\r':
146
0
            escaped = "\\r";
147
0
            escaped_size = 2;
148
0
            break;
149
0
        case '\t':
150
0
            escaped = "\\t";
151
0
            escaped_size = 2;
152
0
            break;
153
10
        default:
154
10
            if (byte < 0x20) {
155
0
                static constexpr char HEX[] = "0123456789ABCDEF";
156
0
                char unicode_escape[] = {'\\', 'u', '0', '0', HEX[byte >> 4], HEX[byte & 0x0F]};
157
0
                if (index != plain_begin) {
158
0
                    out.write(value.data + plain_begin, index - plain_begin);
159
0
                }
160
0
                out.write(unicode_escape, sizeof(unicode_escape));
161
0
                ++index;
162
0
                plain_begin = index;
163
0
                continue;
164
0
            }
165
10
            if (index + 2 < value.size && byte == 0xE2 &&
166
10
                static_cast<uint8_t>(value.data[index + 1]) == 0x80 &&
167
10
                (static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ||
168
0
                 static_cast<uint8_t>(value.data[index + 2]) == 0xA9)) {
169
0
                escaped =
170
0
                        static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ? "\\u2028" : "\\u2029";
171
0
                escaped_size = 6;
172
0
                consumed = 3;
173
0
            }
174
10
            break;
175
10
        }
176
10
        if (escaped == nullptr) {
177
10
            ++index;
178
10
            continue;
179
10
        }
180
0
        if (index != plain_begin) {
181
0
            out.write(value.data + plain_begin, index - plain_begin);
182
0
        }
183
0
        out.write(escaped, escaped_size);
184
0
        index += consumed;
185
0
        plain_begin = index;
186
0
    }
187
6
    if (plain_begin != value.size) {
188
6
        out.write(value.data + plain_begin, value.size - plain_begin);
189
6
    }
190
6
    write_literal(out, "\"");
191
6
}
_ZN5doris12variant_json25write_escaped_json_stringI17VariantJsonWriterEEvRT_NS_9StringRefE
Line
Count
Source
115
8
void write_escaped_json_string(Writer& out, StringRef value) {
116
8
    write_literal(out, "\"");
117
8
    size_t plain_begin = 0;
118
8
    size_t index = 0;
119
33
    while (index < value.size) {
120
25
        const auto byte = static_cast<uint8_t>(value.data[index]);
121
25
        const char* escaped = nullptr;
122
25
        size_t escaped_size = 0;
123
25
        size_t consumed = 1;
124
25
        switch (byte) {
125
0
        case '"':
126
0
            escaped = "\\\"";
127
0
            escaped_size = 2;
128
0
            break;
129
0
        case '\\':
130
0
            escaped = "\\\\";
131
0
            escaped_size = 2;
132
0
            break;
133
0
        case '\b':
134
0
            escaped = "\\b";
135
0
            escaped_size = 2;
136
0
            break;
137
0
        case '\f':
138
0
            escaped = "\\f";
139
0
            escaped_size = 2;
140
0
            break;
141
0
        case '\n':
142
0
            escaped = "\\n";
143
0
            escaped_size = 2;
144
0
            break;
145
0
        case '\r':
146
0
            escaped = "\\r";
147
0
            escaped_size = 2;
148
0
            break;
149
0
        case '\t':
150
0
            escaped = "\\t";
151
0
            escaped_size = 2;
152
0
            break;
153
25
        default:
154
25
            if (byte < 0x20) {
155
0
                static constexpr char HEX[] = "0123456789ABCDEF";
156
0
                char unicode_escape[] = {'\\', 'u', '0', '0', HEX[byte >> 4], HEX[byte & 0x0F]};
157
0
                if (index != plain_begin) {
158
0
                    out.write(value.data + plain_begin, index - plain_begin);
159
0
                }
160
0
                out.write(unicode_escape, sizeof(unicode_escape));
161
0
                ++index;
162
0
                plain_begin = index;
163
0
                continue;
164
0
            }
165
25
            if (index + 2 < value.size && byte == 0xE2 &&
166
25
                static_cast<uint8_t>(value.data[index + 1]) == 0x80 &&
167
25
                (static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ||
168
0
                 static_cast<uint8_t>(value.data[index + 2]) == 0xA9)) {
169
0
                escaped =
170
0
                        static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ? "\\u2028" : "\\u2029";
171
0
                escaped_size = 6;
172
0
                consumed = 3;
173
0
            }
174
25
            break;
175
25
        }
176
25
        if (escaped == nullptr) {
177
25
            ++index;
178
25
            continue;
179
25
        }
180
0
        if (index != plain_begin) {
181
0
            out.write(value.data + plain_begin, index - plain_begin);
182
0
        }
183
0
        out.write(escaped, escaped_size);
184
0
        index += consumed;
185
0
        plain_begin = index;
186
0
    }
187
8
    if (plain_begin != value.size) {
188
8
        out.write(value.data + plain_begin, value.size - plain_begin);
189
8
    }
190
8
    write_literal(out, "\"");
191
8
}
variant_assembler_legacy_test.cpp:_ZN5doris12variant_json25write_escaped_json_stringINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEEEvRT_NS_9StringRefE
Line
Count
Source
115
84
void write_escaped_json_string(Writer& out, StringRef value) {
116
84
    write_literal(out, "\"");
117
84
    size_t plain_begin = 0;
118
84
    size_t index = 0;
119
268
    while (index < value.size) {
120
184
        const auto byte = static_cast<uint8_t>(value.data[index]);
121
184
        const char* escaped = nullptr;
122
184
        size_t escaped_size = 0;
123
184
        size_t consumed = 1;
124
184
        switch (byte) {
125
0
        case '"':
126
0
            escaped = "\\\"";
127
0
            escaped_size = 2;
128
0
            break;
129
0
        case '\\':
130
0
            escaped = "\\\\";
131
0
            escaped_size = 2;
132
0
            break;
133
0
        case '\b':
134
0
            escaped = "\\b";
135
0
            escaped_size = 2;
136
0
            break;
137
0
        case '\f':
138
0
            escaped = "\\f";
139
0
            escaped_size = 2;
140
0
            break;
141
0
        case '\n':
142
0
            escaped = "\\n";
143
0
            escaped_size = 2;
144
0
            break;
145
0
        case '\r':
146
0
            escaped = "\\r";
147
0
            escaped_size = 2;
148
0
            break;
149
0
        case '\t':
150
0
            escaped = "\\t";
151
0
            escaped_size = 2;
152
0
            break;
153
184
        default:
154
184
            if (byte < 0x20) {
155
0
                static constexpr char HEX[] = "0123456789ABCDEF";
156
0
                char unicode_escape[] = {'\\', 'u', '0', '0', HEX[byte >> 4], HEX[byte & 0x0F]};
157
0
                if (index != plain_begin) {
158
0
                    out.write(value.data + plain_begin, index - plain_begin);
159
0
                }
160
0
                out.write(unicode_escape, sizeof(unicode_escape));
161
0
                ++index;
162
0
                plain_begin = index;
163
0
                continue;
164
0
            }
165
184
            if (index + 2 < value.size && byte == 0xE2 &&
166
184
                static_cast<uint8_t>(value.data[index + 1]) == 0x80 &&
167
184
                (static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ||
168
0
                 static_cast<uint8_t>(value.data[index + 2]) == 0xA9)) {
169
0
                escaped =
170
0
                        static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ? "\\u2028" : "\\u2029";
171
0
                escaped_size = 6;
172
0
                consumed = 3;
173
0
            }
174
184
            break;
175
184
        }
176
184
        if (escaped == nullptr) {
177
184
            ++index;
178
184
            continue;
179
184
        }
180
0
        if (index != plain_begin) {
181
0
            out.write(value.data + plain_begin, index - plain_begin);
182
0
        }
183
0
        out.write(escaped, escaped_size);
184
0
        index += consumed;
185
0
        plain_begin = index;
186
0
    }
187
84
    if (plain_begin != value.size) {
188
82
        out.write(value.data + plain_begin, value.size - plain_begin);
189
82
    }
190
84
    write_literal(out, "\"");
191
84
}
variant_string_parse_test.cpp:_ZN5doris12variant_json25write_escaped_json_stringINS_12_GLOBAL__N_112StringWriterEEEvRT_NS_9StringRefE
Line
Count
Source
115
32
void write_escaped_json_string(Writer& out, StringRef value) {
116
32
    write_literal(out, "\"");
117
32
    size_t plain_begin = 0;
118
32
    size_t index = 0;
119
154
    while (index < value.size) {
120
122
        const auto byte = static_cast<uint8_t>(value.data[index]);
121
122
        const char* escaped = nullptr;
122
122
        size_t escaped_size = 0;
123
122
        size_t consumed = 1;
124
122
        switch (byte) {
125
1
        case '"':
126
1
            escaped = "\\\"";
127
1
            escaped_size = 2;
128
1
            break;
129
1
        case '\\':
130
1
            escaped = "\\\\";
131
1
            escaped_size = 2;
132
1
            break;
133
0
        case '\b':
134
0
            escaped = "\\b";
135
0
            escaped_size = 2;
136
0
            break;
137
0
        case '\f':
138
0
            escaped = "\\f";
139
0
            escaped_size = 2;
140
0
            break;
141
1
        case '\n':
142
1
            escaped = "\\n";
143
1
            escaped_size = 2;
144
1
            break;
145
0
        case '\r':
146
0
            escaped = "\\r";
147
0
            escaped_size = 2;
148
0
            break;
149
1
        case '\t':
150
1
            escaped = "\\t";
151
1
            escaped_size = 2;
152
1
            break;
153
118
        default:
154
118
            if (byte < 0x20) {
155
0
                static constexpr char HEX[] = "0123456789ABCDEF";
156
0
                char unicode_escape[] = {'\\', 'u', '0', '0', HEX[byte >> 4], HEX[byte & 0x0F]};
157
0
                if (index != plain_begin) {
158
0
                    out.write(value.data + plain_begin, index - plain_begin);
159
0
                }
160
0
                out.write(unicode_escape, sizeof(unicode_escape));
161
0
                ++index;
162
0
                plain_begin = index;
163
0
                continue;
164
0
            }
165
118
            if (index + 2 < value.size && byte == 0xE2 &&
166
118
                static_cast<uint8_t>(value.data[index + 1]) == 0x80 &&
167
118
                (static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ||
168
1
                 static_cast<uint8_t>(value.data[index + 2]) == 0xA9)) {
169
1
                escaped =
170
1
                        static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ? "\\u2028" : "\\u2029";
171
1
                escaped_size = 6;
172
1
                consumed = 3;
173
1
            }
174
118
            break;
175
122
        }
176
122
        if (escaped == nullptr) {
177
117
            ++index;
178
117
            continue;
179
117
        }
180
5
        if (index != plain_begin) {
181
2
            out.write(value.data + plain_begin, index - plain_begin);
182
2
        }
183
5
        out.write(escaped, escaped_size);
184
5
        index += consumed;
185
5
        plain_begin = index;
186
5
    }
187
32
    if (plain_begin != value.size) {
188
31
        out.write(value.data + plain_begin, value.size - plain_begin);
189
31
    }
190
32
    write_literal(out, "\"");
191
32
}
_ZN5doris12variant_json25write_escaped_json_stringINS_14BufferWritableEEEvRT_NS_9StringRefE
Line
Count
Source
115
20.5k
void write_escaped_json_string(Writer& out, StringRef value) {
116
20.5k
    write_literal(out, "\"");
117
20.5k
    size_t plain_begin = 0;
118
20.5k
    size_t index = 0;
119
1.15M
    while (index < value.size) {
120
1.13M
        const auto byte = static_cast<uint8_t>(value.data[index]);
121
1.13M
        const char* escaped = nullptr;
122
1.13M
        size_t escaped_size = 0;
123
1.13M
        size_t consumed = 1;
124
1.13M
        switch (byte) {
125
11
        case '"':
126
11
            escaped = "\\\"";
127
11
            escaped_size = 2;
128
11
            break;
129
1
        case '\\':
130
1
            escaped = "\\\\";
131
1
            escaped_size = 2;
132
1
            break;
133
0
        case '\b':
134
0
            escaped = "\\b";
135
0
            escaped_size = 2;
136
0
            break;
137
0
        case '\f':
138
0
            escaped = "\\f";
139
0
            escaped_size = 2;
140
0
            break;
141
5
        case '\n':
142
5
            escaped = "\\n";
143
5
            escaped_size = 2;
144
5
            break;
145
0
        case '\r':
146
0
            escaped = "\\r";
147
0
            escaped_size = 2;
148
0
            break;
149
0
        case '\t':
150
0
            escaped = "\\t";
151
0
            escaped_size = 2;
152
0
            break;
153
1.13M
        default:
154
1.13M
            if (byte < 0x20) {
155
0
                static constexpr char HEX[] = "0123456789ABCDEF";
156
0
                char unicode_escape[] = {'\\', 'u', '0', '0', HEX[byte >> 4], HEX[byte & 0x0F]};
157
0
                if (index != plain_begin) {
158
0
                    out.write(value.data + plain_begin, index - plain_begin);
159
0
                }
160
0
                out.write(unicode_escape, sizeof(unicode_escape));
161
0
                ++index;
162
0
                plain_begin = index;
163
0
                continue;
164
0
            }
165
1.13M
            if (index + 2 < value.size && byte == 0xE2 &&
166
1.13M
                static_cast<uint8_t>(value.data[index + 1]) == 0x80 &&
167
1.13M
                (static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ||
168
0
                 static_cast<uint8_t>(value.data[index + 2]) == 0xA9)) {
169
0
                escaped =
170
0
                        static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ? "\\u2028" : "\\u2029";
171
0
                escaped_size = 6;
172
0
                consumed = 3;
173
0
            }
174
1.13M
            break;
175
1.13M
        }
176
1.13M
        if (escaped == nullptr) {
177
1.13M
            ++index;
178
1.13M
            continue;
179
1.13M
        }
180
17
        if (index != plain_begin) {
181
13
            out.write(value.data + plain_begin, index - plain_begin);
182
13
        }
183
17
        out.write(escaped, escaped_size);
184
17
        index += consumed;
185
17
        plain_begin = index;
186
17
    }
187
20.5k
    if (plain_begin != value.size) {
188
20.5k
        out.write(value.data + plain_begin, value.size - plain_begin);
189
20.5k
    }
190
20.5k
    write_literal(out, "\"");
191
20.5k
}
unity_5_cxx.cxx:_ZN5doris12variant_json25write_escaped_json_stringINS_12_GLOBAL__N_114CountingWriterEEEvRT_NS_9StringRefE
Line
Count
Source
115
20.6k
void write_escaped_json_string(Writer& out, StringRef value) {
116
20.6k
    write_literal(out, "\"");
117
20.6k
    size_t plain_begin = 0;
118
20.6k
    size_t index = 0;
119
1.15M
    while (index < value.size) {
120
1.13M
        const auto byte = static_cast<uint8_t>(value.data[index]);
121
1.13M
        const char* escaped = nullptr;
122
1.13M
        size_t escaped_size = 0;
123
1.13M
        size_t consumed = 1;
124
1.13M
        switch (byte) {
125
27
        case '"':
126
27
            escaped = "\\\"";
127
27
            escaped_size = 2;
128
27
            break;
129
1
        case '\\':
130
1
            escaped = "\\\\";
131
1
            escaped_size = 2;
132
1
            break;
133
0
        case '\b':
134
0
            escaped = "\\b";
135
0
            escaped_size = 2;
136
0
            break;
137
0
        case '\f':
138
0
            escaped = "\\f";
139
0
            escaped_size = 2;
140
0
            break;
141
9
        case '\n':
142
9
            escaped = "\\n";
143
9
            escaped_size = 2;
144
9
            break;
145
0
        case '\r':
146
0
            escaped = "\\r";
147
0
            escaped_size = 2;
148
0
            break;
149
0
        case '\t':
150
0
            escaped = "\\t";
151
0
            escaped_size = 2;
152
0
            break;
153
1.13M
        default:
154
1.13M
            if (byte < 0x20) {
155
0
                static constexpr char HEX[] = "0123456789ABCDEF";
156
0
                char unicode_escape[] = {'\\', 'u', '0', '0', HEX[byte >> 4], HEX[byte & 0x0F]};
157
0
                if (index != plain_begin) {
158
0
                    out.write(value.data + plain_begin, index - plain_begin);
159
0
                }
160
0
                out.write(unicode_escape, sizeof(unicode_escape));
161
0
                ++index;
162
0
                plain_begin = index;
163
0
                continue;
164
0
            }
165
1.13M
            if (index + 2 < value.size && byte == 0xE2 &&
166
1.13M
                static_cast<uint8_t>(value.data[index + 1]) == 0x80 &&
167
1.13M
                (static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ||
168
0
                 static_cast<uint8_t>(value.data[index + 2]) == 0xA9)) {
169
0
                escaped =
170
0
                        static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ? "\\u2028" : "\\u2029";
171
0
                escaped_size = 6;
172
0
                consumed = 3;
173
0
            }
174
1.13M
            break;
175
1.13M
        }
176
1.13M
        if (escaped == nullptr) {
177
1.13M
            ++index;
178
1.13M
            continue;
179
1.13M
        }
180
37
        if (index != plain_begin) {
181
29
            out.write(value.data + plain_begin, index - plain_begin);
182
29
        }
183
37
        out.write(escaped, escaped_size);
184
37
        index += consumed;
185
37
        plain_begin = index;
186
37
    }
187
20.6k
    if (plain_begin != value.size) {
188
20.5k
        out.write(value.data + plain_begin, value.size - plain_begin);
189
20.5k
    }
190
20.6k
    write_literal(out, "\"");
191
20.6k
}
unity_5_cxx.cxx:_ZN5doris12variant_json25write_escaped_json_stringINS_12_GLOBAL__N_111FixedWriterEEEvRT_NS_9StringRefE
Line
Count
Source
115
30
void write_escaped_json_string(Writer& out, StringRef value) {
116
30
    write_literal(out, "\"");
117
30
    size_t plain_begin = 0;
118
30
    size_t index = 0;
119
144
    while (index < value.size) {
120
114
        const auto byte = static_cast<uint8_t>(value.data[index]);
121
114
        const char* escaped = nullptr;
122
114
        size_t escaped_size = 0;
123
114
        size_t consumed = 1;
124
114
        switch (byte) {
125
18
        case '"':
126
18
            escaped = "\\\"";
127
18
            escaped_size = 2;
128
18
            break;
129
0
        case '\\':
130
0
            escaped = "\\\\";
131
0
            escaped_size = 2;
132
0
            break;
133
0
        case '\b':
134
0
            escaped = "\\b";
135
0
            escaped_size = 2;
136
0
            break;
137
0
        case '\f':
138
0
            escaped = "\\f";
139
0
            escaped_size = 2;
140
0
            break;
141
6
        case '\n':
142
6
            escaped = "\\n";
143
6
            escaped_size = 2;
144
6
            break;
145
0
        case '\r':
146
0
            escaped = "\\r";
147
0
            escaped_size = 2;
148
0
            break;
149
0
        case '\t':
150
0
            escaped = "\\t";
151
0
            escaped_size = 2;
152
0
            break;
153
90
        default:
154
90
            if (byte < 0x20) {
155
0
                static constexpr char HEX[] = "0123456789ABCDEF";
156
0
                char unicode_escape[] = {'\\', 'u', '0', '0', HEX[byte >> 4], HEX[byte & 0x0F]};
157
0
                if (index != plain_begin) {
158
0
                    out.write(value.data + plain_begin, index - plain_begin);
159
0
                }
160
0
                out.write(unicode_escape, sizeof(unicode_escape));
161
0
                ++index;
162
0
                plain_begin = index;
163
0
                continue;
164
0
            }
165
90
            if (index + 2 < value.size && byte == 0xE2 &&
166
90
                static_cast<uint8_t>(value.data[index + 1]) == 0x80 &&
167
90
                (static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ||
168
0
                 static_cast<uint8_t>(value.data[index + 2]) == 0xA9)) {
169
0
                escaped =
170
0
                        static_cast<uint8_t>(value.data[index + 2]) == 0xA8 ? "\\u2028" : "\\u2029";
171
0
                escaped_size = 6;
172
0
                consumed = 3;
173
0
            }
174
90
            break;
175
114
        }
176
114
        if (escaped == nullptr) {
177
90
            ++index;
178
90
            continue;
179
90
        }
180
24
        if (index != plain_begin) {
181
18
            out.write(value.data + plain_begin, index - plain_begin);
182
18
        }
183
24
        out.write(escaped, escaped_size);
184
24
        index += consumed;
185
24
        plain_begin = index;
186
24
    }
187
30
    if (plain_begin != value.size) {
188
18
        out.write(value.data + plain_begin, value.size - plain_begin);
189
18
    }
190
30
    write_literal(out, "\"");
191
30
}
192
193
template <typename Writer>
194
14.6k
void write_json_string(Writer& out, StringRef value, const char* description) {
195
14.6k
    require_valid_json_utf8(value, description);
196
14.6k
    write_escaped_json_string(out, value);
197
14.6k
}
Unexecuted instantiation: column_variant_v2_test.cpp:_ZN5doris12variant_json17write_json_stringINS_12_GLOBAL__N_110JsonWriterEEEvRT_NS_9StringRefEPKc
function_variant_parse_test.cpp:_ZN5doris12variant_json17write_json_stringINS_12_GLOBAL__N_112StringWriterEEEvRT_NS_9StringRefEPKc
Line
Count
Source
194
1
void write_json_string(Writer& out, StringRef value, const char* description) {
195
1
    require_valid_json_utf8(value, description);
196
1
    write_escaped_json_string(out, value);
197
1
}
_ZN5doris12variant_json17write_json_stringI17VariantJsonWriterEEvRT_NS_9StringRefEPKc
Line
Count
Source
194
3
void write_json_string(Writer& out, StringRef value, const char* description) {
195
3
    require_valid_json_utf8(value, description);
196
3
    write_escaped_json_string(out, value);
197
3
}
variant_assembler_legacy_test.cpp:_ZN5doris12variant_json17write_json_stringINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEEEvRT_NS_9StringRefEPKc
Line
Count
Source
194
13
void write_json_string(Writer& out, StringRef value, const char* description) {
195
13
    require_valid_json_utf8(value, description);
196
13
    write_escaped_json_string(out, value);
197
13
}
variant_string_parse_test.cpp:_ZN5doris12variant_json17write_json_stringINS_12_GLOBAL__N_112StringWriterEEEvRT_NS_9StringRefEPKc
Line
Count
Source
194
7
void write_json_string(Writer& out, StringRef value, const char* description) {
195
7
    require_valid_json_utf8(value, description);
196
7
    write_escaped_json_string(out, value);
197
7
}
_ZN5doris12variant_json17write_json_stringINS_14BufferWritableEEEvRT_NS_9StringRefEPKc
Line
Count
Source
194
7.28k
void write_json_string(Writer& out, StringRef value, const char* description) {
195
7.28k
    require_valid_json_utf8(value, description);
196
7.28k
    write_escaped_json_string(out, value);
197
7.28k
}
unity_5_cxx.cxx:_ZN5doris12variant_json17write_json_stringINS_12_GLOBAL__N_114CountingWriterEEEvRT_NS_9StringRefEPKc
Line
Count
Source
194
7.30k
void write_json_string(Writer& out, StringRef value, const char* description) {
195
7.30k
    require_valid_json_utf8(value, description);
196
7.30k
    write_escaped_json_string(out, value);
197
7.30k
}
unity_5_cxx.cxx:_ZN5doris12variant_json17write_json_stringINS_12_GLOBAL__N_111FixedWriterEEEvRT_NS_9StringRefEPKc
Line
Count
Source
194
27
void write_json_string(Writer& out, StringRef value, const char* description) {
195
27
    require_valid_json_utf8(value, description);
196
27
    write_escaped_json_string(out, value);
197
27
}
198
199
template <typename Writer>
200
2
void write_json_binary(Writer& out, StringRef value) {
201
2
    static constexpr char BASE64[] =
202
2
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
203
2
    write_literal(out, "\"");
204
2
    std::array<char, 1024> encoded {};
205
2
    size_t encoded_size = 0;
206
2
    size_t index = 0;
207
2
    const auto flush = [&]() {
208
2
        if (encoded_size != 0) {
209
2
            out.write(encoded.data(), encoded_size);
210
2
            encoded_size = 0;
211
2
        }
212
2
    };
Unexecuted instantiation: column_variant_v2_test.cpp:_ZZN5doris12variant_json17write_json_binaryINS_12_GLOBAL__N_110JsonWriterEEEvRT_NS_9StringRefEENKUlvE_clEv
Unexecuted instantiation: function_variant_parse_test.cpp:_ZZN5doris12variant_json17write_json_binaryINS_12_GLOBAL__N_112StringWriterEEEvRT_NS_9StringRefEENKUlvE_clEv
Unexecuted instantiation: _ZZN5doris12variant_json17write_json_binaryI17VariantJsonWriterEEvRT_NS_9StringRefEENKUlvE_clEv
Unexecuted instantiation: variant_assembler_legacy_test.cpp:_ZZN5doris12variant_json17write_json_binaryINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEEEvRT_NS_9StringRefEENKUlvE_clEv
variant_string_parse_test.cpp:_ZZN5doris12variant_json17write_json_binaryINS_12_GLOBAL__N_112StringWriterEEEvRT_NS_9StringRefEENKUlvE_clEv
Line
Count
Source
207
1
    const auto flush = [&]() {
208
1
        if (encoded_size != 0) {
209
1
            out.write(encoded.data(), encoded_size);
210
1
            encoded_size = 0;
211
1
        }
212
1
    };
_ZZN5doris12variant_json17write_json_binaryINS_14BufferWritableEEEvRT_NS_9StringRefEENKUlvE_clEv
Line
Count
Source
207
1
    const auto flush = [&]() {
208
1
        if (encoded_size != 0) {
209
1
            out.write(encoded.data(), encoded_size);
210
1
            encoded_size = 0;
211
1
        }
212
1
    };
Unexecuted instantiation: unity_5_cxx.cxx:_ZZN5doris12variant_json17write_json_binaryINS_12_GLOBAL__N_114CountingWriterEEEvRT_NS_9StringRefEENKUlvE_clEv
Unexecuted instantiation: unity_5_cxx.cxx:_ZZN5doris12variant_json17write_json_binaryINS_12_GLOBAL__N_111FixedWriterEEEvRT_NS_9StringRefEENKUlvE_clEv
213
3
    while (index + 3 <= value.size) {
214
1
        if (encoded.size() - encoded_size < 4) {
215
0
            flush();
216
0
        }
217
1
        const auto first = static_cast<uint8_t>(value.data[index]);
218
1
        const auto second = static_cast<uint8_t>(value.data[index + 1]);
219
1
        const auto third = static_cast<uint8_t>(value.data[index + 2]);
220
1
        encoded[encoded_size++] = BASE64[first >> 2];
221
1
        encoded[encoded_size++] = BASE64[((first & 0x03) << 4) | (second >> 4)];
222
1
        encoded[encoded_size++] = BASE64[((second & 0x0F) << 2) | (third >> 6)];
223
1
        encoded[encoded_size++] = BASE64[third & 0x3F];
224
1
        index += 3;
225
1
    }
226
2
    if (index != value.size) {
227
2
        if (encoded.size() - encoded_size < 4) {
228
0
            flush();
229
0
        }
230
2
        const auto first = static_cast<uint8_t>(value.data[index]);
231
2
        encoded[encoded_size++] = BASE64[first >> 2];
232
2
        if (index + 1 == value.size) {
233
1
            encoded[encoded_size++] = BASE64[(first & 0x03) << 4];
234
1
            encoded[encoded_size++] = '=';
235
1
            encoded[encoded_size++] = '=';
236
1
        } else {
237
1
            const auto second = static_cast<uint8_t>(value.data[index + 1]);
238
1
            encoded[encoded_size++] = BASE64[((first & 0x03) << 4) | (second >> 4)];
239
1
            encoded[encoded_size++] = BASE64[(second & 0x0F) << 2];
240
1
            encoded[encoded_size++] = '=';
241
1
        }
242
2
    }
243
2
    flush();
244
2
    write_literal(out, "\"");
245
2
}
Unexecuted instantiation: column_variant_v2_test.cpp:_ZN5doris12variant_json17write_json_binaryINS_12_GLOBAL__N_110JsonWriterEEEvRT_NS_9StringRefE
Unexecuted instantiation: function_variant_parse_test.cpp:_ZN5doris12variant_json17write_json_binaryINS_12_GLOBAL__N_112StringWriterEEEvRT_NS_9StringRefE
Unexecuted instantiation: _ZN5doris12variant_json17write_json_binaryI17VariantJsonWriterEEvRT_NS_9StringRefE
Unexecuted instantiation: variant_assembler_legacy_test.cpp:_ZN5doris12variant_json17write_json_binaryINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEEEvRT_NS_9StringRefE
variant_string_parse_test.cpp:_ZN5doris12variant_json17write_json_binaryINS_12_GLOBAL__N_112StringWriterEEEvRT_NS_9StringRefE
Line
Count
Source
200
1
void write_json_binary(Writer& out, StringRef value) {
201
1
    static constexpr char BASE64[] =
202
1
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
203
1
    write_literal(out, "\"");
204
1
    std::array<char, 1024> encoded {};
205
1
    size_t encoded_size = 0;
206
1
    size_t index = 0;
207
1
    const auto flush = [&]() {
208
1
        if (encoded_size != 0) {
209
1
            out.write(encoded.data(), encoded_size);
210
1
            encoded_size = 0;
211
1
        }
212
1
    };
213
2
    while (index + 3 <= value.size) {
214
1
        if (encoded.size() - encoded_size < 4) {
215
0
            flush();
216
0
        }
217
1
        const auto first = static_cast<uint8_t>(value.data[index]);
218
1
        const auto second = static_cast<uint8_t>(value.data[index + 1]);
219
1
        const auto third = static_cast<uint8_t>(value.data[index + 2]);
220
1
        encoded[encoded_size++] = BASE64[first >> 2];
221
1
        encoded[encoded_size++] = BASE64[((first & 0x03) << 4) | (second >> 4)];
222
1
        encoded[encoded_size++] = BASE64[((second & 0x0F) << 2) | (third >> 6)];
223
1
        encoded[encoded_size++] = BASE64[third & 0x3F];
224
1
        index += 3;
225
1
    }
226
1
    if (index != value.size) {
227
1
        if (encoded.size() - encoded_size < 4) {
228
0
            flush();
229
0
        }
230
1
        const auto first = static_cast<uint8_t>(value.data[index]);
231
1
        encoded[encoded_size++] = BASE64[first >> 2];
232
1
        if (index + 1 == value.size) {
233
1
            encoded[encoded_size++] = BASE64[(first & 0x03) << 4];
234
1
            encoded[encoded_size++] = '=';
235
1
            encoded[encoded_size++] = '=';
236
1
        } else {
237
0
            const auto second = static_cast<uint8_t>(value.data[index + 1]);
238
0
            encoded[encoded_size++] = BASE64[((first & 0x03) << 4) | (second >> 4)];
239
0
            encoded[encoded_size++] = BASE64[(second & 0x0F) << 2];
240
0
            encoded[encoded_size++] = '=';
241
0
        }
242
1
    }
243
1
    flush();
244
1
    write_literal(out, "\"");
245
1
}
_ZN5doris12variant_json17write_json_binaryINS_14BufferWritableEEEvRT_NS_9StringRefE
Line
Count
Source
200
1
void write_json_binary(Writer& out, StringRef value) {
201
1
    static constexpr char BASE64[] =
202
1
            "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
203
1
    write_literal(out, "\"");
204
1
    std::array<char, 1024> encoded {};
205
1
    size_t encoded_size = 0;
206
1
    size_t index = 0;
207
1
    const auto flush = [&]() {
208
1
        if (encoded_size != 0) {
209
1
            out.write(encoded.data(), encoded_size);
210
1
            encoded_size = 0;
211
1
        }
212
1
    };
213
1
    while (index + 3 <= value.size) {
214
0
        if (encoded.size() - encoded_size < 4) {
215
0
            flush();
216
0
        }
217
0
        const auto first = static_cast<uint8_t>(value.data[index]);
218
0
        const auto second = static_cast<uint8_t>(value.data[index + 1]);
219
0
        const auto third = static_cast<uint8_t>(value.data[index + 2]);
220
0
        encoded[encoded_size++] = BASE64[first >> 2];
221
0
        encoded[encoded_size++] = BASE64[((first & 0x03) << 4) | (second >> 4)];
222
0
        encoded[encoded_size++] = BASE64[((second & 0x0F) << 2) | (third >> 6)];
223
0
        encoded[encoded_size++] = BASE64[third & 0x3F];
224
0
        index += 3;
225
0
    }
226
1
    if (index != value.size) {
227
1
        if (encoded.size() - encoded_size < 4) {
228
0
            flush();
229
0
        }
230
1
        const auto first = static_cast<uint8_t>(value.data[index]);
231
1
        encoded[encoded_size++] = BASE64[first >> 2];
232
1
        if (index + 1 == value.size) {
233
0
            encoded[encoded_size++] = BASE64[(first & 0x03) << 4];
234
0
            encoded[encoded_size++] = '=';
235
0
            encoded[encoded_size++] = '=';
236
1
        } else {
237
1
            const auto second = static_cast<uint8_t>(value.data[index + 1]);
238
1
            encoded[encoded_size++] = BASE64[((first & 0x03) << 4) | (second >> 4)];
239
1
            encoded[encoded_size++] = BASE64[(second & 0x0F) << 2];
240
1
            encoded[encoded_size++] = '=';
241
1
        }
242
1
    }
243
1
    flush();
244
1
    write_literal(out, "\"");
245
1
}
Unexecuted instantiation: unity_5_cxx.cxx:_ZN5doris12variant_json17write_json_binaryINS_12_GLOBAL__N_114CountingWriterEEEvRT_NS_9StringRefE
Unexecuted instantiation: unity_5_cxx.cxx:_ZN5doris12variant_json17write_json_binaryINS_12_GLOBAL__N_111FixedWriterEEEvRT_NS_9StringRefE
246
247
template <typename Writer>
248
class Printer {
249
public:
250
11.7k
    Printer(Writer& out, const VariantJsonFormatOptions& options) : _out(out), _options(options) {}
column_variant_v2_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_110JsonWriterEEC2ERS3_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
250
141
    Printer(Writer& out, const VariantJsonFormatOptions& options) : _out(out), _options(options) {}
function_variant_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEEC2ERS3_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
250
13
    Printer(Writer& out, const VariantJsonFormatOptions& options) : _out(out), _options(options) {}
_ZN5doris12variant_json7PrinterI17VariantJsonWriterEC2ERS2_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
250
10
    Printer(Writer& out, const VariantJsonFormatOptions& options) : _out(out), _options(options) {}
variant_assembler_legacy_test.cpp:_ZN5doris12variant_json7PrinterINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEEC2ERS5_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
250
150
    Printer(Writer& out, const VariantJsonFormatOptions& options) : _out(out), _options(options) {}
variant_string_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEEC2ERS3_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
250
47
    Printer(Writer& out, const VariantJsonFormatOptions& options) : _out(out), _options(options) {}
_ZN5doris12variant_json7PrinterINS_14BufferWritableEEC2ERS2_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
250
5.61k
    Printer(Writer& out, const VariantJsonFormatOptions& options) : _out(out), _options(options) {}
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_114CountingWriterEEC2ERS3_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
250
5.65k
    Printer(Writer& out, const VariantJsonFormatOptions& options) : _out(out), _options(options) {}
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_111FixedWriterEEC2ERS3_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
250
106
    Printer(Writer& out, const VariantJsonFormatOptions& options) : _out(out), _options(options) {}
251
252
38.9k
    void write(VariantRef value, uint32_t depth) {
253
38.9k
        require_json_depth(depth);
254
38.9k
        switch (value.basic_type()) {
255
14.6k
        case VariantBasicType::SHORT_STRING:
256
14.6k
            write_json_string(_out, value.get_string(), "string");
257
14.6k
            return;
258
17.6k
        case VariantBasicType::PRIMITIVE:
259
17.6k
            write_primitive(value);
260
17.6k
            return;
261
6.21k
        case VariantBasicType::OBJECT:
262
6.21k
            write_object(value, depth);
263
6.21k
            return;
264
383
        case VariantBasicType::ARRAY:
265
383
            write_array(value, depth);
266
383
            return;
267
38.9k
        }
268
38.9k
    }
column_variant_v2_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_110JsonWriterEE5writeENS_10VariantRefEj
Line
Count
Source
252
257
    void write(VariantRef value, uint32_t depth) {
253
257
        require_json_depth(depth);
254
257
        switch (value.basic_type()) {
255
0
        case VariantBasicType::SHORT_STRING:
256
0
            write_json_string(_out, value.get_string(), "string");
257
0
            return;
258
119
        case VariantBasicType::PRIMITIVE:
259
119
            write_primitive(value);
260
119
            return;
261
119
        case VariantBasicType::OBJECT:
262
119
            write_object(value, depth);
263
119
            return;
264
19
        case VariantBasicType::ARRAY:
265
19
            write_array(value, depth);
266
19
            return;
267
257
        }
268
257
    }
function_variant_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEE5writeENS_10VariantRefEj
Line
Count
Source
252
22
    void write(VariantRef value, uint32_t depth) {
253
22
        require_json_depth(depth);
254
22
        switch (value.basic_type()) {
255
1
        case VariantBasicType::SHORT_STRING:
256
1
            write_json_string(_out, value.get_string(), "string");
257
1
            return;
258
13
        case VariantBasicType::PRIMITIVE:
259
13
            write_primitive(value);
260
13
            return;
261
6
        case VariantBasicType::OBJECT:
262
6
            write_object(value, depth);
263
6
            return;
264
2
        case VariantBasicType::ARRAY:
265
2
            write_array(value, depth);
266
2
            return;
267
22
        }
268
22
    }
_ZN5doris12variant_json7PrinterI17VariantJsonWriterE5writeENS_10VariantRefEj
Line
Count
Source
252
15
    void write(VariantRef value, uint32_t depth) {
253
15
        require_json_depth(depth);
254
15
        switch (value.basic_type()) {
255
3
        case VariantBasicType::SHORT_STRING:
256
3
            write_json_string(_out, value.get_string(), "string");
257
3
            return;
258
7
        case VariantBasicType::PRIMITIVE:
259
7
            write_primitive(value);
260
7
            return;
261
5
        case VariantBasicType::OBJECT:
262
5
            write_object(value, depth);
263
5
            return;
264
0
        case VariantBasicType::ARRAY:
265
0
            write_array(value, depth);
266
0
            return;
267
15
        }
268
15
    }
variant_assembler_legacy_test.cpp:_ZN5doris12variant_json7PrinterINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEE5writeENS_10VariantRefEj
Line
Count
Source
252
249
    void write(VariantRef value, uint32_t depth) {
253
249
        require_json_depth(depth);
254
249
        switch (value.basic_type()) {
255
13
        case VariantBasicType::SHORT_STRING:
256
13
            write_json_string(_out, value.get_string(), "string");
257
13
            return;
258
160
        case VariantBasicType::PRIMITIVE:
259
160
            write_primitive(value);
260
160
            return;
261
56
        case VariantBasicType::OBJECT:
262
56
            write_object(value, depth);
263
56
            return;
264
20
        case VariantBasicType::ARRAY:
265
20
            write_array(value, depth);
266
20
            return;
267
249
        }
268
249
    }
variant_string_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEE5writeENS_10VariantRefEj
Line
Count
Source
252
348
    void write(VariantRef value, uint32_t depth) {
253
348
        require_json_depth(depth);
254
348
        switch (value.basic_type()) {
255
6
        case VariantBasicType::SHORT_STRING:
256
6
            write_json_string(_out, value.get_string(), "string");
257
6
            return;
258
57
        case VariantBasicType::PRIMITIVE:
259
57
            write_primitive(value);
260
57
            return;
261
21
        case VariantBasicType::OBJECT:
262
21
            write_object(value, depth);
263
21
            return;
264
263
        case VariantBasicType::ARRAY:
265
263
            write_array(value, depth);
266
263
            return;
267
348
        }
268
348
    }
_ZN5doris12variant_json7PrinterINS_14BufferWritableEE5writeENS_10VariantRefEj
Line
Count
Source
252
18.9k
    void write(VariantRef value, uint32_t depth) {
253
18.9k
        require_json_depth(depth);
254
18.9k
        switch (value.basic_type()) {
255
7.27k
        case VariantBasicType::SHORT_STRING:
256
7.27k
            write_json_string(_out, value.get_string(), "string");
257
7.27k
            return;
258
8.61k
        case VariantBasicType::PRIMITIVE:
259
8.61k
            write_primitive(value);
260
8.61k
            return;
261
3.00k
        case VariantBasicType::OBJECT:
262
3.00k
            write_object(value, depth);
263
3.00k
            return;
264
36
        case VariantBasicType::ARRAY:
265
36
            write_array(value, depth);
266
36
            return;
267
18.9k
        }
268
18.9k
    }
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_114CountingWriterEE5writeENS_10VariantRefEj
Line
Count
Source
252
18.9k
    void write(VariantRef value, uint32_t depth) {
253
18.9k
        require_json_depth(depth);
254
18.9k
        switch (value.basic_type()) {
255
7.29k
        case VariantBasicType::SHORT_STRING:
256
7.29k
            write_json_string(_out, value.get_string(), "string");
257
7.29k
            return;
258
8.65k
        case VariantBasicType::PRIMITIVE:
259
8.65k
            write_primitive(value);
260
8.65k
            return;
261
3.00k
        case VariantBasicType::OBJECT:
262
3.00k
            write_object(value, depth);
263
3.00k
            return;
264
37
        case VariantBasicType::ARRAY:
265
37
            write_array(value, depth);
266
37
            return;
267
18.9k
        }
268
18.9k
    }
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_111FixedWriterEE5writeENS_10VariantRefEj
Line
Count
Source
252
94
    void write(VariantRef value, uint32_t depth) {
253
94
        require_json_depth(depth);
254
94
        switch (value.basic_type()) {
255
27
        case VariantBasicType::SHORT_STRING:
256
27
            write_json_string(_out, value.get_string(), "string");
257
27
            return;
258
58
        case VariantBasicType::PRIMITIVE:
259
58
            write_primitive(value);
260
58
            return;
261
3
        case VariantBasicType::OBJECT:
262
3
            write_object(value, depth);
263
3
            return;
264
6
        case VariantBasicType::ARRAY:
265
6
            write_array(value, depth);
266
6
            return;
267
94
        }
268
94
    }
269
270
103
    void write_plain_scalar(VariantRef value) {
271
103
        require_json_depth(0);
272
103
        if (value.basic_type() == VariantBasicType::SHORT_STRING) {
273
27
            const StringRef string = value.get_string();
274
27
            require_valid_json_utf8(string, "string");
275
27
            _out.write(string.data, string.size);
276
27
            return;
277
27
        }
278
76
        if (value.basic_type() != VariantBasicType::PRIMITIVE) {
279
8
            write(value, 0);
280
8
            return;
281
8
        }
282
283
68
        switch (value.primitive_id()) {
284
0
        case VariantPrimitiveId::STRING: {
285
0
            const StringRef string = value.get_string();
286
0
            require_valid_json_utf8(string, "string");
287
0
            _out.write(string.data, string.size);
288
0
            return;
289
0
        }
290
8
        case VariantPrimitiveId::DATE:
291
8
            write_scalar(_out, format_json_date(value.get_date()));
292
8
            return;
293
0
        case VariantPrimitiveId::TIMESTAMP_MICROS:
294
0
            write_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
295
0
                                                     _options.timezone));
296
0
            return;
297
8
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
298
8
            write_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6, false,
299
8
                                                     nullptr));
300
8
            return;
301
0
        case VariantPrimitiveId::TIME_NTZ_MICROS:
302
0
            write_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
303
0
            return;
304
0
        case VariantPrimitiveId::TIMESTAMP_NANOS:
305
0
            write_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
306
0
                                                     _options.timezone));
307
0
            return;
308
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
309
0
            write_scalar(_out,
310
0
                         format_json_timestamp(value.get_timestamp_ntz_nanos(), 9, false, nullptr));
311
0
            return;
312
0
        case VariantPrimitiveId::UUID:
313
0
            write_scalar(_out, format_json_uuid(value.get_uuid()));
314
0
            return;
315
52
        default:
316
52
            write_primitive(value);
317
52
            return;
318
68
        }
319
68
    }
_ZN5doris12variant_json7PrinterINS_14BufferWritableEE18write_plain_scalarENS_10VariantRefE
Line
Count
Source
270
51
    void write_plain_scalar(VariantRef value) {
271
51
        require_json_depth(0);
272
51
        if (value.basic_type() == VariantBasicType::SHORT_STRING) {
273
13
            const StringRef string = value.get_string();
274
13
            require_valid_json_utf8(string, "string");
275
13
            _out.write(string.data, string.size);
276
13
            return;
277
13
        }
278
38
        if (value.basic_type() != VariantBasicType::PRIMITIVE) {
279
4
            write(value, 0);
280
4
            return;
281
4
        }
282
283
34
        switch (value.primitive_id()) {
284
0
        case VariantPrimitiveId::STRING: {
285
0
            const StringRef string = value.get_string();
286
0
            require_valid_json_utf8(string, "string");
287
0
            _out.write(string.data, string.size);
288
0
            return;
289
0
        }
290
4
        case VariantPrimitiveId::DATE:
291
4
            write_scalar(_out, format_json_date(value.get_date()));
292
4
            return;
293
0
        case VariantPrimitiveId::TIMESTAMP_MICROS:
294
0
            write_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
295
0
                                                     _options.timezone));
296
0
            return;
297
4
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
298
4
            write_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6, false,
299
4
                                                     nullptr));
300
4
            return;
301
0
        case VariantPrimitiveId::TIME_NTZ_MICROS:
302
0
            write_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
303
0
            return;
304
0
        case VariantPrimitiveId::TIMESTAMP_NANOS:
305
0
            write_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
306
0
                                                     _options.timezone));
307
0
            return;
308
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
309
0
            write_scalar(_out,
310
0
                         format_json_timestamp(value.get_timestamp_ntz_nanos(), 9, false, nullptr));
311
0
            return;
312
0
        case VariantPrimitiveId::UUID:
313
0
            write_scalar(_out, format_json_uuid(value.get_uuid()));
314
0
            return;
315
26
        default:
316
26
            write_primitive(value);
317
26
            return;
318
34
        }
319
34
    }
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_114CountingWriterEE18write_plain_scalarENS_10VariantRefE
Line
Count
Source
270
26
    void write_plain_scalar(VariantRef value) {
271
26
        require_json_depth(0);
272
26
        if (value.basic_type() == VariantBasicType::SHORT_STRING) {
273
7
            const StringRef string = value.get_string();
274
7
            require_valid_json_utf8(string, "string");
275
7
            _out.write(string.data, string.size);
276
7
            return;
277
7
        }
278
19
        if (value.basic_type() != VariantBasicType::PRIMITIVE) {
279
2
            write(value, 0);
280
2
            return;
281
2
        }
282
283
17
        switch (value.primitive_id()) {
284
0
        case VariantPrimitiveId::STRING: {
285
0
            const StringRef string = value.get_string();
286
0
            require_valid_json_utf8(string, "string");
287
0
            _out.write(string.data, string.size);
288
0
            return;
289
0
        }
290
2
        case VariantPrimitiveId::DATE:
291
2
            write_scalar(_out, format_json_date(value.get_date()));
292
2
            return;
293
0
        case VariantPrimitiveId::TIMESTAMP_MICROS:
294
0
            write_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
295
0
                                                     _options.timezone));
296
0
            return;
297
2
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
298
2
            write_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6, false,
299
2
                                                     nullptr));
300
2
            return;
301
0
        case VariantPrimitiveId::TIME_NTZ_MICROS:
302
0
            write_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
303
0
            return;
304
0
        case VariantPrimitiveId::TIMESTAMP_NANOS:
305
0
            write_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
306
0
                                                     _options.timezone));
307
0
            return;
308
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
309
0
            write_scalar(_out,
310
0
                         format_json_timestamp(value.get_timestamp_ntz_nanos(), 9, false, nullptr));
311
0
            return;
312
0
        case VariantPrimitiveId::UUID:
313
0
            write_scalar(_out, format_json_uuid(value.get_uuid()));
314
0
            return;
315
13
        default:
316
13
            write_primitive(value);
317
13
            return;
318
17
        }
319
17
    }
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_111FixedWriterEE18write_plain_scalarENS_10VariantRefE
Line
Count
Source
270
26
    void write_plain_scalar(VariantRef value) {
271
26
        require_json_depth(0);
272
26
        if (value.basic_type() == VariantBasicType::SHORT_STRING) {
273
7
            const StringRef string = value.get_string();
274
7
            require_valid_json_utf8(string, "string");
275
7
            _out.write(string.data, string.size);
276
7
            return;
277
7
        }
278
19
        if (value.basic_type() != VariantBasicType::PRIMITIVE) {
279
2
            write(value, 0);
280
2
            return;
281
2
        }
282
283
17
        switch (value.primitive_id()) {
284
0
        case VariantPrimitiveId::STRING: {
285
0
            const StringRef string = value.get_string();
286
0
            require_valid_json_utf8(string, "string");
287
0
            _out.write(string.data, string.size);
288
0
            return;
289
0
        }
290
2
        case VariantPrimitiveId::DATE:
291
2
            write_scalar(_out, format_json_date(value.get_date()));
292
2
            return;
293
0
        case VariantPrimitiveId::TIMESTAMP_MICROS:
294
0
            write_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
295
0
                                                     _options.timezone));
296
0
            return;
297
2
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
298
2
            write_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6, false,
299
2
                                                     nullptr));
300
2
            return;
301
0
        case VariantPrimitiveId::TIME_NTZ_MICROS:
302
0
            write_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
303
0
            return;
304
0
        case VariantPrimitiveId::TIMESTAMP_NANOS:
305
0
            write_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
306
0
                                                     _options.timezone));
307
0
            return;
308
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
309
0
            write_scalar(_out,
310
0
                         format_json_timestamp(value.get_timestamp_ntz_nanos(), 9, false, nullptr));
311
0
            return;
312
0
        case VariantPrimitiveId::UUID:
313
0
            write_scalar(_out, format_json_uuid(value.get_uuid()));
314
0
            return;
315
13
        default:
316
13
            write_primitive(value);
317
13
            return;
318
17
        }
319
17
    }
320
321
private:
322
17.7k
    void write_primitive(VariantRef value) {
323
17.7k
        const VariantPrimitiveId id = value.primitive_id();
324
17.7k
        switch (id) {
325
121
        case VariantPrimitiveId::NULL_VALUE:
326
121
            write_literal(_out, "null");
327
121
            return;
328
16
        case VariantPrimitiveId::TRUE_VALUE:
329
16
            write_literal(_out, "true");
330
16
            return;
331
3
        case VariantPrimitiveId::FALSE_VALUE:
332
3
            write_literal(_out, "false");
333
3
            return;
334
16.8k
        case VariantPrimitiveId::INT8:
335
17.3k
        case VariantPrimitiveId::INT16:
336
17.3k
        case VariantPrimitiveId::INT32:
337
17.3k
        case VariantPrimitiveId::INT64:
338
17.3k
            write_scalar(_out, format_json_int(value.get_int()));
339
17.3k
            return;
340
124
        case VariantPrimitiveId::DOUBLE: {
341
124
            const double number = value.get_double();
342
124
            if (!std::isfinite(number)) {
343
73
                write_non_finite(number);
344
73
                return;
345
73
            }
346
51
            write_scalar(_out, format_json_double(number));
347
51
            return;
348
124
        }
349
3
        case VariantPrimitiveId::DECIMAL4:
350
13
        case VariantPrimitiveId::DECIMAL8:
351
25
        case VariantPrimitiveId::DECIMAL16:
352
25
            write_scalar(_out, format_json_decimal(value.get_decimal()));
353
25
            return;
354
61
        case VariantPrimitiveId::DATE:
355
61
            write_quoted_scalar(_out, format_json_date(value.get_date()));
356
61
            return;
357
5
        case VariantPrimitiveId::TIMESTAMP_MICROS:
358
5
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
359
5
                                                            _options.timezone));
360
5
            return;
361
26
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
362
26
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6,
363
26
                                                            false, nullptr));
364
26
            return;
365
6
        case VariantPrimitiveId::FLOAT: {
366
6
            const float number = value.get_float();
367
6
            if (!std::isfinite(number)) {
368
2
                write_non_finite(number);
369
2
                return;
370
2
            }
371
4
            write_scalar(_out, format_json_float(number));
372
4
            return;
373
6
        }
374
2
        case VariantPrimitiveId::BINARY:
375
2
            write_json_binary(_out, value.get_binary());
376
2
            return;
377
3
        case VariantPrimitiveId::STRING:
378
3
            write_json_string(_out, value.get_string(), "string");
379
3
            return;
380
2
        case VariantPrimitiveId::TIME_NTZ_MICROS:
381
2
            write_quoted_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
382
2
            return;
383
3
        case VariantPrimitiveId::TIMESTAMP_NANOS:
384
3
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
385
3
                                                            _options.timezone));
386
3
            return;
387
2
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
388
2
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_nanos(), 9,
389
2
                                                            false, nullptr));
390
2
            return;
391
2
        case VariantPrimitiveId::UUID:
392
2
            write_quoted_scalar(_out, format_json_uuid(value.get_uuid()));
393
2
            return;
394
17.7k
        }
395
0
        throw_unsupported_json_primitive(id);
396
0
    }
column_variant_v2_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_110JsonWriterEE15write_primitiveENS_10VariantRefE
Line
Count
Source
322
119
    void write_primitive(VariantRef value) {
323
119
        const VariantPrimitiveId id = value.primitive_id();
324
119
        switch (id) {
325
0
        case VariantPrimitiveId::NULL_VALUE:
326
0
            write_literal(_out, "null");
327
0
            return;
328
0
        case VariantPrimitiveId::TRUE_VALUE:
329
0
            write_literal(_out, "true");
330
0
            return;
331
0
        case VariantPrimitiveId::FALSE_VALUE:
332
0
            write_literal(_out, "false");
333
0
            return;
334
119
        case VariantPrimitiveId::INT8:
335
119
        case VariantPrimitiveId::INT16:
336
119
        case VariantPrimitiveId::INT32:
337
119
        case VariantPrimitiveId::INT64:
338
119
            write_scalar(_out, format_json_int(value.get_int()));
339
119
            return;
340
0
        case VariantPrimitiveId::DOUBLE: {
341
0
            const double number = value.get_double();
342
0
            if (!std::isfinite(number)) {
343
0
                write_non_finite(number);
344
0
                return;
345
0
            }
346
0
            write_scalar(_out, format_json_double(number));
347
0
            return;
348
0
        }
349
0
        case VariantPrimitiveId::DECIMAL4:
350
0
        case VariantPrimitiveId::DECIMAL8:
351
0
        case VariantPrimitiveId::DECIMAL16:
352
0
            write_scalar(_out, format_json_decimal(value.get_decimal()));
353
0
            return;
354
0
        case VariantPrimitiveId::DATE:
355
0
            write_quoted_scalar(_out, format_json_date(value.get_date()));
356
0
            return;
357
0
        case VariantPrimitiveId::TIMESTAMP_MICROS:
358
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
359
0
                                                            _options.timezone));
360
0
            return;
361
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
362
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6,
363
0
                                                            false, nullptr));
364
0
            return;
365
0
        case VariantPrimitiveId::FLOAT: {
366
0
            const float number = value.get_float();
367
0
            if (!std::isfinite(number)) {
368
0
                write_non_finite(number);
369
0
                return;
370
0
            }
371
0
            write_scalar(_out, format_json_float(number));
372
0
            return;
373
0
        }
374
0
        case VariantPrimitiveId::BINARY:
375
0
            write_json_binary(_out, value.get_binary());
376
0
            return;
377
0
        case VariantPrimitiveId::STRING:
378
0
            write_json_string(_out, value.get_string(), "string");
379
0
            return;
380
0
        case VariantPrimitiveId::TIME_NTZ_MICROS:
381
0
            write_quoted_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
382
0
            return;
383
0
        case VariantPrimitiveId::TIMESTAMP_NANOS:
384
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
385
0
                                                            _options.timezone));
386
0
            return;
387
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
388
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_nanos(), 9,
389
0
                                                            false, nullptr));
390
0
            return;
391
0
        case VariantPrimitiveId::UUID:
392
0
            write_quoted_scalar(_out, format_json_uuid(value.get_uuid()));
393
0
            return;
394
119
        }
395
0
        throw_unsupported_json_primitive(id);
396
0
    }
function_variant_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEE15write_primitiveENS_10VariantRefE
Line
Count
Source
322
13
    void write_primitive(VariantRef value) {
323
13
        const VariantPrimitiveId id = value.primitive_id();
324
13
        switch (id) {
325
3
        case VariantPrimitiveId::NULL_VALUE:
326
3
            write_literal(_out, "null");
327
3
            return;
328
1
        case VariantPrimitiveId::TRUE_VALUE:
329
1
            write_literal(_out, "true");
330
1
            return;
331
0
        case VariantPrimitiveId::FALSE_VALUE:
332
0
            write_literal(_out, "false");
333
0
            return;
334
9
        case VariantPrimitiveId::INT8:
335
9
        case VariantPrimitiveId::INT16:
336
9
        case VariantPrimitiveId::INT32:
337
9
        case VariantPrimitiveId::INT64:
338
9
            write_scalar(_out, format_json_int(value.get_int()));
339
9
            return;
340
0
        case VariantPrimitiveId::DOUBLE: {
341
0
            const double number = value.get_double();
342
0
            if (!std::isfinite(number)) {
343
0
                write_non_finite(number);
344
0
                return;
345
0
            }
346
0
            write_scalar(_out, format_json_double(number));
347
0
            return;
348
0
        }
349
0
        case VariantPrimitiveId::DECIMAL4:
350
0
        case VariantPrimitiveId::DECIMAL8:
351
0
        case VariantPrimitiveId::DECIMAL16:
352
0
            write_scalar(_out, format_json_decimal(value.get_decimal()));
353
0
            return;
354
0
        case VariantPrimitiveId::DATE:
355
0
            write_quoted_scalar(_out, format_json_date(value.get_date()));
356
0
            return;
357
0
        case VariantPrimitiveId::TIMESTAMP_MICROS:
358
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
359
0
                                                            _options.timezone));
360
0
            return;
361
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
362
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6,
363
0
                                                            false, nullptr));
364
0
            return;
365
0
        case VariantPrimitiveId::FLOAT: {
366
0
            const float number = value.get_float();
367
0
            if (!std::isfinite(number)) {
368
0
                write_non_finite(number);
369
0
                return;
370
0
            }
371
0
            write_scalar(_out, format_json_float(number));
372
0
            return;
373
0
        }
374
0
        case VariantPrimitiveId::BINARY:
375
0
            write_json_binary(_out, value.get_binary());
376
0
            return;
377
0
        case VariantPrimitiveId::STRING:
378
0
            write_json_string(_out, value.get_string(), "string");
379
0
            return;
380
0
        case VariantPrimitiveId::TIME_NTZ_MICROS:
381
0
            write_quoted_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
382
0
            return;
383
0
        case VariantPrimitiveId::TIMESTAMP_NANOS:
384
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
385
0
                                                            _options.timezone));
386
0
            return;
387
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
388
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_nanos(), 9,
389
0
                                                            false, nullptr));
390
0
            return;
391
0
        case VariantPrimitiveId::UUID:
392
0
            write_quoted_scalar(_out, format_json_uuid(value.get_uuid()));
393
0
            return;
394
13
        }
395
0
        throw_unsupported_json_primitive(id);
396
0
    }
_ZN5doris12variant_json7PrinterI17VariantJsonWriterE15write_primitiveENS_10VariantRefE
Line
Count
Source
322
7
    void write_primitive(VariantRef value) {
323
7
        const VariantPrimitiveId id = value.primitive_id();
324
7
        switch (id) {
325
6
        case VariantPrimitiveId::NULL_VALUE:
326
6
            write_literal(_out, "null");
327
6
            return;
328
0
        case VariantPrimitiveId::TRUE_VALUE:
329
0
            write_literal(_out, "true");
330
0
            return;
331
0
        case VariantPrimitiveId::FALSE_VALUE:
332
0
            write_literal(_out, "false");
333
0
            return;
334
1
        case VariantPrimitiveId::INT8:
335
1
        case VariantPrimitiveId::INT16:
336
1
        case VariantPrimitiveId::INT32:
337
1
        case VariantPrimitiveId::INT64:
338
1
            write_scalar(_out, format_json_int(value.get_int()));
339
1
            return;
340
0
        case VariantPrimitiveId::DOUBLE: {
341
0
            const double number = value.get_double();
342
0
            if (!std::isfinite(number)) {
343
0
                write_non_finite(number);
344
0
                return;
345
0
            }
346
0
            write_scalar(_out, format_json_double(number));
347
0
            return;
348
0
        }
349
0
        case VariantPrimitiveId::DECIMAL4:
350
0
        case VariantPrimitiveId::DECIMAL8:
351
0
        case VariantPrimitiveId::DECIMAL16:
352
0
            write_scalar(_out, format_json_decimal(value.get_decimal()));
353
0
            return;
354
0
        case VariantPrimitiveId::DATE:
355
0
            write_quoted_scalar(_out, format_json_date(value.get_date()));
356
0
            return;
357
0
        case VariantPrimitiveId::TIMESTAMP_MICROS:
358
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
359
0
                                                            _options.timezone));
360
0
            return;
361
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
362
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6,
363
0
                                                            false, nullptr));
364
0
            return;
365
0
        case VariantPrimitiveId::FLOAT: {
366
0
            const float number = value.get_float();
367
0
            if (!std::isfinite(number)) {
368
0
                write_non_finite(number);
369
0
                return;
370
0
            }
371
0
            write_scalar(_out, format_json_float(number));
372
0
            return;
373
0
        }
374
0
        case VariantPrimitiveId::BINARY:
375
0
            write_json_binary(_out, value.get_binary());
376
0
            return;
377
0
        case VariantPrimitiveId::STRING:
378
0
            write_json_string(_out, value.get_string(), "string");
379
0
            return;
380
0
        case VariantPrimitiveId::TIME_NTZ_MICROS:
381
0
            write_quoted_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
382
0
            return;
383
0
        case VariantPrimitiveId::TIMESTAMP_NANOS:
384
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
385
0
                                                            _options.timezone));
386
0
            return;
387
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
388
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_nanos(), 9,
389
0
                                                            false, nullptr));
390
0
            return;
391
0
        case VariantPrimitiveId::UUID:
392
0
            write_quoted_scalar(_out, format_json_uuid(value.get_uuid()));
393
0
            return;
394
7
        }
395
0
        throw_unsupported_json_primitive(id);
396
0
    }
variant_assembler_legacy_test.cpp:_ZN5doris12variant_json7PrinterINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEE15write_primitiveENS_10VariantRefE
Line
Count
Source
322
160
    void write_primitive(VariantRef value) {
323
160
        const VariantPrimitiveId id = value.primitive_id();
324
160
        switch (id) {
325
45
        case VariantPrimitiveId::NULL_VALUE:
326
45
            write_literal(_out, "null");
327
45
            return;
328
2
        case VariantPrimitiveId::TRUE_VALUE:
329
2
            write_literal(_out, "true");
330
2
            return;
331
1
        case VariantPrimitiveId::FALSE_VALUE:
332
1
            write_literal(_out, "false");
333
1
            return;
334
31
        case VariantPrimitiveId::INT8:
335
32
        case VariantPrimitiveId::INT16:
336
34
        case VariantPrimitiveId::INT32:
337
36
        case VariantPrimitiveId::INT64:
338
36
            write_scalar(_out, format_json_int(value.get_int()));
339
36
            return;
340
2
        case VariantPrimitiveId::DOUBLE: {
341
2
            const double number = value.get_double();
342
2
            if (!std::isfinite(number)) {
343
0
                write_non_finite(number);
344
0
                return;
345
0
            }
346
2
            write_scalar(_out, format_json_double(number));
347
2
            return;
348
2
        }
349
2
        case VariantPrimitiveId::DECIMAL4:
350
11
        case VariantPrimitiveId::DECIMAL8:
351
21
        case VariantPrimitiveId::DECIMAL16:
352
21
            write_scalar(_out, format_json_decimal(value.get_decimal()));
353
21
            return;
354
40
        case VariantPrimitiveId::DATE:
355
40
            write_quoted_scalar(_out, format_json_date(value.get_date()));
356
40
            return;
357
2
        case VariantPrimitiveId::TIMESTAMP_MICROS:
358
2
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
359
2
                                                            _options.timezone));
360
2
            return;
361
8
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
362
8
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6,
363
8
                                                            false, nullptr));
364
8
            return;
365
3
        case VariantPrimitiveId::FLOAT: {
366
3
            const float number = value.get_float();
367
3
            if (!std::isfinite(number)) {
368
0
                write_non_finite(number);
369
0
                return;
370
0
            }
371
3
            write_scalar(_out, format_json_float(number));
372
3
            return;
373
3
        }
374
0
        case VariantPrimitiveId::BINARY:
375
0
            write_json_binary(_out, value.get_binary());
376
0
            return;
377
0
        case VariantPrimitiveId::STRING:
378
0
            write_json_string(_out, value.get_string(), "string");
379
0
            return;
380
0
        case VariantPrimitiveId::TIME_NTZ_MICROS:
381
0
            write_quoted_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
382
0
            return;
383
0
        case VariantPrimitiveId::TIMESTAMP_NANOS:
384
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
385
0
                                                            _options.timezone));
386
0
            return;
387
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
388
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_nanos(), 9,
389
0
                                                            false, nullptr));
390
0
            return;
391
0
        case VariantPrimitiveId::UUID:
392
0
            write_quoted_scalar(_out, format_json_uuid(value.get_uuid()));
393
0
            return;
394
160
        }
395
0
        throw_unsupported_json_primitive(id);
396
0
    }
variant_string_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEE15write_primitiveENS_10VariantRefE
Line
Count
Source
322
57
    void write_primitive(VariantRef value) {
323
57
        const VariantPrimitiveId id = value.primitive_id();
324
57
        switch (id) {
325
5
        case VariantPrimitiveId::NULL_VALUE:
326
5
            write_literal(_out, "null");
327
5
            return;
328
4
        case VariantPrimitiveId::TRUE_VALUE:
329
4
            write_literal(_out, "true");
330
4
            return;
331
2
        case VariantPrimitiveId::FALSE_VALUE:
332
2
            write_literal(_out, "false");
333
2
            return;
334
19
        case VariantPrimitiveId::INT8:
335
20
        case VariantPrimitiveId::INT16:
336
21
        case VariantPrimitiveId::INT32:
337
22
        case VariantPrimitiveId::INT64:
338
22
            write_scalar(_out, format_json_int(value.get_int()));
339
22
            return;
340
2
        case VariantPrimitiveId::DOUBLE: {
341
2
            const double number = value.get_double();
342
2
            if (!std::isfinite(number)) {
343
1
                write_non_finite(number);
344
1
                return;
345
1
            }
346
1
            write_scalar(_out, format_json_double(number));
347
1
            return;
348
2
        }
349
1
        case VariantPrimitiveId::DECIMAL4:
350
2
        case VariantPrimitiveId::DECIMAL8:
351
4
        case VariantPrimitiveId::DECIMAL16:
352
4
            write_scalar(_out, format_json_decimal(value.get_decimal()));
353
4
            return;
354
1
        case VariantPrimitiveId::DATE:
355
1
            write_quoted_scalar(_out, format_json_date(value.get_date()));
356
1
            return;
357
3
        case VariantPrimitiveId::TIMESTAMP_MICROS:
358
3
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
359
3
                                                            _options.timezone));
360
3
            return;
361
2
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
362
2
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6,
363
2
                                                            false, nullptr));
364
2
            return;
365
3
        case VariantPrimitiveId::FLOAT: {
366
3
            const float number = value.get_float();
367
3
            if (!std::isfinite(number)) {
368
2
                write_non_finite(number);
369
2
                return;
370
2
            }
371
1
            write_scalar(_out, format_json_float(number));
372
1
            return;
373
3
        }
374
1
        case VariantPrimitiveId::BINARY:
375
1
            write_json_binary(_out, value.get_binary());
376
1
            return;
377
1
        case VariantPrimitiveId::STRING:
378
1
            write_json_string(_out, value.get_string(), "string");
379
1
            return;
380
1
        case VariantPrimitiveId::TIME_NTZ_MICROS:
381
1
            write_quoted_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
382
1
            return;
383
3
        case VariantPrimitiveId::TIMESTAMP_NANOS:
384
3
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
385
3
                                                            _options.timezone));
386
3
            return;
387
2
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
388
2
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_nanos(), 9,
389
2
                                                            false, nullptr));
390
2
            return;
391
1
        case VariantPrimitiveId::UUID:
392
1
            write_quoted_scalar(_out, format_json_uuid(value.get_uuid()));
393
1
            return;
394
57
        }
395
0
        throw_unsupported_json_primitive(id);
396
0
    }
_ZN5doris12variant_json7PrinterINS_14BufferWritableEE15write_primitiveENS_10VariantRefE
Line
Count
Source
322
8.63k
    void write_primitive(VariantRef value) {
323
8.63k
        const VariantPrimitiveId id = value.primitive_id();
324
8.63k
        switch (id) {
325
21
        case VariantPrimitiveId::NULL_VALUE:
326
21
            write_literal(_out, "null");
327
21
            return;
328
5
        case VariantPrimitiveId::TRUE_VALUE:
329
5
            write_literal(_out, "true");
330
5
            return;
331
0
        case VariantPrimitiveId::FALSE_VALUE:
332
0
            write_literal(_out, "false");
333
0
            return;
334
8.31k
        case VariantPrimitiveId::INT8:
335
8.57k
        case VariantPrimitiveId::INT16:
336
8.57k
        case VariantPrimitiveId::INT32:
337
8.57k
        case VariantPrimitiveId::INT64:
338
8.57k
            write_scalar(_out, format_json_int(value.get_int()));
339
8.57k
            return;
340
30
        case VariantPrimitiveId::DOUBLE: {
341
30
            const double number = value.get_double();
342
30
            if (!std::isfinite(number)) {
343
18
                write_non_finite(number);
344
18
                return;
345
18
            }
346
12
            write_scalar(_out, format_json_double(number));
347
12
            return;
348
30
        }
349
0
        case VariantPrimitiveId::DECIMAL4:
350
0
        case VariantPrimitiveId::DECIMAL8:
351
0
        case VariantPrimitiveId::DECIMAL16:
352
0
            write_scalar(_out, format_json_decimal(value.get_decimal()));
353
0
            return;
354
2
        case VariantPrimitiveId::DATE:
355
2
            write_quoted_scalar(_out, format_json_date(value.get_date()));
356
2
            return;
357
0
        case VariantPrimitiveId::TIMESTAMP_MICROS:
358
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
359
0
                                                            _options.timezone));
360
0
            return;
361
2
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
362
2
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6,
363
2
                                                            false, nullptr));
364
2
            return;
365
0
        case VariantPrimitiveId::FLOAT: {
366
0
            const float number = value.get_float();
367
0
            if (!std::isfinite(number)) {
368
0
                write_non_finite(number);
369
0
                return;
370
0
            }
371
0
            write_scalar(_out, format_json_float(number));
372
0
            return;
373
0
        }
374
1
        case VariantPrimitiveId::BINARY:
375
1
            write_json_binary(_out, value.get_binary());
376
1
            return;
377
1
        case VariantPrimitiveId::STRING:
378
1
            write_json_string(_out, value.get_string(), "string");
379
1
            return;
380
1
        case VariantPrimitiveId::TIME_NTZ_MICROS:
381
1
            write_quoted_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
382
1
            return;
383
0
        case VariantPrimitiveId::TIMESTAMP_NANOS:
384
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
385
0
                                                            _options.timezone));
386
0
            return;
387
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
388
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_nanos(), 9,
389
0
                                                            false, nullptr));
390
0
            return;
391
1
        case VariantPrimitiveId::UUID:
392
1
            write_quoted_scalar(_out, format_json_uuid(value.get_uuid()));
393
1
            return;
394
8.63k
        }
395
0
        throw_unsupported_json_primitive(id);
396
0
    }
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_114CountingWriterEE15write_primitiveENS_10VariantRefE
Line
Count
Source
322
8.67k
    void write_primitive(VariantRef value) {
323
8.67k
        const VariantPrimitiveId id = value.primitive_id();
324
8.67k
        switch (id) {
325
27
        case VariantPrimitiveId::NULL_VALUE:
326
27
            write_literal(_out, "null");
327
27
            return;
328
4
        case VariantPrimitiveId::TRUE_VALUE:
329
4
            write_literal(_out, "true");
330
4
            return;
331
0
        case VariantPrimitiveId::FALSE_VALUE:
332
0
            write_literal(_out, "false");
333
0
            return;
334
8.31k
        case VariantPrimitiveId::INT8:
335
8.57k
        case VariantPrimitiveId::INT16:
336
8.57k
        case VariantPrimitiveId::INT32:
337
8.57k
        case VariantPrimitiveId::INT64:
338
8.57k
            write_scalar(_out, format_json_int(value.get_int()));
339
8.57k
            return;
340
50
        case VariantPrimitiveId::DOUBLE: {
341
50
            const double number = value.get_double();
342
50
            if (!std::isfinite(number)) {
343
30
                write_non_finite(number);
344
30
                return;
345
30
            }
346
20
            write_scalar(_out, format_json_double(number));
347
20
            return;
348
50
        }
349
0
        case VariantPrimitiveId::DECIMAL4:
350
0
        case VariantPrimitiveId::DECIMAL8:
351
0
        case VariantPrimitiveId::DECIMAL16:
352
0
            write_scalar(_out, format_json_decimal(value.get_decimal()));
353
0
            return;
354
10
        case VariantPrimitiveId::DATE:
355
10
            write_quoted_scalar(_out, format_json_date(value.get_date()));
356
10
            return;
357
0
        case VariantPrimitiveId::TIMESTAMP_MICROS:
358
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
359
0
                                                            _options.timezone));
360
0
            return;
361
8
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
362
8
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6,
363
8
                                                            false, nullptr));
364
8
            return;
365
0
        case VariantPrimitiveId::FLOAT: {
366
0
            const float number = value.get_float();
367
0
            if (!std::isfinite(number)) {
368
0
                write_non_finite(number);
369
0
                return;
370
0
            }
371
0
            write_scalar(_out, format_json_float(number));
372
0
            return;
373
0
        }
374
0
        case VariantPrimitiveId::BINARY:
375
0
            write_json_binary(_out, value.get_binary());
376
0
            return;
377
1
        case VariantPrimitiveId::STRING:
378
1
            write_json_string(_out, value.get_string(), "string");
379
1
            return;
380
0
        case VariantPrimitiveId::TIME_NTZ_MICROS:
381
0
            write_quoted_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
382
0
            return;
383
0
        case VariantPrimitiveId::TIMESTAMP_NANOS:
384
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
385
0
                                                            _options.timezone));
386
0
            return;
387
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
388
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_nanos(), 9,
389
0
                                                            false, nullptr));
390
0
            return;
391
0
        case VariantPrimitiveId::UUID:
392
0
            write_quoted_scalar(_out, format_json_uuid(value.get_uuid()));
393
0
            return;
394
8.67k
        }
395
0
        throw_unsupported_json_primitive(id);
396
0
    }
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_111FixedWriterEE15write_primitiveENS_10VariantRefE
Line
Count
Source
322
71
    void write_primitive(VariantRef value) {
323
71
        const VariantPrimitiveId id = value.primitive_id();
324
71
        switch (id) {
325
14
        case VariantPrimitiveId::NULL_VALUE:
326
14
            write_literal(_out, "null");
327
14
            return;
328
0
        case VariantPrimitiveId::TRUE_VALUE:
329
0
            write_literal(_out, "true");
330
0
            return;
331
0
        case VariantPrimitiveId::FALSE_VALUE:
332
0
            write_literal(_out, "false");
333
0
            return;
334
3
        case VariantPrimitiveId::INT8:
335
3
        case VariantPrimitiveId::INT16:
336
3
        case VariantPrimitiveId::INT32:
337
3
        case VariantPrimitiveId::INT64:
338
3
            write_scalar(_out, format_json_int(value.get_int()));
339
3
            return;
340
40
        case VariantPrimitiveId::DOUBLE: {
341
40
            const double number = value.get_double();
342
40
            if (!std::isfinite(number)) {
343
24
                write_non_finite(number);
344
24
                return;
345
24
            }
346
16
            write_scalar(_out, format_json_double(number));
347
16
            return;
348
40
        }
349
0
        case VariantPrimitiveId::DECIMAL4:
350
0
        case VariantPrimitiveId::DECIMAL8:
351
0
        case VariantPrimitiveId::DECIMAL16:
352
0
            write_scalar(_out, format_json_decimal(value.get_decimal()));
353
0
            return;
354
8
        case VariantPrimitiveId::DATE:
355
8
            write_quoted_scalar(_out, format_json_date(value.get_date()));
356
8
            return;
357
0
        case VariantPrimitiveId::TIMESTAMP_MICROS:
358
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_micros(), 6, true,
359
0
                                                            _options.timezone));
360
0
            return;
361
6
        case VariantPrimitiveId::TIMESTAMP_NTZ_MICROS:
362
6
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_micros(), 6,
363
6
                                                            false, nullptr));
364
6
            return;
365
0
        case VariantPrimitiveId::FLOAT: {
366
0
            const float number = value.get_float();
367
0
            if (!std::isfinite(number)) {
368
0
                write_non_finite(number);
369
0
                return;
370
0
            }
371
0
            write_scalar(_out, format_json_float(number));
372
0
            return;
373
0
        }
374
0
        case VariantPrimitiveId::BINARY:
375
0
            write_json_binary(_out, value.get_binary());
376
0
            return;
377
0
        case VariantPrimitiveId::STRING:
378
0
            write_json_string(_out, value.get_string(), "string");
379
0
            return;
380
0
        case VariantPrimitiveId::TIME_NTZ_MICROS:
381
0
            write_quoted_scalar(_out, format_json_time_micros(value.get_time_ntz_micros()));
382
0
            return;
383
0
        case VariantPrimitiveId::TIMESTAMP_NANOS:
384
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_nanos(), 9, true,
385
0
                                                            _options.timezone));
386
0
            return;
387
0
        case VariantPrimitiveId::TIMESTAMP_NTZ_NANOS:
388
0
            write_quoted_scalar(_out, format_json_timestamp(value.get_timestamp_ntz_nanos(), 9,
389
0
                                                            false, nullptr));
390
0
            return;
391
0
        case VariantPrimitiveId::UUID:
392
0
            write_quoted_scalar(_out, format_json_uuid(value.get_uuid()));
393
0
            return;
394
71
        }
395
0
        throw_unsupported_json_primitive(id);
396
0
    }
397
398
    template <typename Number>
399
75
    void write_non_finite(Number value) {
400
75
        if (std::isnan(value)) {
401
25
            write_literal(_out, "\"NaN\"");
402
50
        } else if (value > 0) {
403
25
            write_literal(_out, "\"Infinity\"");
404
25
        } else {
405
25
            write_literal(_out, "\"-Infinity\"");
406
25
        }
407
75
    }
Unexecuted instantiation: column_variant_v2_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_110JsonWriterEE16write_non_finiteIdEEvT_
Unexecuted instantiation: column_variant_v2_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_110JsonWriterEE16write_non_finiteIfEEvT_
Unexecuted instantiation: function_variant_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEE16write_non_finiteIdEEvT_
Unexecuted instantiation: function_variant_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEE16write_non_finiteIfEEvT_
Unexecuted instantiation: _ZN5doris12variant_json7PrinterI17VariantJsonWriterE16write_non_finiteIdEEvT_
Unexecuted instantiation: _ZN5doris12variant_json7PrinterI17VariantJsonWriterE16write_non_finiteIfEEvT_
Unexecuted instantiation: variant_assembler_legacy_test.cpp:_ZN5doris12variant_json7PrinterINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEE16write_non_finiteIdEEvT_
Unexecuted instantiation: variant_assembler_legacy_test.cpp:_ZN5doris12variant_json7PrinterINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEE16write_non_finiteIfEEvT_
variant_string_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEE16write_non_finiteIdEEvT_
Line
Count
Source
399
1
    void write_non_finite(Number value) {
400
1
        if (std::isnan(value)) {
401
0
            write_literal(_out, "\"NaN\"");
402
1
        } else if (value > 0) {
403
0
            write_literal(_out, "\"Infinity\"");
404
1
        } else {
405
1
            write_literal(_out, "\"-Infinity\"");
406
1
        }
407
1
    }
variant_string_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEE16write_non_finiteIfEEvT_
Line
Count
Source
399
2
    void write_non_finite(Number value) {
400
2
        if (std::isnan(value)) {
401
1
            write_literal(_out, "\"NaN\"");
402
1
        } else if (value > 0) {
403
1
            write_literal(_out, "\"Infinity\"");
404
1
        } else {
405
0
            write_literal(_out, "\"-Infinity\"");
406
0
        }
407
2
    }
_ZN5doris12variant_json7PrinterINS_14BufferWritableEE16write_non_finiteIdEEvT_
Line
Count
Source
399
18
    void write_non_finite(Number value) {
400
18
        if (std::isnan(value)) {
401
6
            write_literal(_out, "\"NaN\"");
402
12
        } else if (value > 0) {
403
6
            write_literal(_out, "\"Infinity\"");
404
6
        } else {
405
6
            write_literal(_out, "\"-Infinity\"");
406
6
        }
407
18
    }
Unexecuted instantiation: _ZN5doris12variant_json7PrinterINS_14BufferWritableEE16write_non_finiteIfEEvT_
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_114CountingWriterEE16write_non_finiteIdEEvT_
Line
Count
Source
399
30
    void write_non_finite(Number value) {
400
30
        if (std::isnan(value)) {
401
10
            write_literal(_out, "\"NaN\"");
402
20
        } else if (value > 0) {
403
10
            write_literal(_out, "\"Infinity\"");
404
10
        } else {
405
10
            write_literal(_out, "\"-Infinity\"");
406
10
        }
407
30
    }
Unexecuted instantiation: unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_114CountingWriterEE16write_non_finiteIfEEvT_
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_111FixedWriterEE16write_non_finiteIdEEvT_
Line
Count
Source
399
24
    void write_non_finite(Number value) {
400
24
        if (std::isnan(value)) {
401
8
            write_literal(_out, "\"NaN\"");
402
16
        } else if (value > 0) {
403
8
            write_literal(_out, "\"Infinity\"");
404
8
        } else {
405
8
            write_literal(_out, "\"-Infinity\"");
406
8
        }
407
24
    }
Unexecuted instantiation: unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_111FixedWriterEE16write_non_finiteIfEEvT_
408
409
6.21k
    void write_object(VariantRef value, uint32_t depth) {
410
6.21k
        write_literal(_out, "{");
411
6.21k
        const uint32_t count = value.num_elements();
412
6.21k
        StringRef previous_key;
413
33.0k
        for (uint32_t index = 0; index < count; ++index) {
414
26.8k
            if (index != 0) {
415
20.6k
                write_literal(_out, ",");
416
20.6k
            }
417
26.8k
            uint32_t field_id = 0;
418
26.8k
            VariantRef child = value.object_value_at(index, &field_id);
419
26.8k
            const StringRef key = value.metadata.key_at(field_id);
420
26.8k
            require_json_object_key(key, previous_key, index);
421
26.8k
            write_escaped_json_string(_out, key);
422
26.8k
            write_literal(_out, ":");
423
26.8k
            write(child, depth + 1);
424
26.8k
            previous_key = key;
425
26.8k
        }
426
6.21k
        write_literal(_out, "}");
427
6.21k
    }
column_variant_v2_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_110JsonWriterEE12write_objectENS_10VariantRefEj
Line
Count
Source
409
119
    void write_object(VariantRef value, uint32_t depth) {
410
119
        write_literal(_out, "{");
411
119
        const uint32_t count = value.num_elements();
412
119
        StringRef previous_key;
413
216
        for (uint32_t index = 0; index < count; ++index) {
414
97
            if (index != 0) {
415
0
                write_literal(_out, ",");
416
0
            }
417
97
            uint32_t field_id = 0;
418
97
            VariantRef child = value.object_value_at(index, &field_id);
419
97
            const StringRef key = value.metadata.key_at(field_id);
420
97
            require_json_object_key(key, previous_key, index);
421
97
            write_escaped_json_string(_out, key);
422
97
            write_literal(_out, ":");
423
97
            write(child, depth + 1);
424
97
            previous_key = key;
425
97
        }
426
119
        write_literal(_out, "}");
427
119
    }
function_variant_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEE12write_objectENS_10VariantRefEj
Line
Count
Source
409
6
    void write_object(VariantRef value, uint32_t depth) {
410
6
        write_literal(_out, "{");
411
6
        const uint32_t count = value.num_elements();
412
6
        StringRef previous_key;
413
11
        for (uint32_t index = 0; index < count; ++index) {
414
5
            if (index != 0) {
415
0
                write_literal(_out, ",");
416
0
            }
417
5
            uint32_t field_id = 0;
418
5
            VariantRef child = value.object_value_at(index, &field_id);
419
5
            const StringRef key = value.metadata.key_at(field_id);
420
5
            require_json_object_key(key, previous_key, index);
421
5
            write_escaped_json_string(_out, key);
422
5
            write_literal(_out, ":");
423
5
            write(child, depth + 1);
424
5
            previous_key = key;
425
5
        }
426
6
        write_literal(_out, "}");
427
6
    }
_ZN5doris12variant_json7PrinterI17VariantJsonWriterE12write_objectENS_10VariantRefEj
Line
Count
Source
409
5
    void write_object(VariantRef value, uint32_t depth) {
410
5
        write_literal(_out, "{");
411
5
        const uint32_t count = value.num_elements();
412
5
        StringRef previous_key;
413
10
        for (uint32_t index = 0; index < count; ++index) {
414
5
            if (index != 0) {
415
0
                write_literal(_out, ",");
416
0
            }
417
5
            uint32_t field_id = 0;
418
5
            VariantRef child = value.object_value_at(index, &field_id);
419
5
            const StringRef key = value.metadata.key_at(field_id);
420
5
            require_json_object_key(key, previous_key, index);
421
5
            write_escaped_json_string(_out, key);
422
5
            write_literal(_out, ":");
423
5
            write(child, depth + 1);
424
5
            previous_key = key;
425
5
        }
426
5
        write_literal(_out, "}");
427
5
    }
variant_assembler_legacy_test.cpp:_ZN5doris12variant_json7PrinterINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEE12write_objectENS_10VariantRefEj
Line
Count
Source
409
56
    void write_object(VariantRef value, uint32_t depth) {
410
56
        write_literal(_out, "{");
411
56
        const uint32_t count = value.num_elements();
412
56
        StringRef previous_key;
413
127
        for (uint32_t index = 0; index < count; ++index) {
414
71
            if (index != 0) {
415
19
                write_literal(_out, ",");
416
19
            }
417
71
            uint32_t field_id = 0;
418
71
            VariantRef child = value.object_value_at(index, &field_id);
419
71
            const StringRef key = value.metadata.key_at(field_id);
420
71
            require_json_object_key(key, previous_key, index);
421
71
            write_escaped_json_string(_out, key);
422
71
            write_literal(_out, ":");
423
71
            write(child, depth + 1);
424
71
            previous_key = key;
425
71
        }
426
56
        write_literal(_out, "}");
427
56
    }
variant_string_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEE12write_objectENS_10VariantRefEj
Line
Count
Source
409
21
    void write_object(VariantRef value, uint32_t depth) {
410
21
        write_literal(_out, "{");
411
21
        const uint32_t count = value.num_elements();
412
21
        StringRef previous_key;
413
49
        for (uint32_t index = 0; index < count; ++index) {
414
28
            if (index != 0) {
415
8
                write_literal(_out, ",");
416
8
            }
417
28
            uint32_t field_id = 0;
418
28
            VariantRef child = value.object_value_at(index, &field_id);
419
28
            const StringRef key = value.metadata.key_at(field_id);
420
28
            require_json_object_key(key, previous_key, index);
421
28
            write_escaped_json_string(_out, key);
422
28
            write_literal(_out, ":");
423
28
            write(child, depth + 1);
424
28
            previous_key = key;
425
28
        }
426
21
        write_literal(_out, "}");
427
21
    }
_ZN5doris12variant_json7PrinterINS_14BufferWritableEE12write_objectENS_10VariantRefEj
Line
Count
Source
409
3.00k
    void write_object(VariantRef value, uint32_t depth) {
410
3.00k
        write_literal(_out, "{");
411
3.00k
        const uint32_t count = value.num_elements();
412
3.00k
        StringRef previous_key;
413
16.3k
        for (uint32_t index = 0; index < count; ++index) {
414
13.3k
            if (index != 0) {
415
10.3k
                write_literal(_out, ",");
416
10.3k
            }
417
13.3k
            uint32_t field_id = 0;
418
13.3k
            VariantRef child = value.object_value_at(index, &field_id);
419
13.3k
            const StringRef key = value.metadata.key_at(field_id);
420
13.3k
            require_json_object_key(key, previous_key, index);
421
13.3k
            write_escaped_json_string(_out, key);
422
13.3k
            write_literal(_out, ":");
423
13.3k
            write(child, depth + 1);
424
13.3k
            previous_key = key;
425
13.3k
        }
426
3.00k
        write_literal(_out, "}");
427
3.00k
    }
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_114CountingWriterEE12write_objectENS_10VariantRefEj
Line
Count
Source
409
3.00k
    void write_object(VariantRef value, uint32_t depth) {
410
3.00k
        write_literal(_out, "{");
411
3.00k
        const uint32_t count = value.num_elements();
412
3.00k
        StringRef previous_key;
413
16.3k
        for (uint32_t index = 0; index < count; ++index) {
414
13.3k
            if (index != 0) {
415
10.3k
                write_literal(_out, ",");
416
10.3k
            }
417
13.3k
            uint32_t field_id = 0;
418
13.3k
            VariantRef child = value.object_value_at(index, &field_id);
419
13.3k
            const StringRef key = value.metadata.key_at(field_id);
420
13.3k
            require_json_object_key(key, previous_key, index);
421
13.3k
            write_escaped_json_string(_out, key);
422
13.3k
            write_literal(_out, ":");
423
13.3k
            write(child, depth + 1);
424
13.3k
            previous_key = key;
425
13.3k
        }
426
3.00k
        write_literal(_out, "}");
427
3.00k
    }
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_111FixedWriterEE12write_objectENS_10VariantRefEj
Line
Count
Source
409
3
    void write_object(VariantRef value, uint32_t depth) {
410
3
        write_literal(_out, "{");
411
3
        const uint32_t count = value.num_elements();
412
3
        StringRef previous_key;
413
6
        for (uint32_t index = 0; index < count; ++index) {
414
3
            if (index != 0) {
415
0
                write_literal(_out, ",");
416
0
            }
417
3
            uint32_t field_id = 0;
418
3
            VariantRef child = value.object_value_at(index, &field_id);
419
3
            const StringRef key = value.metadata.key_at(field_id);
420
3
            require_json_object_key(key, previous_key, index);
421
3
            write_escaped_json_string(_out, key);
422
3
            write_literal(_out, ":");
423
3
            write(child, depth + 1);
424
3
            previous_key = key;
425
3
        }
426
3
        write_literal(_out, "}");
427
3
    }
428
429
383
    void write_array(VariantRef value, uint32_t depth) {
430
383
        write_literal(_out, "[");
431
383
        const uint32_t count = value.num_elements();
432
831
        for (uint32_t index = 0; index < count; ++index) {
433
448
            if (index != 0) {
434
83
                write_literal(_out, ",");
435
83
            }
436
448
            write(value.array_at(index), depth + 1);
437
448
        }
438
383
        write_literal(_out, "]");
439
383
    }
column_variant_v2_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_110JsonWriterEE11write_arrayENS_10VariantRefEj
Line
Count
Source
429
19
    void write_array(VariantRef value, uint32_t depth) {
430
19
        write_literal(_out, "[");
431
19
        const uint32_t count = value.num_elements();
432
38
        for (uint32_t index = 0; index < count; ++index) {
433
19
            if (index != 0) {
434
0
                write_literal(_out, ",");
435
0
            }
436
19
            write(value.array_at(index), depth + 1);
437
19
        }
438
19
        write_literal(_out, "]");
439
19
    }
function_variant_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEE11write_arrayENS_10VariantRefEj
Line
Count
Source
429
2
    void write_array(VariantRef value, uint32_t depth) {
430
2
        write_literal(_out, "[");
431
2
        const uint32_t count = value.num_elements();
432
6
        for (uint32_t index = 0; index < count; ++index) {
433
4
            if (index != 0) {
434
2
                write_literal(_out, ",");
435
2
            }
436
4
            write(value.array_at(index), depth + 1);
437
4
        }
438
2
        write_literal(_out, "]");
439
2
    }
Unexecuted instantiation: _ZN5doris12variant_json7PrinterI17VariantJsonWriterE11write_arrayENS_10VariantRefEj
variant_assembler_legacy_test.cpp:_ZN5doris12variant_json7PrinterINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEE11write_arrayENS_10VariantRefEj
Line
Count
Source
429
20
    void write_array(VariantRef value, uint32_t depth) {
430
20
        write_literal(_out, "[");
431
20
        const uint32_t count = value.num_elements();
432
48
        for (uint32_t index = 0; index < count; ++index) {
433
28
            if (index != 0) {
434
10
                write_literal(_out, ",");
435
10
            }
436
28
            write(value.array_at(index), depth + 1);
437
28
        }
438
20
        write_literal(_out, "]");
439
20
    }
variant_string_parse_test.cpp:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_112StringWriterEE11write_arrayENS_10VariantRefEj
Line
Count
Source
429
263
    void write_array(VariantRef value, uint32_t depth) {
430
263
        write_literal(_out, "[");
431
263
        const uint32_t count = value.num_elements();
432
538
        for (uint32_t index = 0; index < count; ++index) {
433
275
            if (index != 0) {
434
12
                write_literal(_out, ",");
435
12
            }
436
275
            write(value.array_at(index), depth + 1);
437
275
        }
438
263
        write_literal(_out, "]");
439
263
    }
_ZN5doris12variant_json7PrinterINS_14BufferWritableEE11write_arrayENS_10VariantRefEj
Line
Count
Source
429
36
    void write_array(VariantRef value, uint32_t depth) {
430
36
        write_literal(_out, "[");
431
36
        const uint32_t count = value.num_elements();
432
92
        for (uint32_t index = 0; index < count; ++index) {
433
56
            if (index != 0) {
434
26
                write_literal(_out, ",");
435
26
            }
436
56
            write(value.array_at(index), depth + 1);
437
56
        }
438
36
        write_literal(_out, "]");
439
36
    }
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_114CountingWriterEE11write_arrayENS_10VariantRefEj
Line
Count
Source
429
37
    void write_array(VariantRef value, uint32_t depth) {
430
37
        write_literal(_out, "[");
431
37
        const uint32_t count = value.num_elements();
432
94
        for (uint32_t index = 0; index < count; ++index) {
433
57
            if (index != 0) {
434
27
                write_literal(_out, ",");
435
27
            }
436
57
            write(value.array_at(index), depth + 1);
437
57
        }
438
37
        write_literal(_out, "]");
439
37
    }
unity_5_cxx.cxx:_ZN5doris12variant_json7PrinterINS_12_GLOBAL__N_111FixedWriterEE11write_arrayENS_10VariantRefEj
Line
Count
Source
429
6
    void write_array(VariantRef value, uint32_t depth) {
430
6
        write_literal(_out, "[");
431
6
        const uint32_t count = value.num_elements();
432
15
        for (uint32_t index = 0; index < count; ++index) {
433
9
            if (index != 0) {
434
6
                write_literal(_out, ",");
435
6
            }
436
9
            write(value.array_at(index), depth + 1);
437
9
        }
438
6
        write_literal(_out, "]");
439
6
    }
440
441
    Writer& _out;
442
    const VariantJsonFormatOptions& _options;
443
};
444
445
} // namespace variant_json
446
447
// Writer is statically dispatched and only needs write(const char*, size_t).
448
template <typename Writer>
449
void to_json(VariantRef value, Writer& out,
450
11.6k
             const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
451
11.6k
    variant_json::require_exact_json_value(value);
452
11.6k
    variant_json::Printer<Writer>(out, options).write(value, 0);
453
11.6k
}
column_variant_v2_test.cpp:_ZN5doris7to_jsonINS_12_GLOBAL__N_110JsonWriterEEEvNS_10VariantRefERT_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
450
141
             const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
451
141
    variant_json::require_exact_json_value(value);
452
141
    variant_json::Printer<Writer>(out, options).write(value, 0);
453
141
}
function_variant_parse_test.cpp:_ZN5doris7to_jsonINS_12_GLOBAL__N_112StringWriterEEEvNS_10VariantRefERT_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
450
13
             const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
451
13
    variant_json::require_exact_json_value(value);
452
13
    variant_json::Printer<Writer>(out, options).write(value, 0);
453
13
}
_ZN5doris7to_jsonI17VariantJsonWriterEEvNS_10VariantRefERT_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
450
10
             const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
451
10
    variant_json::require_exact_json_value(value);
452
10
    variant_json::Printer<Writer>(out, options).write(value, 0);
453
10
}
variant_assembler_legacy_test.cpp:_ZN5doris7to_jsonINS_10segment_v210variant_v212_GLOBAL__N_110JsonWriterEEEvNS_10VariantRefERT_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
450
150
             const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
451
150
    variant_json::require_exact_json_value(value);
452
150
    variant_json::Printer<Writer>(out, options).write(value, 0);
453
150
}
variant_string_parse_test.cpp:_ZN5doris7to_jsonINS_12_GLOBAL__N_112StringWriterEEEvNS_10VariantRefERT_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
450
48
             const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
451
48
    variant_json::require_exact_json_value(value);
452
48
    variant_json::Printer<Writer>(out, options).write(value, 0);
453
48
}
_ZN5doris7to_jsonINS_14BufferWritableEEEvNS_10VariantRefERT_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
450
5.56k
             const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
451
5.56k
    variant_json::require_exact_json_value(value);
452
5.56k
    variant_json::Printer<Writer>(out, options).write(value, 0);
453
5.56k
}
unity_5_cxx.cxx:_ZN5doris7to_jsonINS_12_GLOBAL__N_114CountingWriterEEEvNS_10VariantRefERT_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
450
5.63k
             const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
451
5.63k
    variant_json::require_exact_json_value(value);
452
5.63k
    variant_json::Printer<Writer>(out, options).write(value, 0);
453
5.63k
}
unity_5_cxx.cxx:_ZN5doris7to_jsonINS_12_GLOBAL__N_111FixedWriterEEEvNS_10VariantRefERT_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
450
80
             const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
451
80
    variant_json::require_exact_json_value(value);
452
80
    variant_json::Printer<Writer>(out, options).write(value, 0);
453
80
}
454
455
// Preserve the current Variant V1 SQL result contract for top-level scalar values: JSON strings
456
// such as "value" and "2" are returned as value and 2. Once V1 is removed, this compatibility
457
// output will change to the uniform JSON representation ("value" and "2").
458
template <typename Writer>
459
void to_sql_string(VariantRef value, Writer& out,
460
103
                   const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
461
103
    variant_json::require_exact_json_value(value);
462
103
    variant_json::Printer<Writer>(out, options).write_plain_scalar(value);
463
103
}
_ZN5doris13to_sql_stringINS_14BufferWritableEEEvNS_10VariantRefERT_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
460
51
                   const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
461
51
    variant_json::require_exact_json_value(value);
462
51
    variant_json::Printer<Writer>(out, options).write_plain_scalar(value);
463
51
}
unity_5_cxx.cxx:_ZN5doris13to_sql_stringINS_12_GLOBAL__N_114CountingWriterEEEvNS_10VariantRefERT_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
460
26
                   const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
461
26
    variant_json::require_exact_json_value(value);
462
26
    variant_json::Printer<Writer>(out, options).write_plain_scalar(value);
463
26
}
unity_5_cxx.cxx:_ZN5doris13to_sql_stringINS_12_GLOBAL__N_111FixedWriterEEEvNS_10VariantRefERT_RKNS_24VariantJsonFormatOptionsE
Line
Count
Source
460
26
                   const VariantJsonFormatOptions& options = VariantJsonFormatOptions {}) {
461
26
    variant_json::require_exact_json_value(value);
462
26
    variant_json::Printer<Writer>(out, options).write_plain_scalar(value);
463
26
}
464
465
} // namespace doris