branch-2.1:[fix](nereids)Use utf-8 when convert string like literal to double. (#50085) (#50155)

backport: https://github.com/apache/doris/pull/50085
This commit is contained in:
James
2025-04-19 17:16:20 +08:00
committed by GitHub
parent 967d0a59b9
commit 048537cd03
2 changed files with 9 additions and 1 deletions

View File

@ -19,6 +19,7 @@ package org.apache.doris.nereids.trees.expressions.literal;
import org.apache.doris.nereids.types.DataType;
import java.nio.charset.StandardCharsets;
import java.util.Objects;
/**
@ -46,7 +47,7 @@ public abstract class StringLikeLiteral extends Literal {
* get double value
*/
public static double getDouble(String str) {
byte[] bytes = str.getBytes();
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
long v = 0;
int pos = 0;
int len = Math.min(bytes.length, 7);

View File

@ -31,4 +31,11 @@ public class StringLikeLiteralTest {
double d2 = StringLikeLiteral.getDouble(maxStr);
Assertions.assertTrue(d1 < d2);
}
@Test
public void testUtf8() {
System.setProperty("file.encoding", "ANSI_X3.4-1968");
double d1 = StringLikeLiteral.getDouble("一般风险准备");
Assertions.assertEquals(d1, 6.4379158486625512E16);
}
}