You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ch...@apache.org on 2020/06/21 11:18:04 UTC

[phoenix] branch 4.x updated: PHOENIX-5897 SingleKeyValueTuple.toString() returns unexpected result

This is an automated email from the ASF dual-hosted git repository.

chenglei pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x by this push:
     new dbd52de  PHOENIX-5897 SingleKeyValueTuple.toString() returns unexpected result
dbd52de is described below

commit dbd52de7711432f2364ba8381e06f087beff1fd5
Author: chenglei <ch...@apache.org>
AuthorDate: Sun Jun 21 19:16:44 2020 +0800

    PHOENIX-5897 SingleKeyValueTuple.toString() returns unexpected result
---
 .../phoenix/schema/tuple/SingleKeyValueTuple.java  | 28 +++++++++----
 .../schema/tuple/SingleKeyValueTupleTest.java      | 47 ++++++++++++++++++++++
 2 files changed, 67 insertions(+), 8 deletions(-)

diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/SingleKeyValueTuple.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/SingleKeyValueTuple.java
index e35eb13..c2895b8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/SingleKeyValueTuple.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/tuple/SingleKeyValueTuple.java
@@ -25,7 +25,7 @@ import org.apache.hadoop.hbase.util.Bytes;
 public class SingleKeyValueTuple extends BaseTuple {
     private static final byte[] UNITIALIZED_KEY_BUFFER = new byte[0];
     private Cell cell;
-    private ImmutableBytesWritable keyPtr = new ImmutableBytesWritable(UNITIALIZED_KEY_BUFFER);
+    private ImmutableBytesWritable rowKeyPtr = new ImmutableBytesWritable(UNITIALIZED_KEY_BUFFER);
     
     public SingleKeyValueTuple() {
     }
@@ -38,12 +38,12 @@ public class SingleKeyValueTuple extends BaseTuple {
     }
     
     public boolean hasKey() {
-        return keyPtr.get() != UNITIALIZED_KEY_BUFFER;
+        return rowKeyPtr.get() != UNITIALIZED_KEY_BUFFER;
     }
     
     public void reset() {
         this.cell = null;
-        keyPtr.set(UNITIALIZED_KEY_BUFFER);
+        rowKeyPtr.set(UNITIALIZED_KEY_BUFFER);
     }
     
     public void setCell(Cell cell) {
@@ -55,19 +55,19 @@ public class SingleKeyValueTuple extends BaseTuple {
     }
     
     public void setKey(ImmutableBytesWritable ptr) {
-        keyPtr.set(ptr.get(), ptr.getOffset(), ptr.getLength());
+        rowKeyPtr.set(ptr.get(), ptr.getOffset(), ptr.getLength());
     }
     
     public void setKey(Cell cell) {
         if (cell == null) {
             throw new IllegalArgumentException();
         }
-        keyPtr.set(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
+        rowKeyPtr.set(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
     }
     
     @Override
     public void getKey(ImmutableBytesWritable ptr) {
-        ptr.set(keyPtr.get(), keyPtr.getOffset(), keyPtr.getLength());
+        ptr.set(rowKeyPtr.get(), rowKeyPtr.getOffset(), rowKeyPtr.getLength());
     }
     
     @Override
@@ -79,10 +79,22 @@ public class SingleKeyValueTuple extends BaseTuple {
     public boolean isImmutable() {
         return true;
     }
-    
+
     @Override
     public String toString() {
-        return "SingleKeyValueTuple[" + cell == null ? keyPtr.get() == UNITIALIZED_KEY_BUFFER ? "null" : Bytes.toStringBinary(keyPtr.get(),keyPtr.getOffset(),keyPtr.getLength()) : cell.toString() + "]";
+        StringBuilder sb = new StringBuilder();
+        sb.append("SingleKeyValueTuple[");
+        if (cell == null) {
+            if (rowKeyPtr.get() == UNITIALIZED_KEY_BUFFER) {
+                sb.append("null");
+            } else {
+                sb.append(Bytes.toStringBinary(rowKeyPtr.get(),rowKeyPtr.getOffset(),rowKeyPtr.getLength()));
+            }
+        } else {
+            sb.append(cell.toString());
+        }
+        sb.append("]");
+        return sb.toString();
     }
 
     @Override
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/tuple/SingleKeyValueTupleTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/tuple/SingleKeyValueTupleTest.java
new file mode 100644
index 0000000..42df766
--- /dev/null
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/tuple/SingleKeyValueTupleTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.schema.tuple;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.KeyValue.Type;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.util.Bytes;
+
+public class SingleKeyValueTupleTest {
+
+    @Test
+    public void testToString() {
+
+        SingleKeyValueTuple singleKeyValueTuple = new SingleKeyValueTuple();
+        assertTrue(singleKeyValueTuple.toString().equals("SingleKeyValueTuple[null]"));
+        final byte [] rowKey = Bytes.toBytes("aaa");
+        singleKeyValueTuple.setKey(new ImmutableBytesWritable(rowKey));
+        assertTrue(singleKeyValueTuple.toString().equals("SingleKeyValueTuple[aaa]"));
+
+        byte [] family1 = Bytes.toBytes("abc");
+        byte [] qualifier1 = Bytes.toBytes("def");
+        KeyValue keyValue = new KeyValue(rowKey, family1, qualifier1, 0L, Type.Put, rowKey);
+        singleKeyValueTuple = new SingleKeyValueTuple(keyValue);
+        assertTrue(singleKeyValueTuple.toString().startsWith("SingleKeyValueTuple[aaa/abc:def/0/Put/vlen=3"));
+        assertTrue(singleKeyValueTuple.toString().endsWith("]"));
+    }
+
+}