From b2cc94a04fb936ae8335abceb1469fa4286288e3 Mon Sep 17 00:00:00 2001 From: nextdreamblue Date: Mon, 24 Oct 2022 19:04:58 +0800 Subject: [PATCH 1/2] [fix][fe] Inconsistent behavior for string comparison in FE and BE Signed-off-by: nextdreamblue --- .../main/java/org/apache/doris/analysis/StringLiteral.java | 4 ++-- 1 file changed, 2 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 3a6dcd60941cf5..9761a43725d043 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 @@ -96,9 +96,9 @@ public int compareLiteral(LiteralExpr expr) { int minLength = Math.min(thisBytes.length, otherBytes.length); int i = 0; for (i = 0; i < minLength; i++) { - if (thisBytes[i] < otherBytes[i]) { + if (Byte.toUnsignedInt(thisBytes[i]) < Byte.toUnsignedInt(otherBytes[i])) { return -1; - } else if (thisBytes[i] > otherBytes[i]) { + } else if (Byte.toUnsignedInt(thisBytes[i]) > Byte.toUnsignedInt(otherBytes[i])) { return 1; } } From d03e6dbdb3d496cd641c13600f1cdce5849efdf2 Mon Sep 17 00:00:00 2001 From: nextdreamblue Date: Tue, 25 Oct 2022 11:56:23 +0800 Subject: [PATCH 2/2] add test case Signed-off-by: nextdreamblue --- regression-test/data/query_p0/sort/sort.out | 3 +++ regression-test/suites/query_p0/sort/sort.groovy | 1 + 2 files changed, 4 insertions(+) diff --git a/regression-test/data/query_p0/sort/sort.out b/regression-test/data/query_p0/sort/sort.out index b4a5c9ee016a7b..4e898a3f6242a5 100644 --- a/regression-test/data/query_p0/sort/sort.out +++ b/regression-test/data/query_p0/sort/sort.out @@ -7,3 +7,6 @@ 2022-01-01 1 汇总 1 +-- !sort_string_on_fe -- +true + diff --git a/regression-test/suites/query_p0/sort/sort.groovy b/regression-test/suites/query_p0/sort/sort.groovy index b967c93137c606..2d41adf19239bd 100644 --- a/regression-test/suites/query_p0/sort/sort.groovy +++ b/regression-test/suites/query_p0/sort/sort.groovy @@ -22,4 +22,5 @@ suite("sort") { qt_sort_string_single_column """ select * from ( select '汇总' as a union all select '2022-01-01' as a ) a order by 1 """ qt_sort_string_multiple_columns """ select * from ( select '汇总' as a,1 as b union all select '2022-01-01' as a,1 as b ) a order by 1,2 """ + qt_sort_string_on_fe """ select '汇总' > '2022-01-01' """ }