hive-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (Jira)" <j...@apache.org>
Subject [jira] [Work logged] (HIVE-20447) Add JSON Outputformat support
Date Tue, 14 Jul 2020 18:00:00 GMT

     [ https://issues.apache.org/jira/browse/HIVE-20447?focusedWorklogId=458840&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-458840
]

ASF GitHub Bot logged work on HIVE-20447:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 14/Jul/20 17:59
            Start Date: 14/Jul/20 17:59
    Worklog Time Spent: 10m 
      Work Description: belugabehr commented on a change in pull request #1169:
URL: https://github.com/apache/hive/pull/1169#discussion_r454541362



##########
File path: beeline/src/java/org/apache/hive/beeline/JSONOutputFormat.java
##########
@@ -0,0 +1,129 @@
+/*
+ * 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) {
+      beeLine.handleException(e);
+    }
+  }
+
+  @Override 
+  void printRow(Rows rows, Rows.Row header, Rows.Row row) {
+    String[] head = header.values;
+    String[] vals = row.values;
+    
+    try {
+      int colCount = rows.rsMeta.getColumnCount();
+      boolean objStartFlag = true;
+
+      for (int i = 0; (i < head.length) && (i < vals.length); i++) {
+        if (objStartFlag) {
+          generator.writeStartObject();
+          objStartFlag = false;

Review comment:
       This looks a bit suspect to me.  Should be able to just put one of these before the
loop and the corresponding `writeEndObject` after the loop.
   
   ```
   final int printCount = Math.min(colCount, Math.min(head.length, vals.length));
   generator.writeStartObject();
   for (int i = 0; i < printCount; i++) {
       ...
   }
   generator.writeEndObject();
   
   ```




----------------------------------------------------------------
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:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 458840)
    Time Spent: 2.5h  (was: 2h 20m)

> 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: 2.5h
>  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)

Mime
View raw message