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

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

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



##########
File path: beeline/src/java/org/apache/hive/beeline/JSONOutputFormat.java
##########
@@ -0,0 +1,113 @@
+/*
+ * 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();
+      beeLine.output(generator.getOutputTarget().toString());
+      generator.flush();
+    } 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{
+      for (int i = 0; (i < head.length) && (i < vals.length); i++) {
+        generator.writeFieldName(head[i]);
+        switch(rows.rsMeta.getColumnType(i)) {
+          case Types.TINYINT:
+          case Types.SMALLINT:
+          case Types.INTEGER:
+          case Types.BIGINT:
+          case Types.REAL:
+          case Types.FLOAT:
+          case Types.DOUBLE:
+          case Types.DECIMAL:
+          case Types.NUMERIC:
+            generator.writeNumber(vals[i]);
+            break;
+          case Types.NULL:
+            generator.writeNull();
+            break;
+          case Types.BOOLEAN:
+            generator.writeBoolean(vals[i].equalsIgnoreCase("true"));

Review comment:
       Take a look at using `Boolean#parse` instead:
   
   
https://docs.oracle.com/javase/8/docs/api/java/lang/Boolean.html#parseBoolean-java.lang.String-




----------------------------------------------------------------
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: 456188)
    Time Spent: 2h 10m  (was: 2h)

> 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: 2h 10m
>  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)

Reply via email to