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

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


View the commit online:
https://github.com/apache/kudu/commit/c8409bbdab8d36d6d864ea16a329569414340f0e

The following commit(s) were added to refs/heads/master by this push:
     new c8409bb  [Java] Fixed Type.getTypeForName method.
c8409bb is described below

commit c8409bbdab8d36d6d864ea16a329569414340f0e
Author: Michele Milesi <[email protected]>
AuthorDate: Mon Nov 18 18:12:43 2019 +0100

    [Java] Fixed Type.getTypeForName method.
    
    Original version uses only name() method to check Type name.
    Output from name() (inerrithed from Enum) method was different
    from output from Type.getName() method (ie INT32 vs int32),
    so the check fails.
    
    Now the method uses both getName() and name() to check Type name.
    
    Change-Id: Ibd0f4f614125d630d128c36fce05f22e19c60100
    Reviewed-on: http://gerrit.cloudera.org:8080/14736
    Tested-by: Kudu Jenkins
    Reviewed-by: Grant Henke <[email protected]>
---
 .../src/main/java/org/apache/kudu/Type.java        | 10 ++++-
 .../src/test/java/org/apache/kudu/TestType.java    | 44 ++++++++++++++++++++++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/java/kudu-client/src/main/java/org/apache/kudu/Type.java 
b/java/kudu-client/src/main/java/org/apache/kudu/Type.java
index 6d31910..16b7726 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/Type.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/Type.java
@@ -194,9 +194,17 @@ public enum Type {
     }
   }
 
+  /**
+   * Create a Type from its name
+   * @param name The DataType name. It accepts Type name (from the getName()
+   * method) and ENUM name (from the name() method).
+   * @throws IllegalArgumentException if the provided name doesn't map to any
+   * known type.
+   * @return a matching Type.
+   */
   public static Type getTypeForName(String name) {
     for (Type t : values()) {
-      if (t.name().equals(name)) {
+      if (t.name().equals(name) || t.getName().equals(name)) {
         return t;
       }
     }
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/TestType.java 
b/java/kudu-client/src/test/java/org/apache/kudu/TestType.java
new file mode 100644
index 0000000..0c4f65e
--- /dev/null
+++ b/java/kudu-client/src/test/java/org/apache/kudu/TestType.java
@@ -0,0 +1,44 @@
+// 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 static org.junit.Assert.assertEquals;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import org.apache.kudu.test.junit.RetryRule;
+
+public class TestType {
+
+  @Rule
+  public RetryRule retryRule = new RetryRule();
+
+  @Test
+  public void testGetTypeForName() {
+    String name = Type.INT64.getName();
+    Type newType = Type.getTypeForName(name);
+
+    assertEquals("Get Type from getName()", Type.INT64, newType);
+
+    name = Type.INT64.name();
+    newType = Type.getTypeForName(name);
+
+    assertEquals("Get Type from name()", Type.INT64, newType);
+  }
+}

Reply via email to