mihaibudiu commented on code in PR #4522:
URL: https://github.com/apache/calcite/pull/4522#discussion_r2324073315
##########
core/src/main/java/org/apache/calcite/rex/RexSimplify.java:
##########
@@ -529,6 +530,66 @@ private RexNode simplifyLike(RexCall e, RexUnknownAs
unknownAs) {
return simplifyGenericNode(e);
}
+ // string 'AA%%__%%AA' simplify to 'AA__%AA'
+ // string with even escapes 'AA\\\\%%__%%AA' simplify to 'AA\\__%AA'
+ // string with odd escapes 'AA\\\\\\%%__%%AA' simplify to 'AA\\\\\\%__%AA'
+ private String simplifyMixedWildcards(String str, char escape) {
+ Pattern pattern = Pattern.compile("[_%]+");
+ Matcher matcher = pattern.matcher(str);
+ StringBuilder builder = new StringBuilder();
+ int from = 0;
+ while (matcher.find()) {
+ int start = matcher.start();
+ String group = requireNonNull(matcher.group(0));
+ if (start > 0
+ && str.charAt(start - 1) == escape
+ && consecutiveSameCharCountBefore(str, start - 1, escape) % 2 == 1) {
+ builder.append(str.substring(from, start + 1));
+ builder.append(simplifyPercentAndUnderline(group.substring(1)));
+ } else {
+ builder.append(str.substring(from, start));
+ builder.append(simplifyPercentAndUnderline(group));
+ }
+ from = matcher.end();
+ }
+ if (from < str.length()) {
+ builder.append(str.substring(from));
+ }
+ return builder.toString();
+ }
+
+ // Tool method: count the number of consecutive identical characters before
index
+ private int consecutiveSameCharCountBefore(String str, int index, char
escape) {
+ int count = 0;
+ while (index >= 0) {
+ if (str.charAt(index) != escape) {
+ break;
+ }
+ count++;
+ index--;
+ }
+ return count;
+ }
+
+ // Tool method: simplied string mixed with '%' and '_'
+ private String simplifyPercentAndUnderline(String str) {
+ StringBuilder builder = new StringBuilder();
+ boolean contaninsPercent = false;
Review Comment:
I don't know why you ask for a new review if you haven't addressed yet the
comments in the previous one.
there is a typo in the variable name.
It's spelled 'contains'
--
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]