Coverage Report

Created: 2026-06-26 13:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format/arrow/arrow_utils.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "format/arrow/arrow_utils.h"
19
20
#include <arrow/pretty_print.h>
21
#include <arrow/status.h>
22
23
namespace doris {
24
25
3
Status to_doris_status(const arrow::Status& status) {
26
3
    if (status.ok()) {
27
0
        return Status::OK();
28
3
    } else {
29
3
        return Status::InternalError(status.ToString());
30
3
    }
31
3
}
32
33
348
arrow::Status to_arrow_status(const Status& status) {
34
348
    if (LIKELY(status.ok())) {
35
348
        return arrow::Status::OK();
36
348
    } else {
37
0
        LOG(WARNING) << status.to_string();
38
        // The length of exception msg returned to the ADBC Client cannot larger than 8192,
39
        // otherwise ADBC Client will receive:
40
        // `INTERNAL: http2 exception Header size exceeded max allowed size (8192)`.
41
        // The message is carried in the gRPC trailer (an HTTP2 header) and may be
42
        // percent-encoded (which can expand its size), so an oversized message can break the
43
        // response or even crash the flight transport status conversion. Truncate it well below
44
        // 8192 to leave headroom; the full message is already logged above.
45
0
        constexpr size_t kMaxArrowStatusMsgLen = 1024;
46
0
        std::string msg = status.to_string_no_stack();
47
0
        if (msg.size() > kMaxArrowStatusMsgLen) {
48
0
            msg.resize(kMaxArrowStatusMsgLen);
49
0
            msg += "... (truncated)";
50
0
        }
51
0
        return arrow::Status::Invalid(msg);
52
0
    }
53
348
}
54
55
0
Status arrow_pretty_print(const arrow::RecordBatch& rb, std::ostream* os) {
56
0
    return to_doris_status(arrow::PrettyPrint(rb, 0, os));
57
0
}
58
59
0
Status arrow_pretty_print(const arrow::Array& arr, std::ostream* os) {
60
0
    arrow::PrettyPrintOptions opts(4);
61
0
    return to_doris_status(arrow::PrettyPrint(arr, opts, os));
62
0
}
63
64
} // namespace doris