Skip to content

Commit 69c327e

Browse files
committed
update to_string
1 parent c6d2da5 commit 69c327e

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

be/src/vec/common/string_view.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,15 @@ class StringView {
126126
std::string dump_hex() const {
127127
static const char* kHex = "0123456789ABCDEF";
128128
std::string out;
129-
out.reserve(size_ * 2 + 3);
130-
out.push_back('X');
131-
out.push_back('\'');
129+
out.reserve(size_ * 2 + 2);
130+
out.push_back('0');
131+
out.push_back('x');
132132
const char* ptr = data();
133133
for (uint32_t i = 0; i < size_; ++i) {
134134
auto c = static_cast<unsigned char>(ptr[i]);
135135
out.push_back(kHex[c >> 4]);
136136
out.push_back(kHex[c & 0x0F]);
137137
}
138-
out.push_back('\'');
139138
return out;
140139
}
141140

be/src/vec/data_types/serde/data_type_varbinary_serde.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Status DataTypeVarbinarySerDe::write_column_to_mysql_binary(const IColumn& colum
4141
int64_t row_idx, bool col_const,
4242
const FormatOptions& options) const {
4343
auto col_index = index_check_const(row_idx, col_const);
44-
auto data = assert_cast<const ColumnVarbinary&>(column).get_data()[col_index];
44+
const auto& data = assert_cast<const ColumnVarbinary&>(column).get_data()[col_index];
4545

4646
if (0 != result.push_string(data.data(), data.size())) {
4747
return Status::InternalError("pack mysql buffer failed.");
@@ -62,7 +62,7 @@ Status DataTypeVarbinarySerDe::write_column_to_arrow(const IColumn& column, cons
6262
builder.type()->name()));
6363
continue;
6464
}
65-
auto string_view = varbinary_column_data[i];
65+
const auto& string_view = varbinary_column_data[i];
6666
RETURN_IF_ERROR(checkArrowStatus(builder.Append(string_view.data(), string_view.size()),
6767
column.get_name(), builder.type()->name()));
6868
}
@@ -117,8 +117,13 @@ Status DataTypeVarbinarySerDe::deserialize_one_cell_from_json(IColumn& column, S
117117

118118
void DataTypeVarbinarySerDe::to_string(const IColumn& column, size_t row_num,
119119
BufferWritable& bw) const {
120-
const auto value = assert_cast<const ColumnVarbinary&>(column).get_data_at(row_num);
121-
bw.write(value.data, value.size);
120+
const auto& value = assert_cast<const ColumnVarbinary&>(column).get_data()[row_num];
121+
if (_nesting_level >= 2) { // in complex type, need to dump as hex string by hand
122+
const auto& hex_str = value.dump_hex();
123+
bw.write(hex_str.data(), hex_str.size());
124+
} else { // mysql protocol will be handle as hex binary data directly
125+
bw.write(value.data(), value.size());
126+
}
122127
}
123128

124129
} // namespace doris::vectorized
Binary file not shown.

0 commit comments

Comments
 (0)