kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danburk...@apache.org
Subject kudu git commit: KUDU-1757: add PartialRow.toString
Date Fri, 09 Dec 2016 00:00:31 GMT
Repository: kudu
Updated Branches:
  refs/heads/master f17562fd0 -> 18a8a90f7


KUDU-1757: add PartialRow.toString

Operation.toString could fail if the operation's partial row had not had
its full primary key filled in yet. This adds a PartialRow.toString
method which can handle any unset columns, and changes
Operation.toString to use that. Also fixes a ByteBuffer usage bug in
PartialRow::appendCellValueDebugString

Change-Id: Ife05af5a11e95751b3cc259e786d36494aeb5d3a
Reviewed-on: http://gerrit.cloudera.org:8080/5237
Reviewed-by: Jean-Daniel Cryans <jdcryans@apache.org>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/18a8a90f
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/18a8a90f
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/18a8a90f

Branch: refs/heads/master
Commit: 18a8a90f765dffde08165bc2aea2921a008ae351
Parents: f17562f
Author: yanlongzheng <yan-long.zheng@outlook.com>
Authored: Sun Nov 27 13:27:46 2016 +0000
Committer: Dan Burkert <danburkert@apache.org>
Committed: Fri Dec 9 00:00:15 2016 +0000

----------------------------------------------------------------------
 .../java/org/apache/kudu/client/Operation.java  |  4 +-
 .../java/org/apache/kudu/client/PartialRow.java | 31 +++++++++-
 .../org/apache/kudu/client/TestPartialRow.java  | 60 ++++++++++++++++++++
 3 files changed, 92 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/18a8a90f/java/kudu-client/src/main/java/org/apache/kudu/client/Operation.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/Operation.java b/java/kudu-client/src/main/java/org/apache/kudu/client/Operation.java
index 3727d5d..5d214b7 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/Operation.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/Operation.java
@@ -202,8 +202,8 @@ public abstract class Operation extends KuduRpc<OperationResponse>
{
   @Override
   public String toString() {
     StringBuilder sb = new StringBuilder(super.toString());
-    sb.append(" row_key=");
-    sb.append(row.stringifyRowKey());
+    sb.append(' ');
+    sb.append(row.toString());
     return sb.toString();
   }
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/18a8a90f/java/kudu-client/src/main/java/org/apache/kudu/client/PartialRow.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/PartialRow.java b/java/kudu-client/src/main/java/org/apache/kudu/client/PartialRow.java
index 82250cf..c53dd53 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/PartialRow.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/PartialRow.java
@@ -521,6 +521,35 @@ public class PartialRow {
     return KeyEncoder.encodePrimaryKey(this);
   }
 
+  /** {@inheritDoc} */
+  public String toString() {
+    int numCols = schema.getColumnCount();
+    StringBuilder sb = new StringBuilder();
+    sb.append('(');
+    boolean first = true;
+    for (int idx = 0; idx < numCols; ++idx) {
+      if (!columnsBitSet.get(idx)) {
+        continue;
+      }
+
+      if (first) {
+        first = false;
+      } else {
+        sb.append(", ");
+      }
+
+      ColumnSchema col = schema.getColumnByIndex(idx);
+      sb.append(col.getType().getName());
+      sb.append(' ');
+      sb.append(col.getName());
+      sb.append('=');
+
+      appendCellValueDebugString(idx, sb);
+    }
+    sb.append(')');
+    return sb.toString();
+  }
+
   /**
    * Transforms the row key into a string representation where each column is in the format:
    * "type col_name=value".
@@ -629,7 +658,7 @@ public class PartialRow {
       case STRING:
         ByteBuffer value = getVarLengthData().get(idx).duplicate();
         value.reset(); // Make sure we start at the beginning.
-        byte[] data = new byte[value.limit()];
+        byte[] data = new byte[value.limit() - value.position()];
         value.get(data);
         if (col.getType() == Type.STRING) {
           sb.append('"');

http://git-wip-us.apache.org/repos/asf/kudu/blob/18a8a90f/java/kudu-client/src/test/java/org/apache/kudu/client/TestPartialRow.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestPartialRow.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestPartialRow.java
new file mode 100644
index 0000000..9885ad2
--- /dev/null
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestPartialRow.java
@@ -0,0 +1,60 @@
+// 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.kudu.client;
+
+import static org.junit.Assert.assertEquals;
+
+import java.nio.ByteBuffer;
+
+import org.junit.Test;
+
+import org.apache.kudu.Schema;
+
+public class TestPartialRow {
+
+  @Test
+  public void testToString() {
+    Schema schema = BaseKuduTest.getSchemaWithAllTypes();
+
+    PartialRow row = schema.newPartialRow();
+    assertEquals("()", row.toString());
+
+    row.addInt("int32", 42);
+    row.addByte("int8", (byte) 42);
+
+    assertEquals("(int8 int8=42, int32 int32=42)", row.toString());
+
+    row.addString("string", "fun with ütf\0");
+    assertEquals("(int8 int8=42, int32 int32=42, string string=\"fun with ütf\\0\")",
+                 row.toString());
+
+    ByteBuffer binary = ByteBuffer.wrap(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
+    binary.position(2);
+    binary.limit(5);
+
+    row.addBinary("binary-bytebuffer", binary);
+    assertEquals("(int8 int8=42, int32 int32=42, string string=\"fun with ütf\\0\", " +
+                     "binary binary-bytebuffer=[2, 3, 4])",
+                 row.toString());
+
+    row.addDouble("double", 52.35);
+    assertEquals("(int8 int8=42, int32 int32=42, double double=52.35, " +
+                     "string string=\"fun with ütf\\0\", binary binary-bytebuffer=[2, 3,
4])",
+                 row.toString());
+  }
+}


Mime
View raw message