LakeShen commented on code in PR #3317:
URL: https://github.com/apache/calcite/pull/3317#discussion_r1331774237
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -1076,6 +1076,32 @@ public static int levenshtein(String string1, String
string2) {
return LEVENSHTEIN_DISTANCE.apply(string1, string2);
}
+ /** SQL FIND_IN_SET(string, stringArray) function. */
+ public static int findInSet(String matchStr, String textStr) {
+ if (matchStr.contains(",")) {
+ return 0;
+ }
+ int textStrLen = textStr.length();
+ int matchStrLen = matchStr.length();
+ int n = 1;
+ int lastComma = -1;
+ for (int i = 0; i < textStrLen; i++) {
+ if (textStr.charAt(i) == ',') {
+ if (i - (lastComma + 1) == matchStrLen
+ && textStr.substring(lastComma + 1, i).equals(matchStr)) {
+ return n;
+ }
+ lastComma = i;
+ n++;
+ }
+ }
+ if (textStrLen - (lastComma + 1) == matchStrLen
+ && textStr.substring(lastComma + 1, textStrLen).equals(matchStr)) {
Review Comment:
If there are more code comments would help people understand better,I think
you could give more code comments in this method:)
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]