Search in sources :

Example 1 with Matcher

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)));
        }
    }
}
Also used : Matcher(com.google.re2j.Matcher) MetricsException(org.apache.hadoop.metrics2.MetricsException)

Example 2 with Matcher

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();
}
Also used : Matcher(com.google.re2j.Matcher) Slice(io.airlift.slice.Slice) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 3 with Matcher

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);
}
Also used : Matcher(com.google.re2j.Matcher)

Example 4 with Matcher

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();
}
Also used : Matcher(com.google.re2j.Matcher) Slice(io.airlift.slice.Slice) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Aggregations

Matcher (com.google.re2j.Matcher)4 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)2 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)2 Slice (io.airlift.slice.Slice)2 MetricsException (org.apache.hadoop.metrics2.MetricsException)1