kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpe...@apache.org
Subject kudu git commit: [java] Fix ColumnSchema.toString NPE
Date Tue, 08 May 2018 20:48:04 GMT
Repository: kudu
Updated Branches:
  refs/heads/branch-1.7.x fb4bc2f64 -> 305862f9e


[java] Fix ColumnSchema.toString NPE

ColumnSchema#toString throws an NPE on
non-decimal types because the TypeAttributes are
null. This patch fixes the issue and adds a test.

Change-Id: I0a240088fd52891f11f2090d8c457c19e784b7de
Reviewed-on: http://gerrit.cloudera.org:8080/10344
Reviewed-by: Todd Lipcon <todd@apache.org>
Tested-by: Grant Henke <granthenke@apache.org>


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

Branch: refs/heads/branch-1.7.x
Commit: 305862f9ef3cefa52eedca91ac35f3f6ce02d552
Parents: fb4bc2f
Author: Grant Henke <granthenke@apache.org>
Authored: Tue May 8 10:35:21 2018 -0500
Committer: Grant Henke <granthenke@apache.org>
Committed: Tue May 8 20:28:21 2018 +0000

----------------------------------------------------------------------
 .../main/java/org/apache/kudu/ColumnSchema.java | 10 ++++-
 .../java/org/apache/kudu/TestColumnSchema.java  | 39 ++++++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/305862f9/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java b/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java
index 17dec97..3072076 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/ColumnSchema.java
@@ -223,7 +223,15 @@ public class ColumnSchema {
 
   @Override
   public String toString() {
-    return "Column name: " + name + ", type: " + type.getName() + typeAttributes.toStringForType(type);
+    StringBuilder sb = new StringBuilder();
+    sb.append("Column name: ");
+    sb.append(name);
+    sb.append(", type: ");
+    sb.append(type.getName());
+    if (typeAttributes != null) {
+      sb.append(typeAttributes.toStringForType(type));
+    }
+    return sb.toString();
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/kudu/blob/305862f9/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java b/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java
new file mode 100644
index 0000000..d2d0710
--- /dev/null
+++ b/java/kudu-client/src/test/java/org/apache/kudu/TestColumnSchema.java
@@ -0,0 +1,39 @@
+// 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;
+
+import org.apache.kudu.ColumnSchema.ColumnSchemaBuilder;
+import org.apache.kudu.util.DecimalUtil;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestColumnSchema {
+
+  @Test
+  public void testToString() {
+    ColumnSchema col1 = new ColumnSchemaBuilder("col1", Type.STRING).build();
+    ColumnSchema col2 = new ColumnSchemaBuilder("col2", Type.INT64).build();
+    ColumnSchema col3 = new ColumnSchemaBuilder("col3", Type.DECIMAL)
+        .typeAttributes(DecimalUtil.typeAttributes(5, 2))
+        .build();
+
+    assertEquals("Column name: col1, type: string", col1.toString());
+    assertEquals("Column name: col2, type: int64", col2.toString());
+    assertEquals("Column name: col3, type: decimal(5, 2)", col3.toString());
+  }
+}


Mime
View raw message