github-actions[bot] commented on code in PR #62741:
URL: https://github.com/apache/doris/pull/62741#discussion_r3145447407


##########
be/src/core/data_type_serde/data_type_string_serde.cpp:
##########
@@ -430,7 +430,17 @@ void DataTypeStringSerDeBase<ColumnType>::to_string(const 
IColumn& column, size_
     const auto& value =
             assert_cast<const ColumnType&, 
TypeCheckOnRelease::DISABLE>(column).get_data_at(
                     row_num);
-    bw.write(value.data, value.size);
+
+    if constexpr (std::is_same_v<ColumnType, ColumnString>) {
+        if (_nesting_level > 1 && options.escape_char != 0) {

Review Comment:
   This branch now makes `SELECT struct_col` / `CAST(struct_col AS STRING)` 
emit JSON escapes for `\n`, `\t`, `\r`, `\b`, and `\f`, but the reverse parser 
still does not decode those escapes. `cast_from_string_to_complex_type()` 
passes `escape_char='\\'`, and 
`DataTypeStringSerDeBase::deserialize_one_cell_from_json()` just strips the 
backslash via `escape_string()` instead of translating `\n` back to a newline 
byte. As a result, `CAST(CAST(st AS STRING) AS STRUCT<a:STRING>)` now 
round-trips `a\nb\tc` as `anbtc`. Please either teach the string parser to 
decode standard JSON escapes or avoid emitting them on this path until the 
reverse direction is fixed.



##########
be/src/core/data_type_serde/data_type_string_serde.cpp:
##########
@@ -430,7 +430,17 @@ void DataTypeStringSerDeBase<ColumnType>::to_string(const 
IColumn& column, size_
     const auto& value =
             assert_cast<const ColumnType&, 
TypeCheckOnRelease::DISABLE>(column).get_data_at(
                     row_num);
-    bw.write(value.data, value.size);
+
+    if constexpr (std::is_same_v<ColumnType, ColumnString>) {
+        if (_nesting_level > 1 && options.escape_char != 0) {
+            write_with_escaped_char_to_json(value, bw);

Review Comment:
   This still does not make the struct text output valid JSON for all strings. 
`write_with_escaped_char_to_json()` only handles `\"`, `\\`, `\b`, `\f`, `\n`, 
`\r`, and `\t`; bytes like `0x00`, `0x01`, or `0x1B` are written raw inside the 
quoted string. JSON requires every `U+0000..U+001F` control byte to be escaped, 
so a struct field containing those bytes will still produce invalid JSON on the 
new path. Please switch to a full JSON string escaper (or add `\u00XX` escaping 
for the remaining control bytes).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to