XuQianJin-Stars commented on a change in pull request #1768: [CALCITE-3704]
Implement STRCMP function
URL: https://github.com/apache/calcite/pull/1768#discussion_r376834082
##########
File path: site/_docs/reference.md
##########
@@ -2350,6 +2350,7 @@ semantics.
| m o p | SOUNDEX(string) | Returns the phonetic
representation of *string*; throws if *string* is encoded with multi-byte
encoding such as UTF-8
| m | SPACE(integer) | Returns a string of
*integer* spaces; returns an empty string if *integer* is less than 1
| o | SUBSTR(string, position [, substringLength ]) | Returns a portion of
*string*, beginning at character *position*, *substringLength* characters long.
SUBSTR calculates lengths using characters as defined by the input character set
+| m | STRCMP(string, string) | Returns 0 if both of
the strings are same and returns -1 when the first argument is smaller than the
second according to the defined order and 1 when the second one is smaller the
first one.
Review comment:
> Can the Java `compareTo` take the charSet into account ?
String chinese = "中文";
String gbkChinese = new String(chinese.getBytes("GBK"),
"ISO-8859-1");//转换成gbk编码
String unicodeChinese = new
String(gbkChinese.getBytes("ISO-8859-1"), "GBK");//java内部编码
System.out.println(unicodeChinese);//中文
String utf8Chinese = new String(unicodeChinese.getBytes("UTF-8"),
"ISO-8859-1");//utf--8编码
System.out.println(utf8Chinese);//乱码
unicodeChinese = new String(utf8Chinese.getBytes("ISO-8859-1"),
"UTF-8");//java内部编码
System.out.println(unicodeChinese);//中文
String str1 = "中文";
String str2 = "中文1";
String str3 = null;
System.out.println((int) Math.signum(str1.compareTo(chinese)));
System.out.println((int) Math.signum(str2.compareTo(chinese)));
System.out.println(str1.compareTo(chinese));
System.out.println(str2.compareTo(chinese));
This test `compareTo` is work.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services