[ https://issues.apache.org/jira/browse/HIVE-20447?focusedWorklogId=458884&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-458884 ]
ASF GitHub Bot logged work on HIVE-20447: ----------------------------------------- Author: ASF GitHub Bot Created on: 14/Jul/20 19:25 Start Date: 14/Jul/20 19:25 Worklog Time Spent: 10m Work Description: belugabehr commented on a change in pull request #1169: URL: https://github.com/apache/hive/pull/1169#discussion_r454590457 ########## File path: beeline/src/java/org/apache/hive/beeline/JSONOutputFormat.java ########## @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * This source file is based on code taken from SQLLine 1.9 + * See SQLLine notice in LICENSE + */ +package org.apache.hive.beeline; + +import java.sql.SQLException; +import java.sql.Types; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonEncoding; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; + +/** + * OutputFormat for standard JSON format. + * + */ +public class JSONOutputFormat extends AbstractOutputFormat { + protected final BeeLine beeLine; + protected JsonGenerator generator; + + + /** + * @param beeLine + */ + JSONOutputFormat(BeeLine beeLine){ + this.beeLine = beeLine; + ByteArrayOutputStream buf = new ByteArrayOutputStream(); + try { + this.generator = new JsonFactory().createGenerator(buf, JsonEncoding.UTF8); + } catch(IOException e) { + beeLine.handleException(e); + } + } + + @Override + void printHeader(Rows.Row header) { + try { + generator.writeStartObject(); + generator.writeArrayFieldStart("resultset"); + } catch(IOException e) { + beeLine.handleException(e); + } + } + + @Override + void printFooter(Rows.Row header) { + try { + generator.writeEndArray(); + generator.writeEndObject(); + generator.flush(); + String out = ((ByteArrayOutputStream) generator.getOutputTarget()).toString("UTF-8"); + beeLine.output(out); + } catch(IOException e) { Review comment: Please clear the `ByteArrayInputStream` here otherwise it will carry around all the buffered data for a while. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 458884) Time Spent: 4h (was: 3h 50m) > Add JSON Outputformat support > ----------------------------- > > Key: HIVE-20447 > URL: https://issues.apache.org/jira/browse/HIVE-20447 > Project: Hive > Issue Type: Task > Components: Beeline > Reporter: Max Efremov > Assignee: Hunter Logan > Priority: Major > Labels: pull-request-available > Attachments: HIVE-20447.01.patch > > Time Spent: 4h > Remaining Estimate: 0h > > This function is present in SQLLine. We need add it to beeline too. > https://github.com/julianhyde/sqlline/pull/84 -- This message was sent by Atlassian Jira (v8.3.4#803005)