From fee08fb979ac5ca7b38eca42dd843ac2a1d8fbff Mon Sep 17 00:00:00 2001 From: "Mateusz \"Serafin\" Gajewski" Date: Thu, 31 Oct 2024 23:10:27 +0100 Subject: [PATCH] Undo optimization In Hive coercion tests some test cases produce binary arrays that contain \0. Previously we were writing Slices representing UTF-8 String by calling .toStringUtf8() which passed the bytes to the String constructor that would truncate the value at \0. When directly writing Slice to a JSON output, \0 isn't interpreted as String terminator, got escaped and appears in the output without truncation. It seems more correct but breaks previous behaviour. --- .../java/io/trino/server/protocol/JsonEncodingUtils.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/trino-main/src/main/java/io/trino/server/protocol/JsonEncodingUtils.java b/core/trino-main/src/main/java/io/trino/server/protocol/JsonEncodingUtils.java index 8783fc641e42..e8c8970e0a32 100644 --- a/core/trino-main/src/main/java/io/trino/server/protocol/JsonEncodingUtils.java +++ b/core/trino-main/src/main/java/io/trino/server/protocol/JsonEncodingUtils.java @@ -263,8 +263,7 @@ public void encode(JsonGenerator generator, ConnectorSession session, Block bloc return; } Slice slice = VARCHAR.getSlice(block, position); - // Optimization: avoid conversion from Slice to String and String to bytes when writing UTF-8 strings - generator.writeUTF8String(slice.byteArray(), slice.byteArrayOffset(), slice.length()); + generator.writeString(slice.toStringUtf8()); } } @@ -287,8 +286,7 @@ public void encode(JsonGenerator generator, ConnectorSession session, Block bloc return; } Slice slice = padSpaces(VARCHAR.getSlice(block, position), length); - // Optimization: avoid conversion from Slice to String and String to bytes when writing UTF-8 strings - generator.writeUTF8String(slice.byteArray(), slice.byteArrayOffset(), slice.length()); + generator.writeString(slice.toStringUtf8()); } }