hawq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GodenYao <...@git.apache.org>
Subject [GitHub] incubator-hawq pull request: HAWQ 459 Enhanced metadata api to sup...
Date Tue, 22 Mar 2016 17:56:47 GMT
Github user GodenYao commented on a diff in the pull request:

    https://github.com/apache/incubator-hawq/pull/477#discussion_r57036585
  
    --- Diff: pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/MetadataResponseFormatter.java
---
    @@ -55,50 +54,65 @@ public static String formatResponseString(Metadata metadata) throws
IOException
          * To be used as the result string for HAWQ.
          * An example result is as follows:
          *
    -     * {"PXFMetadata":[{"table":{"dbName":"default","tableName":"t1"},"fields":[{"name":"a","type":"int"},{"name":"b","type":"float"}]}]}
    +     * {"PXFMetadata":[{"item":{"path":"default","name":"t1"},"fields":[{"name":"a","type":"int"},{"name":"b","type":"float"}]}]}
          */
    -    private static String metadataToJSON(Metadata metadata) throws IOException {
    +    private static String metadataToJSON(List<Metadata> metadataList) throws IOException
{
     
    -        if (metadata == null) {
    -            throw new IllegalArgumentException("metadata object is null - cannot serialize");
    +        if (metadataList == null || metadataList.isEmpty()) {
    +            throw new IllegalArgumentException("no metadata objects found - cannot serialize");
             }
     
    -        if ((metadata.getFields() == null) || metadata.getFields().isEmpty()) {
    -            throw new IllegalArgumentException("metadata contains no fields - cannot
serialize");
    +        StringBuilder result = null;
    +
    +        for(Metadata metadata: metadataList) {
    +            if(metadata == null) {
    +                throw new IllegalArgumentException("metadata object is null - cannot
serialize");
    +            }
    +            if ((metadata.getFields() == null) || metadata.getFields().isEmpty()) {
    +                throw new IllegalArgumentException("metadata contains no fields - cannot
serialize");
    +            }
    +            if (result == null) {
    +                result = new StringBuilder("{\"PXFMetadata\":["); /* prefix info */
    +            } else {
    +                result.append(",");
    +            }
    +
    +            ObjectMapper mapper = new ObjectMapper();
    +            mapper.setSerializationInclusion(Inclusion.NON_EMPTY); // ignore empty fields
    +            result.append(mapper.writeValueAsString(metadata));
             }
     
    -        ObjectMapper mapper = new ObjectMapper();
    -        mapper.setSerializationInclusion(Inclusion.NON_EMPTY); // ignore empty fields
    +        return result.append("]}").toString(); /* append suffix info */
     
    -        StringBuilder result = new StringBuilder("{\"PXFMetadata\":");
    -        String prefix = "["; // preparation for supporting multiple tables
    -        result.append(prefix).append(mapper.writeValueAsString(metadata));
    -        return result.append("]}").toString();
         }
     
         /**
    -     * Converts metadata to a readable string.
    +     * Converts metadata list to a readable string.
          * Intended for debugging purposes only.
          */
    -    private static String metadataToString(Metadata metadata) {
    -        StringBuilder result = new StringBuilder("Metadata for table \"");
    +    private static String metadataToString(List<Metadata> metadataList) {
    +        StringBuilder result = new StringBuilder("Metadata:");
     
    -        if (metadata == null) {
    -            return "No metadata";
    -        }
    +        for(Metadata metadata: metadataList) {
    +            result.append(" Metadata for item \"");
    --- End diff --
    
    remove leading space.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message