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. Return default empty response for patterns with no tables
Date Wed, 23 Mar 2016 22:01:17 GMT
Repository: incubator-hawq
Updated Branches:
  refs/heads/HAWQ-459 287229645 -> bb7773478


HAWQ-459. Return default empty response for patterns with no tables


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

Branch: refs/heads/HAWQ-459
Commit: bb7773478bd2ab0f1de8f5e18f8ac7a9f390a56c
Parents: 2872296
Author: Shivram Mani <shivram.mani@gmail.com>
Authored: Wed Mar 23 15:01:02 2016 -0700
Committer: Shivram Mani <shivram.mani@gmail.com>
Committed: Wed Mar 23 15:01:02 2016 -0700

----------------------------------------------------------------------
 .../pxf/plugins/hive/HiveMetadataFetcher.java   |  6 +++
 .../plugins/hive/utilities/HiveUtilities.java   |  3 +-
 .../pxf/service/MetadataResponseFormatter.java  |  3 +-
 .../service/MetadataResponseFormatterTest.java  | 42 +++++++++-----------
 4 files changed, 29 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bb777347/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/HiveMetadataFetcher.java
----------------------------------------------------------------------
diff --git a/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/HiveMetadataFetcher.java
b/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/HiveMetadataFetcher.java
index c035a55..d228ec5 100644
--- a/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/HiveMetadataFetcher.java
+++ b/pxf/pxf-hive/src/main/java/org/apache/hawq/pxf/plugins/hive/HiveMetadataFetcher.java
@@ -54,6 +54,12 @@ public class HiveMetadataFetcher extends MetadataFetcher {
     public List<Metadata> getMetadata(String pattern) throws Exception {
 
         List<Metadata.Item> tblsDesc = HiveUtilities.extractTablesFromPattern(client,
pattern);
+
+        if(tblsDesc == null || tblsDesc.isEmpty()) {
+            LOG.warn("No tables found for the given pattern: " + pattern);
+            return null;
+        }
+
         List<Metadata> metadataList = new ArrayList<Metadata>();
 
         for(Metadata.Item tblDesc: tblsDesc) {

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bb777347/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 70574a4..7dfe410 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
@@ -272,7 +272,8 @@ public class HiveUtilities {
         try {
             databases = client.getDatabases(dbPattern);
             if(databases.isEmpty()) {
-                throw new IllegalArgumentException("No database found for the given pattern");
+                LOG.warn("No database found for the given pattern: " + dbPattern);
+                return null;
             }
             for(String dbName: databases) {
                 for(String tableName: client.getTables(dbName, tablePattern)) {

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bb777347/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 04d3d79..a420ca7 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
@@ -37,6 +37,7 @@ import org.apache.hawq.pxf.api.Metadata;
 public class MetadataResponseFormatter {
 
     private static final Log LOG = LogFactory.getLog(MetadataResponseFormatter.class);
+    private static final String METADATA_DEFAULT_RESPONSE = "{\"PXFMetadata\":[]}";
 
     /**
      * Converts list of {@link Metadata} to JSON String format.
@@ -59,7 +60,7 @@ public class MetadataResponseFormatter {
     private static String metadataToJSON(List<Metadata> metadataList) throws IOException
{
 
         if (metadataList == null || metadataList.isEmpty()) {
-            throw new IllegalArgumentException("no metadata objects found - cannot serialize");
+               return METADATA_DEFAULT_RESPONSE;
         }
 
         StringBuilder result = null;

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/bb777347/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 8709879..b4583aa 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
@@ -46,11 +46,11 @@ public class MetadataResponseFormatterTest {
         metadataList.add(metadata);
 
         result = MetadataResponseFormatter.formatResponseString(metadataList);
-        String expected = "{\"PXFMetadata\":[{"
-                + "\"item\":{\"path\":\"default\",\"name\":\"table1\"},"
-                + "\"fields\":[{\"name\":\"field1\",\"type\":\"int\"},{\"name\":\"field2\",\"type\":\"text\"}]}]}";
+        StringBuilder expected = new StringBuilder("{\"PXFMetadata\":[{");
+        expected.append("\"item\":{\"path\":\"default\",\"name\":\"table1\"},")
+                .append("\"fields\":[{\"name\":\"field1\",\"type\":\"int\"},{\"name\":\"field2\",\"type\":\"text\"}]}]}");
 
-        assertEquals(expected, result);
+        assertEquals(expected.toString(), result);
     }
 
     @Test
@@ -64,11 +64,11 @@ public class MetadataResponseFormatterTest {
         metadataList.add(metadata);
 
         result = MetadataResponseFormatter.formatResponseString(metadataList);
-        String expected = "{\"PXFMetadata\":[{"
-                + "\"item\":{\"path\":\"default\",\"name\":\"table1\"},"
-                + "\"fields\":[{\"name\":\"field1\",\"type\":\"int\"},{\"name\":\"field2\",\"type\":\"text\"}]}]}";
+        StringBuilder expected = new StringBuilder("{\"PXFMetadata\":[{");
+        expected.append("\"item\":{\"path\":\"default\",\"name\":\"table1\"},")
+                .append("\"fields\":[{\"name\":\"field1\",\"type\":\"int\"},{\"name\":\"field2\",\"type\":\"text\"}]}]}");
 
-        assertEquals(expected, result);
+        assertEquals(expected.toString(), result);
     }
 
     @Test
@@ -85,27 +85,23 @@ public class MetadataResponseFormatterTest {
         metadataList.add(metadata);
 
         result = MetadataResponseFormatter.formatResponseString(metadataList);
-        String expected = "{\"PXFMetadata\":[{"
-                + "\"item\":{\"path\":\"default\",\"name\":\"table1\"},"
-                + "\"fields\":["
-                + "{\"name\":\"field1\",\"type\":\"int\"},"
-                + "{\"name\":\"field2\",\"type\":\"numeric\",\"modifiers\":[\"1349\",\"1789\"]},"
-                + "{\"name\":\"field3\",\"type\":\"char\",\"modifiers\":[\"50\"]}"
-                + "]}]}";
+        StringBuilder expected = new StringBuilder("{\"PXFMetadata\":[{");
+        expected.append("\"item\":{\"path\":\"default\",\"name\":\"table1\"},")
+                .append("\"fields\":[")
+                .append("{\"name\":\"field1\",\"type\":\"int\"},")
+                .append("{\"name\":\"field2\",\"type\":\"numeric\",\"modifiers\":[\"1349\",\"1789\"]},")
+                .append("{\"name\":\"field3\",\"type\":\"char\",\"modifiers\":[\"50\"]}")
+                .append("]}]}");
 
-        assertEquals(expected, result);
+        assertEquals(expected.toString(), result);
     }
 
     @Test
     public void formatResponseStringNull() throws Exception {
         List<Metadata> metadataList = null;
-
-        try {
-            result = MetadataResponseFormatter.formatResponseString(metadataList);
-            fail("no metadata objects found - cannot serialize");
-        } catch (IllegalArgumentException e) {
-            assertEquals("no metadata objects found - cannot serialize", e.getMessage());
-        }
+        result = MetadataResponseFormatter.formatResponseString(metadataList);
+        String expected = new String("{\"PXFMetadata\":[]}");
+        assertEquals(expected, result);
     }
 
     @Test


Mime
View raw message