From 54cb9b4809ab68355f072e9ffb7bffff70cd7dba Mon Sep 17 00:00:00 2001 From: lihangyu <15605149486@163.com> Date: Wed, 3 Jul 2024 23:03:00 +0800 Subject: [PATCH] [Fix](Prepared Statment) use fixed charset to init StringLiteral (#37085) picked from #36860 --- .../main/java/org/apache/doris/analysis/StringLiteral.java | 5 ++++- .../src/main/java/org/apache/doris/qe/ConnectProcessor.java | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java index 67cf82cc1a0753..542c668459af51 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java @@ -40,6 +40,7 @@ import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.Objects; public class StringLiteral extends LiteralExpr { @@ -310,7 +311,9 @@ public void setupParamFromBinary(ByteBuffer data, boolean isUnsigned) { } byte[] bytes = new byte[strLen]; data.get(bytes); - value = new String(bytes); + // ATTN: use fixed StandardCharsets.UTF_8 to avoid unexpected charset in + // different environment + value = new String(bytes, StandardCharsets.UTF_8); if (LOG.isDebugEnabled()) { LOG.debug("parsed value '{}'", value); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java index e608b68684b7a8..ba4fbfa1fcaed2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java @@ -214,7 +214,9 @@ private static boolean isNull(byte[] bitmap, int position) { // process COM_EXECUTE, parse binary row data // https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_execute.html private void handleExecute() { - // debugPacket(); + if (LOG.isDebugEnabled()) { + debugPacket(); + } packetBuf = packetBuf.order(ByteOrder.LITTLE_ENDIAN); // parse stmt_id, flags, params int stmtId = packetBuf.getInt();