Coder Social home page Coder Social logo

Comments (2)

RamyaStec avatar RamyaStec commented on August 15, 2024

package org.apache.phoenix.expression.function;

import java.io.DataInput;
import java.io.IOException;
import java.util.List;
import java.util.regex.Pattern;

import org.apache.hadoop.hbase.io.ImmutableBytesWritable;

import org.apache.phoenix.expression.Expression;
import org.apache.phoenix.expression.LiteralExpression;
import org.apache.phoenix.parse.FunctionParseNode.Argument;
import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
import org.apache.phoenix.schema.PDataType;
import org.apache.phoenix.schema.tuple.Tuple;

@BuiltInFunction(name=RegexpLikeFunction.NAME, args= {
@argument(allowedTypes={PDataType.VARCHAR}),
@argument(allowedTypes={PDataType.VARCHAR})} )
public class RegexpLikeFunction extends ScalarFunction {
public static final String NAME = "REGEXP_REPLACE";

private boolean hasReplaceStr;
private Pattern pattern;

public RegexpLikeFunction() { }

public RegexpLikeFunction(List<Expression> children) {
    super(children);
    init();
}

private void init() {
    Object patternString = ((LiteralExpression)children.get(1)).getValue();
    if (patternString != null) {
        pattern = Pattern.compile((String)patternString);
    }
}

@Override
public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
    if (pattern == null) {
        return false;
    }
    Expression sourceStrExpression = getSourceStrExpression();
    if (!sourceStrExpression.evaluate(tuple, ptr)) {
        return false;
    }
    String sourceStr = (String)PDataType.VARCHAR.toObject(ptr, sourceStrExpression.getColumnModifier());
    if (sourceStr == null) {
        return false;
    }


    boolean matched = pattern.matcher(sourceStr).matches();
    ptr.set(matched ? PDataType.TRUE_BYTES : PDataType.FALSE_BYTES);
    return true;
}

private Expression getSourceStrExpression() {
    return children.get(0);
}



@Override
public PDataType getDataType() {
    return PDataType.BOOLEAN;
}

@Override
public void readFields(DataInput input) throws IOException {
    super.readFields(input);
    init();
}

@Override
public String getName() {
    return NAME;
}

}

from phoenix.

jtaylor-sfdc avatar jtaylor-sfdc commented on August 15, 2024

@RamyaStec - thanks for the patch, however this github repo is no longer active as Phoenix is an Apache project since last year. Please see here on how to contribute. Essentially you'll send a pull request to our Apache github repo and generate a patch file for each branch that'll contain your fix: 3.0, 4.0, and master.

from phoenix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.