15 package com.cloudera.impala.util;
17 import java.util.Arrays;
18 import java.util.List;
19 import java.util.regex.Matcher;
20 import java.util.regex.Pattern;
22 import com.google.common.collect.Lists;
35 public boolean matches(String candidate) {
39 if (pattern.matcher(candidate).matches())
return true;
53 if (hivePattern != null) {
54 result.patterns_ = Lists.newArrayList();
56 final String metaCharacters =
"+?.^()]\\/{}";
57 final Pattern regex = Pattern.compile(
"([" + Pattern.quote(metaCharacters) +
"])");
59 for (String pattern: Arrays.asList(hivePattern.split(
"\\|"))) {
60 Matcher matcher = regex.matcher(pattern);
61 pattern = matcher.replaceAll(
"\\\\$1").replace(
"*",
".*");
62 result.patterns_.add(Pattern.compile(pattern));
72 String wildcardPattern =
".*";
73 String workPattern = pattern;
74 if (workPattern == null || pattern.isEmpty()) {
77 String result = workPattern
78 .replaceAll(
"([^\\\\])%",
"$1" + wildcardPattern)
79 .replaceAll(
"\\\\%",
"%")
80 .replaceAll(
"^%", wildcardPattern)
81 .replaceAll(
"([^\\\\])_",
"$1.")
82 .replaceAll(
"\\\\_",
"_")
83 .replaceAll(
"^_",
".");
85 matcher.patterns_ = Lists.newArrayList();
86 matcher.patterns_.add(Pattern.compile(result));
List< Pattern > patterns_
boolean matches(String candidate)
static PatternMatcher createJdbcPatternMatcher(String pattern)
static PatternMatcher createHivePatternMatcher(String hivePattern)