use of com.google.re2j.Matcher in project hadoop by apache.
the class AbstractPatternFilter method init.
@Override
public void init(SubsetConfiguration conf) {
String patternString = conf.getString(INCLUDE_KEY);
if (patternString != null && !patternString.isEmpty()) {
setIncludePattern(compile(patternString));
}
patternString = conf.getString(EXCLUDE_KEY);
if (patternString != null && !patternString.isEmpty()) {
setExcludePattern(compile(patternString));
}
String[] patternStrings = conf.getStringArray(INCLUDE_TAGS_KEY);
if (patternStrings != null && patternStrings.length != 0) {
for (String pstr : patternStrings) {
Matcher matcher = tagPattern.matcher(pstr);
if (!matcher.matches()) {
throw new MetricsException("Illegal tag pattern: " + pstr);
}
setIncludeTagPattern(matcher.group(1), compile(matcher.group(2)));
}
}
patternStrings = conf.getStringArray(EXCLUDE_TAGS_KEY);
if (patternStrings != null && patternStrings.length != 0) {
for (String pstr : patternStrings) {
Matcher matcher = tagPattern.matcher(pstr);
if (!matcher.matches()) {
throw new MetricsException("Illegal tag pattern: " + pstr);
}
setExcludeTagPattern(matcher.group(1), compile(matcher.group(2)));
}
}
}
use of com.google.re2j.Matcher in project presto by prestodb.
the class Re2JRegexp method split.
public Block split(Slice source) {
Matcher matcher = re2jPattern.matcher(source);
BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), 32);
int lastEnd = 0;
while (matcher.find()) {
Slice slice = source.slice(lastEnd, matcher.start() - lastEnd);
lastEnd = matcher.end();
VARCHAR.writeSlice(blockBuilder, slice);
}
VARCHAR.writeSlice(blockBuilder, source.slice(lastEnd, source.length() - lastEnd));
return blockBuilder.build();
}
use of com.google.re2j.Matcher in project presto by prestodb.
the class Re2JRegexp method extract.
public Slice extract(Slice source, long groupIndex) {
Matcher matcher = re2jPattern.matcher(source);
int group = toIntExact(groupIndex);
validateGroup(group, matcher.groupCount());
if (!matcher.find()) {
return null;
}
return matcher.group(group);
}
use of com.google.re2j.Matcher in project presto by prestodb.
the class Re2JRegexp method extractAll.
public Block extractAll(Slice source, long groupIndex) {
Matcher matcher = re2jPattern.matcher(source);
int group = toIntExact(groupIndex);
validateGroup(group, matcher.groupCount());
BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(new BlockBuilderStatus(), 32);
while (true) {
if (!matcher.find()) {
break;
}
Slice searchedGroup = matcher.group(group);
if (searchedGroup == null) {
blockBuilder.appendNull();
continue;
}
VARCHAR.writeSlice(blockBuilder, searchedGroup);
}
return blockBuilder.build();
}
Aggregations