phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject phoenix git commit: PHOENIX-1870 Fix NPE occurring during regex processing when joni library not used (Shuxiong Ye)
Date Tue, 21 Apr 2015 05:48:20 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 c1db374b4 -> 24979aa1e


PHOENIX-1870 Fix NPE occurring during regex processing when joni library not used (Shuxiong
Ye)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/24979aa1
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/24979aa1
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/24979aa1

Branch: refs/heads/4.x-HBase-0.98
Commit: 24979aa1eb3aec0f8362cc719afb390185236a00
Parents: c1db374
Author: James Taylor <jtaylor@salesforce.com>
Authored: Mon Apr 20 22:45:57 2015 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Mon Apr 20 22:47:15 2015 -0700

----------------------------------------------------------------------
 .../phoenix/expression/LikeExpression.java      |  8 +--
 .../function/RegexpReplaceFunction.java         | 74 ++++++++++++++------
 .../function/RegexpSplitFunction.java           | 59 +++++++++-------
 .../util/regex/AbstractBasePattern.java         |  6 +-
 .../util/regex/AbstractBaseSplitter.java        |  2 +-
 .../expression/util/regex/GuavaSplitter.java    |  6 +-
 .../expression/util/regex/JONIPattern.java      | 22 +++---
 .../expression/util/regex/JavaPattern.java      | 20 +++---
 .../util/regex/PatternPerformanceTest.java      | 13 +++-
 9 files changed, 125 insertions(+), 85 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/24979aa1/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java
index 52ac969..ec4aa3a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/LikeExpression.java
@@ -236,10 +236,10 @@ public abstract class LikeExpression extends BaseCompoundExpression
{
             LiteralExpression likeTypeExpression = (LiteralExpression)children.get(LIKE_TYPE_INDEX);
             this.likeType = LikeType.valueOf((String)likeTypeExpression.getValue());
         }
+        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
         Expression e = getPatternExpression();
-        if (e instanceof LiteralExpression) {
-            LiteralExpression patternExpression = (LiteralExpression)e;
-            String value = (String)patternExpression.getValue();
+        if (e.isStateless() && e.getDeterminism() == Determinism.ALWAYS &&
e.evaluate(null, ptr)) {
+            String value = (String) PVarchar.INSTANCE.toObject(ptr, e.getDataType(), e.getSortOrder());
             pattern = compilePattern(value);
         }
     }
@@ -294,7 +294,7 @@ public abstract class LikeExpression extends BaseCompoundExpression {
             value = (String) strDataType.toObject(ptr, strSortOrder);
         }
         strDataType.coerceBytes(ptr, strDataType, strSortOrder, SortOrder.ASC);
-        pattern.matches(ptr, ptr);
+        pattern.matches(ptr);
         if (logger.isTraceEnabled()) {
             boolean matched = ((Boolean) PBoolean.INSTANCE.toObject(ptr)).booleanValue();
             logger.trace("LIKE(value='" + value + "'pattern='" + pattern.pattern() + "' is
" + matched);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/24979aa1/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
index f22c978..b5a3d39 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpReplaceFunction.java
@@ -22,8 +22,8 @@ import java.io.IOException;
 import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.expression.Determinism;
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.expression.util.regex.AbstractBasePattern;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
@@ -57,9 +57,11 @@ import org.apache.phoenix.schema.types.PVarchar;
 public abstract class RegexpReplaceFunction extends ScalarFunction {
     public static final String NAME = "REGEXP_REPLACE";
 
-    private boolean hasReplaceStr;
+    private static final PVarchar TYPE = PVarchar.INSTANCE;
+    private byte [] rStrBytes;
+    private int rStrOffset, rStrLen;
     private AbstractBasePattern pattern;
-    
+
     public RegexpReplaceFunction() { }
 
     // Expect 1 arguments, the pattern. 
@@ -71,37 +73,59 @@ public abstract class RegexpReplaceFunction extends ScalarFunction {
     protected abstract AbstractBasePattern compilePatternSpec(String value);
 
     private void init() {
-        hasReplaceStr = ((LiteralExpression)getReplaceStrExpression()).getValue() != null;
-        Object patternString = ((LiteralExpression)children.get(1)).getValue();
-        if (patternString != null) {
-            pattern = compilePatternSpec((String) patternString);
+        ImmutableBytesWritable tmpPtr = new ImmutableBytesWritable();
+        Expression e = getPatternStrExpression();
+        if (e.isStateless() && e.getDeterminism() == Determinism.ALWAYS &&
e.evaluate(null, tmpPtr)) {
+            String patternStr = (String) TYPE.toObject(tmpPtr, e.getDataType(), e.getSortOrder());
+            if (patternStr != null) pattern = compilePatternSpec(patternStr);
+        }
+        e = getReplaceStrExpression();
+        if (e.isStateless() && e.getDeterminism() == Determinism.ALWAYS &&
e.evaluate(null, tmpPtr)) {
+            TYPE.coerceBytes(tmpPtr, TYPE, e.getSortOrder(), SortOrder.ASC);
+            rStrBytes = tmpPtr.get();
+            rStrOffset = tmpPtr.getOffset();
+            rStrLen = tmpPtr.getLength();
+        } else {
+            rStrBytes = null;
         }
     }
 
     @Override
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
-        // Can't parse if there is no replacement pattern.
+        AbstractBasePattern pattern = this.pattern;
         if (pattern == null) {
-            return false;
-        }
-        Expression sourceStrExpression = getSourceStrExpression();
-        if (!sourceStrExpression.evaluate(tuple, ptr)) {
-            return false;
+            Expression e = getPatternStrExpression();
+            if (!e.evaluate(tuple, ptr)) {
+                return false;
+            }
+            String patternStr = (String) TYPE.toObject(ptr, e.getDataType(), e.getSortOrder());
+            if (patternStr == null) {
+                return false;
+            } else {
+                pattern = compilePatternSpec(patternStr);
+            }
         }
-        if (ptr == null) return false;
-        PVarchar type = PVarchar.INSTANCE;
-        type.coerceBytes(ptr, type, sourceStrExpression.getSortOrder(), SortOrder.ASC);
-        ImmutableBytesWritable replacePtr = new ImmutableBytesWritable();
-        if (hasReplaceStr) {
+
+        byte[] rStrBytes = this.rStrBytes;
+        int rStrOffset = this.rStrOffset, rStrLen = this.rStrLen;
+        if (rStrBytes == null) {
             Expression replaceStrExpression = getReplaceStrExpression();
-            if (!replaceStrExpression.evaluate(tuple, replacePtr)) {
+            if (!replaceStrExpression.evaluate(tuple, ptr)) {
                 return false;
             }
-            type.coerceBytes(replacePtr, type, replaceStrExpression.getSortOrder(), SortOrder.ASC);
-        } else {
-            replacePtr.set(type.toBytes(""));
+            TYPE.coerceBytes(ptr, TYPE, replaceStrExpression.getSortOrder(), SortOrder.ASC);
+            rStrBytes = ptr.get();
+            rStrOffset = ptr.getOffset();
+            rStrLen = ptr.getLength();
         }
-        pattern.replaceAll(ptr, replacePtr, ptr);
+
+        Expression sourceStrExpression = getSourceStrExpression();
+        if (!sourceStrExpression.evaluate(tuple, ptr)) {
+            return false;
+        }
+        TYPE.coerceBytes(ptr, TYPE, sourceStrExpression.getSortOrder(), SortOrder.ASC);
+
+        pattern.replaceAll(ptr, rStrBytes, rStrOffset, rStrLen);
         return true;
     }
 
@@ -109,6 +133,10 @@ public abstract class RegexpReplaceFunction extends ScalarFunction {
         return children.get(0);
     }
 
+    private Expression getPatternStrExpression() {
+        return children.get(1);
+    }
+
     private Expression getReplaceStrExpression() {
         return children.get(2);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/24979aa1/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
index b43dec9..c663188 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/RegexpSplitFunction.java
@@ -22,8 +22,8 @@ import java.io.IOException;
 import java.util.List;
 
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.expression.Determinism;
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.expression.util.regex.AbstractBaseSplitter;
 import org.apache.phoenix.parse.FunctionParseNode;
 import org.apache.phoenix.parse.RegexpSplitParseNode;
@@ -53,6 +53,8 @@ public abstract class RegexpSplitFunction extends ScalarFunction {
 
     public static final String NAME = "REGEXP_SPLIT";
 
+    private static final PVarchar TYPE = PVarchar.INSTANCE;
+
     private AbstractBaseSplitter initializedSplitter = null;
 
     public RegexpSplitFunction() {}
@@ -63,11 +65,12 @@ public abstract class RegexpSplitFunction extends ScalarFunction {
     }
 
     private void init() {
-        Expression patternExpression = children.get(1);
-        if (patternExpression instanceof LiteralExpression) {
-            Object patternValue = ((LiteralExpression) patternExpression).getValue();
-            if (patternValue != null) {
-                initializedSplitter = compilePatternSpec(patternValue.toString());
+        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+        Expression e = getPatternStrExpression();
+        if (e.isStateless() && e.getDeterminism() == Determinism.ALWAYS &&
e.evaluate(null, ptr)) {
+            String pattern = (String) TYPE.toObject(ptr, TYPE, e.getSortOrder());
+            if (pattern != null) {
+                initializedSplitter = compilePatternSpec(pattern);
             }
         }
     }
@@ -87,31 +90,37 @@ public abstract class RegexpSplitFunction extends ScalarFunction {
 
     @Override
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
-        if (!children.get(0).evaluate(tuple, ptr)) {
-            return false;
-        }
-
-        Expression sourceStrExpression = children.get(0);
-        PVarchar type = PVarchar.INSTANCE;
-        type.coerceBytes(ptr, type, sourceStrExpression.getSortOrder(), SortOrder.ASC);
-
         AbstractBaseSplitter splitter = initializedSplitter;
         if (splitter == null) {
-            ImmutableBytesWritable tmpPtr = new ImmutableBytesWritable();
-            Expression patternExpression = children.get(1);
-            if (!patternExpression.evaluate(tuple, tmpPtr)) {
+            Expression e = getPatternStrExpression();
+            if (e.evaluate(tuple, ptr)) {
+                String pattern = (String) TYPE.toObject(ptr, TYPE, e.getSortOrder());
+                if (pattern != null) {
+                    splitter = compilePatternSpec(pattern);
+                } else {
+                    ptr.set(ByteUtil.EMPTY_BYTE_ARRAY); // set ptr to null
+                    return true;
+                }
+            } else {
                 return false;
             }
-            if (tmpPtr.getLength() == 0) {
-                ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
-                return true; // set ptr to null
-            }
-            String patternStr =
-                    (String) PVarchar.INSTANCE.toObject(tmpPtr, patternExpression.getSortOrder());
-            splitter = compilePatternSpec(patternStr);
         }
 
-        return splitter.split(ptr, ptr);
+        Expression e = getSourceStrExpression();
+        if (!e.evaluate(tuple, ptr)) {
+            return false;
+        }
+        TYPE.coerceBytes(ptr, TYPE, e.getSortOrder(), SortOrder.ASC);
+
+        return splitter.split(ptr);
+    }
+
+    private Expression getSourceStrExpression() {
+        return children.get(0);
+    }
+
+    private Expression getPatternStrExpression() {
+        return children.get(1);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/24979aa1/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/AbstractBasePattern.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/AbstractBasePattern.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/AbstractBasePattern.java
index 5287fd7..922c7c9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/AbstractBasePattern.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/AbstractBasePattern.java
@@ -21,10 +21,10 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 public abstract class AbstractBasePattern {
 
-    public abstract void matches(ImmutableBytesWritable srcPtr, ImmutableBytesWritable outPtr);
+    public abstract void matches(ImmutableBytesWritable srcPtr);
 
-    public abstract void replaceAll(ImmutableBytesWritable srcPtr,
-            ImmutableBytesWritable replacePtr, ImmutableBytesWritable outPtr);
+    public abstract void replaceAll(ImmutableBytesWritable srcPtr, byte[] rStrBytes,
+            int rStrOffset, int rStrLen);
 
     public abstract void substr(ImmutableBytesWritable srcPtr, int offsetInStr);
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/24979aa1/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/AbstractBaseSplitter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/AbstractBaseSplitter.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/AbstractBaseSplitter.java
index 323eed0..7565338 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/AbstractBaseSplitter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/AbstractBaseSplitter.java
@@ -20,5 +20,5 @@ package org.apache.phoenix.expression.util.regex;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 
 public abstract interface AbstractBaseSplitter {
-    public abstract boolean split(ImmutableBytesWritable srcPtr, ImmutableBytesWritable outPtr);
+    public abstract boolean split(ImmutableBytesWritable srcPtr);
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/24979aa1/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/GuavaSplitter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/GuavaSplitter.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/GuavaSplitter.java
index 325919e..1f53526 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/GuavaSplitter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/GuavaSplitter.java
@@ -40,14 +40,14 @@ public class GuavaSplitter implements AbstractBaseSplitter {
     }
 
     @Override
-    public boolean split(ImmutableBytesWritable srcPtr, ImmutableBytesWritable outPtr) {
+    public boolean split(ImmutableBytesWritable srcPtr) {
         String sourceStr = (String) PVarchar.INSTANCE.toObject(srcPtr);
         if (sourceStr == null) { // sourceStr evaluated to null
-            outPtr.set(ByteUtil.EMPTY_BYTE_ARRAY);
+            srcPtr.set(ByteUtil.EMPTY_BYTE_ARRAY);
         } else {
             List<String> splitStrings = Lists.newArrayList(splitter.split(sourceStr));
             PhoenixArray splitArray = new PhoenixArray(PVarchar.INSTANCE, splitStrings.toArray());
-            outPtr.set(PVarcharArray.INSTANCE.toBytes(splitArray));
+            srcPtr.set(PVarcharArray.INSTANCE.toBytes(splitArray));
         }
         return true;
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/24979aa1/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java
index b17e8a7..69f9eaf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JONIPattern.java
@@ -60,11 +60,10 @@ public class JONIPattern extends AbstractBasePattern implements AbstractBaseSpli
     }
 
     @Override
-    public void matches(ImmutableBytesWritable srcPtr, ImmutableBytesWritable outPtr) {
+    public void matches(ImmutableBytesWritable srcPtr) {
         Preconditions.checkNotNull(srcPtr);
-        Preconditions.checkNotNull(outPtr);
         boolean ret = matches(srcPtr.get(), srcPtr.getOffset(), srcPtr.getLength());
-        outPtr.set(ret ? PDataType.TRUE_BYTES : PDataType.FALSE_BYTES);
+        srcPtr.set(ret ? PDataType.TRUE_BYTES : PDataType.FALSE_BYTES);
     }
 
     private boolean matches(byte[] bytes, int offset, int len) {
@@ -80,15 +79,14 @@ public class JONIPattern extends AbstractBasePattern implements AbstractBaseSpli
     }
 
     @Override
-    public void replaceAll(ImmutableBytesWritable srcPtr, ImmutableBytesWritable replacePtr,
-            ImmutableBytesWritable replacedPtr) {
+    public void replaceAll(ImmutableBytesWritable srcPtr, byte[] rStrBytes, int rStrOffset,
+            int rStrLen) {
         Preconditions.checkNotNull(srcPtr);
-        Preconditions.checkNotNull(replacePtr);
-        Preconditions.checkNotNull(replacedPtr);
+        Preconditions.checkNotNull(rStrBytes);
         byte[] replacedBytes =
-                replaceAll(srcPtr.get(), srcPtr.getOffset(), srcPtr.getLength(), replacePtr.get(),
-                    replacePtr.getOffset(), replacePtr.getLength());
-        replacedPtr.set(replacedBytes);
+                replaceAll(srcPtr.get(), srcPtr.getOffset(), srcPtr.getLength(), rStrBytes,
+                    rStrOffset, rStrLen);
+        srcPtr.set(replacedBytes);
     }
 
     private byte[] replaceAll(byte[] srcBytes, int srcOffset, int srcLen, byte[] replaceBytes,
@@ -154,8 +152,8 @@ public class JONIPattern extends AbstractBasePattern implements AbstractBaseSpli
     }
 
     @Override
-    public boolean split(ImmutableBytesWritable srcPtr, ImmutableBytesWritable outPtr) {
-        return split(srcPtr.get(), srcPtr.getOffset(), srcPtr.getLength(), outPtr);
+    public boolean split(ImmutableBytesWritable srcPtr) {
+        return split(srcPtr.get(), srcPtr.getOffset(), srcPtr.getLength(), srcPtr);
     }
 
     private boolean

http://git-wip-us.apache.org/repos/asf/phoenix/blob/24979aa1/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JavaPattern.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JavaPattern.java
b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JavaPattern.java
index f4bd239..707bced 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JavaPattern.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/util/regex/JavaPattern.java
@@ -44,13 +44,12 @@ public class JavaPattern extends AbstractBasePattern {
     }
 
     @Override
-    public void matches(ImmutableBytesWritable srcPtr, ImmutableBytesWritable outPtr) {
+    public void matches(ImmutableBytesWritable srcPtr) {
         Preconditions.checkNotNull(srcPtr);
-        Preconditions.checkNotNull(outPtr);
         String matcherSourceStr = (String) PVarchar.INSTANCE.toObject(srcPtr);
         if (srcPtr.get().length == 0 && matcherSourceStr == null) matcherSourceStr
= "";
         boolean ret = pattern.matcher(matcherSourceStr).matches();
-        outPtr.set(ret ? PDataType.TRUE_BYTES : PDataType.FALSE_BYTES);
+        srcPtr.set(ret ? PDataType.TRUE_BYTES : PDataType.FALSE_BYTES);
     }
 
     @Override
@@ -59,17 +58,16 @@ public class JavaPattern extends AbstractBasePattern {
     }
 
     @Override
-    public void replaceAll(ImmutableBytesWritable srcPtr, ImmutableBytesWritable replacePtr,
-            ImmutableBytesWritable replacedPtr) {
+    public void replaceAll(ImmutableBytesWritable srcPtr, byte[] rStrBytes, int rStrOffset,
+            int rStrLen) {
         Preconditions.checkNotNull(srcPtr);
-        Preconditions.checkNotNull(replacePtr);
-        Preconditions.checkNotNull(replacedPtr);
+        Preconditions.checkNotNull(rStrBytes);
         String sourceStr = (String) PVarchar.INSTANCE.toObject(srcPtr);
-        String replaceStr = (String) PVarchar.INSTANCE.toObject(replacePtr);
-        if (srcPtr.get().length == 0 && sourceStr == null) sourceStr = "";
-        if (replacePtr.get().length == 0 && replaceStr == null) replaceStr = "";
+        String replaceStr = (String) PVarchar.INSTANCE.toObject(rStrBytes, rStrOffset, rStrLen);
+        if (srcPtr.getLength() == 0 && sourceStr == null) sourceStr = "";
+        if (rStrLen == 0 && replaceStr == null) replaceStr = "";
         String replacedStr = pattern.matcher(sourceStr).replaceAll(replaceStr);
-        replacedPtr.set(PVarchar.INSTANCE.toBytes(replacedStr));
+        srcPtr.set(PVarchar.INSTANCE.toBytes(replacedStr));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/24979aa1/phoenix-core/src/test/java/org/apache/phoenix/expression/util/regex/PatternPerformanceTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/expression/util/regex/PatternPerformanceTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/expression/util/regex/PatternPerformanceTest.java
index 4275687..6722a71 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/expression/util/regex/PatternPerformanceTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/expression/util/regex/PatternPerformanceTest.java
@@ -63,7 +63,10 @@ public class PatternPerformanceTest {
             String name) {
         timer.reset();
         for (int i = 0; i < maxTimes; ++i) {
-            pattern.replaceAll(dataPtr[i % 3], replacePtr, resultPtr);
+            ImmutableBytesWritable ptr = dataPtr[i % 3];
+            resultPtr.set(ptr.get(), ptr.getOffset(), ptr.getLength());
+            pattern.replaceAll(resultPtr, replacePtr.get(), replacePtr.getOffset(),
+                replacePtr.getLength());
             if (ENABLE_ASSERT) {
                 String result = (String) PVarchar.INSTANCE.toObject(resultPtr);
                 assertTrue((i % 3 == 1 && ":".equals(result))
@@ -83,7 +86,9 @@ public class PatternPerformanceTest {
     private void testLike(AbstractBasePattern pattern, String name) {
         timer.reset();
         for (int i = 0; i < maxTimes; ++i) {
-            pattern.matches(dataPtr[i % 3], resultPtr);
+            ImmutableBytesWritable ptr = dataPtr[i % 3];
+            resultPtr.set(ptr.get(), ptr.getOffset(), ptr.getLength());
+            pattern.matches(resultPtr);
             if (ENABLE_ASSERT) {
                 Boolean b = (Boolean) PBoolean.INSTANCE.toObject(resultPtr);
                 assertTrue(i % 3 != 2 || b.booleanValue());
@@ -120,7 +125,9 @@ public class PatternPerformanceTest {
     private void testSplit(AbstractBaseSplitter pattern, String name) throws SQLException
{
         timer.reset();
         for (int i = 0; i < maxTimes; ++i) {
-            boolean ret = pattern.split(dataPtr[i % 3], resultPtr);
+            ImmutableBytesWritable ptr = dataPtr[i % 3];
+            resultPtr.set(ptr.get(), ptr.getOffset(), ptr.getLength());
+            boolean ret = pattern.split(resultPtr);
             if (ENABLE_ASSERT) {
                 PhoenixArray array = (PhoenixArray) PVarcharArray.INSTANCE.toObject(resultPtr);
                 assertTrue(ret && (i % 3 != 1 || ((String[]) array.getArray()).length
== 2));


Mime
View raw message