AshinGau commented on code in PR #10213:
URL: https://github.com/apache/doris/pull/10213#discussion_r900045726
##########
fe/fe-core/src/main/java/org/apache/doris/common/PatternMatcher.java:
##########
@@ -20,27 +20,58 @@
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
+import java.util.Locale;
import java.util.Set;
import java.util.regex.Pattern;
// Wrap for Java pattern and matcher
public class PatternMatcher {
+ public static PatternMatcher MATCH_ANY = new
PatternMatcher(Pattern.compile(".*"));
private Pattern pattern;
+ private String casePattern;
+ private boolean caseSensitive;
private static final Set<Character> FORBIDDEN_CHARS = Sets.newHashSet('<',
'(', '[', '{', '^', '=',
'$',
'!', '|', ']', '}', ')',
'?',
'*', '+', '>', '@');
+ public PatternMatcher(Pattern pattern) {
+ this.pattern = pattern;
+ }
+
+ public PatternMatcher(String casePattern, boolean caseSensitive) {
+ this.casePattern = caseSensitive ? casePattern :
casePattern.toLowerCase(Locale.ROOT);
+ this.caseSensitive = caseSensitive;
+ }
+
public boolean match(String candidate) {
- if (pattern == null || candidate == null) {
- // No pattern, how can I explain this? Return false now.
- // No candidate, return false.
+ if (candidate == null) {
return false;
}
- if (pattern.matcher(candidate).matches()) {
- return true;
+ if (pattern != null) {
+ return pattern.matcher(candidate).matches();
+ }
+ if (caseSensitive) {
+ return candidate.equals(casePattern);
+ } else {
+ return candidate.toLowerCase(Locale.ROOT).equals(casePattern);
+ }
+ }
+
+ public static PatternMatcher createCasePattern(String casePattern, boolean
caseSensitive) {
+ return createCasePattern(casePattern, caseSensitive, false);
+ }
+
+ /**
+ * In grant operation, database and table support matching a single
wildcard,
+ * the other cases are string case-sensitive equivalent matching.
+ */
+ public static PatternMatcher createCasePattern(
Review Comment:
change to createFlatPattern
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]