hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shiv...@apache.org
Subject incubator-hawq git commit: HAWQ-459. Unit tests for metadata api
Date Mon, 21 Mar 2016 21:58:59 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/HAWQ-459 c94f38aaa -> b1198ed9c


HAWQ-459. Unit tests for metadata api


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

Branch: refs/heads/HAWQ-459
Commit: b1198ed9c1edb519b5337a6272f0199183a2f83c
Parents: c94f38a
Author: Shivram Mani <shivram.mani@gmail.com>
Authored: Mon Mar 21 14:58:51 2016 -0700
Committer: Shivram Mani <shivram.mani@gmail.com>
Committed: Mon Mar 21 14:58:51 2016 -0700

----------------------------------------------------------------------
 .../plugins/hive/utilities/HiveUtilities.java   |   5 +-
 .../pxf/service/MetadataResponseFormatter.java  |  16 ---
 .../service/MetadataResponseFormatterTest.java  | 104 +++++++++++++++++--
 3 files changed, 94 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b1198ed9/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 3a3cf0f..1ac575f 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
@@ -221,16 +221,13 @@ public class HiveUtilities {
      * or when querying HCatalog table.
      * It can be either <code>table_name_pattern</code> or <code>db_name_pattern.table_name_pattern</code>.
      *
+     * @param client Hivemetastore client
      * @param pattern Hive table name or pattern
      * @return {@link Metadata.Item} object holding the full table name
      */
     public static List<Metadata.Item> extractTablesFromPattern(HiveMetaStoreClient
client, String pattern) {
 
-
         String dbPattern, tablePattern;
-
-        System.out.println(pattern);
-
         String errorMsg = " is not a valid Hive table name. "
                 + "Should be either <table_name> or <db_name.table_name>";
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b1198ed9/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/MetadataResponseFormatter.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/MetadataResponseFormatter.java
b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/MetadataResponseFormatter.java
index cb69f94..444e2e1 100644
--- a/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/MetadataResponseFormatter.java
+++ b/pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/MetadataResponseFormatter.java
@@ -39,19 +39,6 @@ public class MetadataResponseFormatter {
     private static final Log LOG = LogFactory.getLog(MetadataResponseFormatter.class);
 
     /**
-     * Converts {@link Metadata} to JSON String format.
-     *
-     * @param metadata metadata objects to convert
-     * @return JSON formatted response
-     * @throws IOException if converting the data to JSON fails
-     */
-    public static String formatResponseString(Metadata metadata) throws IOException {
-        List<Metadata> metadataList = new ArrayList<Metadata>();
-        metadataList.add(metadata);
-        return formatResponseString(metadataList);
-    }
-
-    /**
      * Converts list of {@link Metadata} to JSON String format.
      *
      * @param metadataList list of metadata objects to convert
@@ -59,9 +46,6 @@ public class MetadataResponseFormatter {
      * @throws IOException if converting the data to JSON fails
      */
     public static String formatResponseString(List<Metadata> metadataList) throws IOException
{
-        /* print the metadata before serialization */
-        LOG.debug(MetadataResponseFormatter.metadataToString(metadataList));
-
         return MetadataResponseFormatter.metadataToJSON(metadataList);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/b1198ed9/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/MetadataResponseFormatterTest.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/MetadataResponseFormatterTest.java
b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/MetadataResponseFormatterTest.java
index bea8067..40a0896 100644
--- a/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/MetadataResponseFormatterTest.java
+++ b/pxf/pxf-service/src/test/java/org/apache/hawq/pxf/service/MetadataResponseFormatterTest.java
@@ -25,6 +25,8 @@ import static org.junit.Assert.*;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.directory.shared.kerberos.components.MethodData;
 import org.junit.Test;
 
 import org.apache.hawq.pxf.api.Metadata;
@@ -35,13 +37,15 @@ public class MetadataResponseFormatterTest {
 
     @Test
     public void formatResponseString() throws Exception {
+        List<Metadata> metadataList = new ArrayList<Metadata>();
         List<Metadata.Field> fields = new ArrayList<Metadata.Field>();
         Metadata.Item itemName = new Metadata.Item("default", "table1");
         Metadata metadata = new Metadata(itemName, fields);
         fields.add(new Metadata.Field("field1", "int"));
         fields.add(new Metadata.Field("field2", "text"));
+        metadataList.add(metadata);
 
-        result = MetadataResponseFormatter.formatResponseString(metadata);
+        result = MetadataResponseFormatter.formatResponseString(metadataList);
         String expected = "{\"PXFMetadata\":[{"
                 + "\"item\":{\"path\":\"default\",\"name\":\"table1\"},"
                 + "\"fields\":[{\"name\":\"field1\",\"type\":\"int\"},{\"name\":\"field2\",\"type\":\"text\"}]}]}";
@@ -51,13 +55,15 @@ public class MetadataResponseFormatterTest {
 
     @Test
     public void formatResponseStringWithNullModifier() throws Exception {
+        List<Metadata> metadataList = new ArrayList<Metadata>();
         List<Metadata.Field> fields = new ArrayList<Metadata.Field>();
         Metadata.Item itemName = new Metadata.Item("default", "table1");
         Metadata metadata = new Metadata(itemName, fields);
         fields.add(new Metadata.Field("field1", "int", null));
         fields.add(new Metadata.Field("field2", "text", new String[] {}));
+        metadataList.add(metadata);
 
-        result = MetadataResponseFormatter.formatResponseString(metadata);
+        result = MetadataResponseFormatter.formatResponseString(metadataList);
         String expected = "{\"PXFMetadata\":[{"
                 + "\"item\":{\"path\":\"default\",\"name\":\"table1\"},"
                 + "\"fields\":[{\"name\":\"field1\",\"type\":\"int\"},{\"name\":\"field2\",\"type\":\"text\"}]}]}";
@@ -67,6 +73,7 @@ public class MetadataResponseFormatterTest {
 
     @Test
     public void formatResponseStringWithModifiers() throws Exception {
+        List<Metadata> metadataList = new ArrayList<Metadata>();
         List<Metadata.Field> fields = new ArrayList<Metadata.Field>();
         Metadata.Item itemName = new Metadata.Item("default", "table1");
         Metadata metadata = new Metadata(itemName, fields);
@@ -75,8 +82,9 @@ public class MetadataResponseFormatterTest {
                 new String[] {"1349", "1789"}));
         fields.add(new Metadata.Field("field3", "char",
                 new String[] {"50"}));
+        metadataList.add(metadata);
 
-        result = MetadataResponseFormatter.formatResponseString(metadata);
+        result = MetadataResponseFormatter.formatResponseString(metadataList);
         String expected = "{\"PXFMetadata\":[{"
                 + "\"item\":{\"path\":\"default\",\"name\":\"table1\"},"
                 + "\"fields\":["
@@ -90,37 +98,111 @@ public class MetadataResponseFormatterTest {
 
     @Test
     public void formatResponseStringNull() throws Exception {
-        Metadata metadata = null;
+        List<Metadata> metadataList = null;
 
         try {
-            result = MetadataResponseFormatter.formatResponseString(metadata);
-            fail("formatting should fail because metadata is null");
+            result = MetadataResponseFormatter.formatResponseString(metadataList);
+            fail("no metadata objects found - cannot serialize");
         } catch (IllegalArgumentException e) {
-            assertEquals("metadata object is null - cannot serialize", e.getMessage());
+            assertEquals("no metadata objects found - cannot serialize", e.getMessage());
         }
     }
 
     @Test
     public void formatResponseStringNoFields() throws Exception {
+        List<Metadata> metadataList = new ArrayList<Metadata>();
         Metadata.Item itemName = new Metadata.Item("default", "table1");
         Metadata metadata = new Metadata(itemName, null);
-
+        metadataList.add(metadata);
         try {
-            result = MetadataResponseFormatter.formatResponseString(metadata);
+            result = MetadataResponseFormatter.formatResponseString(metadataList);
             fail("formatting should fail because fields field is null");
         } catch (IllegalArgumentException e) {
             assertEquals("metadata contains no fields - cannot serialize", e.getMessage());
         }
 
         ArrayList<Metadata.Field> fields = new ArrayList<Metadata.Field>();
+        metadataList = new ArrayList<Metadata>();
         metadata = new Metadata(itemName, fields);
-
+        metadataList.add(metadata);
         try {
-            result = MetadataResponseFormatter.formatResponseString(metadata);
+            result = MetadataResponseFormatter.formatResponseString(metadataList);
             fail("formatting should fail because there are no fields");
         } catch (IllegalArgumentException e) {
             assertEquals("metadata contains no fields - cannot serialize", e.getMessage());
         }
     }
+
+    @Test
+    public void formatResponseStringPartialNull() throws Exception {
+        List<Metadata> metadataList = new ArrayList<Metadata>();
+        List<Metadata.Field> fields = new ArrayList<Metadata.Field>();
+        Metadata.Item itemName = new Metadata.Item("default", "table1");
+        Metadata metadata = new Metadata(itemName, fields);
+        fields.add(new Metadata.Field("field1", "int"));
+        metadataList.add(null);
+        metadataList.add(metadata);
+        try {
+            result = MetadataResponseFormatter.formatResponseString(metadataList);
+            fail("formatting should fail because one of the metdata object is null");
+        } catch (IllegalArgumentException e) {
+            assertEquals("metadata object is null - cannot serialize", e.getMessage());
+        }
+    }
+
+    @Test
+    public void formatResponseStringWithMultipleItems() throws Exception {
+        List <Metadata> metdataList = new ArrayList<Metadata>();
+        for (int i=1; i<=10; i++) {
+            List<Metadata.Field> fields = new ArrayList<Metadata.Field>();
+            Metadata.Item itemName = new Metadata.Item("default", "table"+i);
+            Metadata metadata = new Metadata(itemName, fields);
+            fields.add(new Metadata.Field("field1", "int"));
+            fields.add(new Metadata.Field("field2", "text"));
+            metdataList.add(metadata);
+        }
+        result = MetadataResponseFormatter.formatResponseString(metdataList);
+
+        StringBuilder expected = new StringBuilder();
+        for (int i=1; i<=10; i++) {
+            if(i==1) {
+                expected.append("{\"PXFMetadata\":[");
+            } else {
+                expected.append(",");
+            }
+            expected.append("{\"item\":{\"path\":\"default\",\"name\":\"table").append(i).append("\"},");
+            expected.append("\"fields\":[{\"name\":\"field1\",\"type\":\"int\"},{\"name\":\"field2\",\"type\":\"text\"}]}");
+        }
+        expected.append("]}");
+
+        assertEquals(expected.toString(), result);
+    }
+
+    @Test
+    public void formatResponseStringWithMultiplePathsAndItems() throws Exception {
+        List <Metadata> metdataList = new ArrayList<Metadata>();
+        for (int i=1; i<=10; i++) {
+            List<Metadata.Field> fields = new ArrayList<Metadata.Field>();
+            Metadata.Item itemName = new Metadata.Item("default"+i, "table"+i);
+            Metadata metadata = new Metadata(itemName, fields);
+            fields.add(new Metadata.Field("field1", "int"));
+            fields.add(new Metadata.Field("field2", "text"));
+            metdataList.add(metadata);
+        }
+        result = MetadataResponseFormatter.formatResponseString(metdataList);
+        StringBuilder expected = new StringBuilder();
+        for (int i=1; i<=10; i++) {
+            if(i==1) {
+                expected.append("{\"PXFMetadata\":[");
+            } else {
+                expected.append(",");
+            }
+            expected.append("{\"item\":{\"path\":\"default").append(i).append("\",\"name\":\"table").append(i).append("\"},");
+            expected.append("\"fields\":[{\"name\":\"field1\",\"type\":\"int\"},{\"name\":\"field2\",\"type\":\"text\"}]}");
+        }
+        expected.append("]}");
+
+        assertEquals(expected.toString(), result);
+    }
 }
 


Mime
View raw message