[ https://issues.apache.org/jira/browse/HAWQ-577?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15215122#comment-15215122 ]
ASF GitHub Bot commented on HAWQ-577: ------------------------------------- Github user hornn commented on a diff in the pull request: https://github.com/apache/incubator-hawq/pull/522#discussion_r57654541 --- Diff: pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/MetadataResponseFormatter.java --- @@ -46,76 +45,50 @@ * @return JSON formatted response * @throws IOException if converting the data to JSON fails */ - public static String formatResponseString(List<Metadata> metadataList) throws IOException { - return MetadataResponseFormatter.metadataToJSON(metadataList); - } - - /** - * Serializes a metadata in JSON, - * To be used as the result string for HAWQ. - * An example result is as follows: - * - * {"PXFMetadata":[{"item":{"path":"default","name":"t1"},"fields":[{"name":"a","type":"int"},{"name":"b","type":"float"}]}]} - */ - private static String metadataToJSON(List<Metadata> metadataList) throws IOException { - - if (metadataList == null || metadataList.isEmpty()) { - return METADATA_DEFAULT_RESPONSE; + public static MetadataResponse formatResponse(List<Metadata> metadataList, String path) throws IOException { + /* print the fragment list to log when in debug level */ + if (LOG.isDebugEnabled()) { + MetadataResponseFormatter.printMetadata(metadataList, path); } - 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 for " + metadata.getItem() + " 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)); - } - - return result.append("]}").toString(); /* append suffix info */ - + return new MetadataResponse(metadataList); } /** * Converts metadata list to a readable string. * Intended for debugging purposes only. */ - private static String metadataToString(List<Metadata> metadataList) { - StringBuilder result = new StringBuilder("Metadata:"); + private static void printMetadata(List<Metadata> metadataList, String path) { + LOG.debug("Metadata List for path " + path + ": "); + + if (null == metadataList || metadataList.isEmpty()) { + LOG.debug("No metadata"); + return; + } for(Metadata metadata: metadataList) { - result.append(" Metadata for item \""); + StringBuilder result = new StringBuilder(); + result.append("Metadata for item \""); --- End diff -- the quotes are not closed for the case of null metadata. perhaps move `\"` to be part of line 79. > Stream PXF metadata response > ----------------------------- > > Key: HAWQ-577 > URL: https://issues.apache.org/jira/browse/HAWQ-577 > Project: Apache HAWQ > Issue Type: Bug > Components: PXF > Reporter: Shivram Mani > Assignee: Shivram Mani > > getMetadata api returns the metadata corresponding to the user specified > pattern. There is no limit to the #of tables the pattern can correspond do > and the current approach of building in memory the json object might not > scale. > We needed to serialize them inside a streaming object similar to the approach > used for streaming the FragmentsResponse > The same applies also for the debug function that prints metadata of all the > items - if there are too many of them the StringBuilder will run out of > memory. The solution in the fragments case was to print a log of one fragment > at a time. -- This message was sent by Atlassian JIRA (v6.3.4#6332)