hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odiache...@apache.org
Subject incubator-hawq git commit: HAWQ-992. Added comments and more tests.
Date Mon, 29 Aug 2016 23:37:03 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/HAWQ-992 f7fdd2728 -> 7404083bf


HAWQ-992. Added comments and more tests.


Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/7404083b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/7404083b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/7404083b

Branch: refs/heads/HAWQ-992
Commit: 7404083bf83bed6cb62fc22a1f871d919fe0a941
Parents: f7fdd27
Author: Oleksandr Diachenko <odiachenko@pivotal.io>
Authored: Mon Aug 29 16:36:57 2016 -0700
Committer: Oleksandr Diachenko <odiachenko@pivotal.io>
Committed: Mon Aug 29 16:36:57 2016 -0700

----------------------------------------------------------------------
 .../hawq/pxf/api/utilities/EnumHawqType.java    |  3 +-
 .../hive/utilities/EnumHiveToHawqType.java      |  2 +-
 .../plugins/hive/utilities/HiveUtilities.java   |  2 +-
 .../hive/utilities/HiveUtilitiesTest.java       | 54 +++++++++++++++++-
 .../hawq/pxf/service/io/GPDBWritable.java       | 38 ++-----------
 .../hawq/pxf/service/io/GPDBWritableTest.java   | 58 ++++++++++++++++++++
 6 files changed, 117 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7404083b/pxf/pxf-api/src/main/java/org/apache/hawq/pxf/api/utilities/EnumHawqType.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-api/src/main/java/org/apache/hawq/pxf/api/utilities/EnumHawqType.java
b/pxf/pxf-api/src/main/java/org/apache/hawq/pxf/api/utilities/EnumHawqType.java
index 1187069..d9f7d28 100644
--- a/pxf/pxf-api/src/main/java/org/apache/hawq/pxf/api/utilities/EnumHawqType.java
+++ b/pxf/pxf-api/src/main/java/org/apache/hawq/pxf/api/utilities/EnumHawqType.java
@@ -57,7 +57,8 @@ public enum EnumHawqType {
     TimestampType("timestamp", DataType.TIMESTAMP),
     BoolType("bool", DataType.BOOLEAN),
     NumericType("numeric", DataType.NUMERIC, (byte) 2, false),
-    BpcharType("bpchar", DataType.BPCHAR, (byte) 1, true);
+    BpcharType("bpchar", DataType.BPCHAR, (byte) 1, true),
+    CharType("char", DataType.CHAR, (byte) 1, false);
 
     private DataType dataType;
     private String typeName;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7404083b/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/EnumHiveToHawqType.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/EnumHiveToHawqType.java
b/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/EnumHiveToHawqType.java
index f90f39a..af7f0ef 100644
--- a/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/EnumHiveToHawqType.java
+++ b/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/EnumHiveToHawqType.java
@@ -48,7 +48,7 @@ public enum EnumHiveToHawqType {
     DateType("date", EnumHawqType.DateType),
     DecimalType("decimal", EnumHawqType.NumericType, "[(,)]"),
     VarcharType("varchar", EnumHawqType.VarcharType, "[(,)]"),
-    CharType("char", EnumHawqType.BpcharType, "[(,)]"),
+    CharType("char", EnumHawqType.CharType, "[(,)]"),
     ArrayType("array", EnumHawqType.TextType, "[<,>]"),
     MapType("map", EnumHawqType.TextType, "[<,>]"),
     StructType("struct", EnumHawqType.TextType, "[<,>]"),

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7404083b/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilities.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilities.java
b/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilities.java
index 7a74ca6..6e8c315 100644
--- a/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilities.java
+++ b/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilities.java
@@ -264,7 +264,7 @@ public class HiveUtilities {
      * <li>{@code BOOLEAN -> boolean}</li>
      * <li>{@code SMALLINT -> smallint (tinyint is converted to smallint)}</li>
      * <li>{@code BIGINT -> bigint}</li>
-     * <li>{@code TIMESTAMP, TIME -> timestamp}</li>
+     * <li>{@code TIMESTAMP -> timestamp}</li>
      * <li>{@code NUMERIC -> decimal}</li>
      * <li>{@code BYTEA -> binary}</li>
      * <li>{@code INTERGER -> int}</li>

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7404083b/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilitiesTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilitiesTest.java
b/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilitiesTest.java
index 799c8be..e3db7ba 100644
--- a/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilitiesTest.java
+++ b/pxf/pxf-hive/src/test/java/org/apache/hawq/pxf/plugins/hive/utilities/HiveUtilitiesTest.java
@@ -56,7 +56,7 @@ public class HiveUtilitiesTest {
     static String[][] typesWithModifiers = {
         {"decimal(19,84)", "numeric", "19,84"},
         {"varchar(13)", "varchar", "13"},
-        {"char(40)", "bpchar", "40"},
+        {"char(40)", "char", "40"},
     };
 
     static String[][] complexTypes = {
@@ -110,7 +110,7 @@ public class HiveUtilitiesTest {
         /*
          * decimal -> numeric
          * varchar -> varchar
-         * char -> bpchar
+         * char -> char
          */
         for (String[] line: typesWithModifiers) {
             String hiveType = line[0];
@@ -127,8 +127,56 @@ public class HiveUtilitiesTest {
 
     @Test
     public void testCompatibleHiveType() {
-        String compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.SMALLINT);
+
+        String compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.BOOLEAN);
+        assertEquals(compatibleTypeName, EnumHiveToHawqType.BooleanType.getTypeName());
+
+        compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.BYTEA);
+        assertEquals(compatibleTypeName, EnumHiveToHawqType.BinaryType.getTypeName());
+
+        compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.CHAR);
+        assertEquals(compatibleTypeName, EnumHiveToHawqType.CharType.getTypeName());
+
+        compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.BIGINT);
+        assertEquals(compatibleTypeName, EnumHiveToHawqType.BigintType.getTypeName());
+
+        compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.SMALLINT);
         assertEquals(compatibleTypeName, EnumHiveToHawqType.SmallintType.getTypeName());
+
+        compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.INTEGER);
+        assertEquals(compatibleTypeName, EnumHiveToHawqType.IntType.getTypeName());
+
+        compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.TEXT);
+        assertEquals(compatibleTypeName, EnumHiveToHawqType.StringType.getTypeName());
+
+        compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.REAL);
+        assertEquals(compatibleTypeName, EnumHiveToHawqType.FloatType.getTypeName());
+
+        compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.FLOAT8);
+        assertEquals(compatibleTypeName, EnumHiveToHawqType.DoubleType.getTypeName());
+
+        compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.VARCHAR);
+        assertEquals(compatibleTypeName, EnumHiveToHawqType.VarcharType.getTypeName());
+
+        compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.DATE);
+        assertEquals(compatibleTypeName, EnumHiveToHawqType.DateType.getTypeName());
+
+        compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.TIMESTAMP);
+        assertEquals(compatibleTypeName, EnumHiveToHawqType.TimestampType.getTypeName());
+
+        compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.NUMERIC);
+        assertEquals(compatibleTypeName, EnumHiveToHawqType.DecimalType.getTypeName());
+
+        try {
+            compatibleTypeName = HiveUtilities.toCompatibleHiveType(DataType.UNSUPPORTED_TYPE);
+            fail("should fail because there is no mapped Hive type");
+        }
+        catch (UnsupportedTypeException e) {
+            String errorMsg = "Unable to find compatible Hive type for given HAWQ's type:
" + DataType.UNSUPPORTED_TYPE;
+            assertEquals(errorMsg, e.getMessage());
+        }
+
+
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7404083b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/io/GPDBWritable.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/io/GPDBWritable.java
b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/io/GPDBWritable.java
index 5bc26f1..7e374e2 100644
--- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/io/GPDBWritable.java
+++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/io/GPDBWritable.java
@@ -832,40 +832,10 @@ public class GPDBWritable implements Writable {
      * @return type name
      */
     public static String getTypeName(int oid) {
-        switch (DataType.get(oid)) {
-            case BOOLEAN:
-                return "BOOLEAN";
-            case BYTEA:
-                return "BYTEA";
-            case CHAR:
-                return "CHAR";
-            case BIGINT:
-                return "BIGINT";
-            case SMALLINT:
-                return "SMALLINT";
-            case INTEGER:
-                return "INTEGER";
-            case TEXT:
-                return "TEXT";
-            case REAL:
-                return "REAL";
-            case FLOAT8:
-                return "FLOAT8";
-            case BPCHAR:
-                return "BPCHAR";
-            case VARCHAR:
-                return "VARCHAR";
-            case DATE:
-                return "DATE";
-            case TIME:
-                return "TIME";
-            case TIMESTAMP:
-                return "TIMESTAMP";
-            case NUMERIC:
-                return "NUMERIC";
-            default:
-                return "TEXT";
-        }
+        DataType type = DataType.get(oid);
+        if (type == UNSUPPORTED_TYPE)
+            return DataType.TEXT.name();
+        return type.name();
     }
 
     /*

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/7404083b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java
b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java
index dcb89b8..7a6f0af 100644
--- a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java
+++ b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/io/GPDBWritableTest.java
@@ -21,6 +21,8 @@ package org.apache.hawq.pxf.service.io;
 
 
 import org.apache.commons.logging.Log;
+import org.apache.hawq.pxf.api.io.DataType;
+import org.apache.hawq.pxf.service.io.GPDBWritable;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -36,6 +38,7 @@ import java.io.EOFException;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -123,6 +126,61 @@ public class GPDBWritableTest {
         assertFalse(gpdbWritable.isEmpty()); // len > 0
     }
 
+    @Test
+    public void testGetType() {
+        String typeName = GPDBWritable.getTypeName(-1);
+        assertEquals(typeName, DataType.TEXT.name());
+
+        typeName = GPDBWritable.getTypeName(-7777);
+        assertEquals(typeName, DataType.TEXT.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.BOOLEAN.getOID());
+        assertEquals(typeName, DataType.BOOLEAN.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.BYTEA.getOID());
+        assertEquals(typeName, DataType.BYTEA.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.CHAR.getOID());
+        assertEquals(typeName, DataType.CHAR.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.BIGINT.getOID());
+        assertEquals(typeName, DataType.BIGINT.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.SMALLINT.getOID());
+        assertEquals(typeName, DataType.SMALLINT.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.INTEGER.getOID());
+        assertEquals(typeName, DataType.INTEGER.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.TEXT.getOID());
+        assertEquals(typeName, DataType.TEXT.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.REAL.getOID());
+        assertEquals(typeName, DataType.REAL.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.FLOAT8.getOID());
+        assertEquals(typeName, DataType.FLOAT8.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.BPCHAR.getOID());
+        assertEquals(typeName, DataType.BPCHAR.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.VARCHAR.getOID());
+        assertEquals(typeName, DataType.VARCHAR.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.DATE.getOID());
+        assertEquals(typeName, DataType.DATE.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.TIME.getOID());
+        assertEquals(typeName, DataType.TIME.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.TIMESTAMP.getOID());
+        assertEquals(typeName, DataType.TIMESTAMP.name());
+
+        typeName = GPDBWritable.getTypeName(DataType.NUMERIC.getOID());
+        assertEquals(typeName, DataType.NUMERIC.name());
+
+    }
+
 
     /*
      * helpers functions


Mime
View raw message