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

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

                Author: ASF GitHub Bot
            Created on: 02/Jan/21 21:44
            Start Date: 02/Jan/21 21:44
    Worklog Time Spent: 10m 
      Work Description: miklosgergely commented on a change in pull request 
#1756:
URL: https://github.com/apache/hive/pull/1756#discussion_r550924330



##########
File path: 
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/show/status/formatter/JsonShowTableStatusFormatter.java
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.
+ */
+
+package org.apache.hadoop.hive.ql.ddl.table.info.show.status.formatter;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.TableType;
+import org.apache.hadoop.hive.ql.ddl.ShowUtils;
+import 
org.apache.hadoop.hive.ql.ddl.table.info.desc.formatter.JsonDescTableFormatter;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.Partition;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.metadata.formatting.MapBuilder;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Formats SHOW TABLE STATUS commands to json format.
+ */
+public class JsonShowTableStatusFormatter extends ShowTableStatusFormatter {
+  @Override
+  public void showTableStatus(DataOutputStream out, Hive db, HiveConf conf, 
List<Table> tables, Partition partition)
+      throws HiveException {
+    List<Map<String, Object>> tableData = new ArrayList<>();
+    try {
+      for (Table table : tables) {
+        tableData.add(makeOneTableStatus(table, db, conf, partition));
+      }
+    } catch (IOException e) {
+      throw new HiveException(e);
+    }
+    ShowUtils.asJson(out, MapBuilder.create().put("tables", 
tableData).build());
+  }
+
+  private Map<String, Object> makeOneTableStatus(Table table, Hive db, 
HiveConf conf, Partition partition)
+      throws HiveException, IOException {
+    StorageInfo storageInfo = getStorageInfo(table, partition);
+
+    MapBuilder builder = MapBuilder.create();
+    builder.put("tableName", table.getTableName());
+    builder.put("ownerType", (table.getOwnerType() != null) ? 
table.getOwnerType().name() : "null");
+    builder.put("owner", table.getOwner());
+    builder.put("location", storageInfo.location);
+    builder.put("inputFormat", storageInfo.inputFormatClass);
+    builder.put("outputFormat", storageInfo.outputFormatClass);
+    builder.put("columns", 
JsonDescTableFormatter.createColumnsInfo(table.getCols(), new ArrayList<>()));
+
+    builder.put("partitioned", table.isPartitioned());
+    if (table.isPartitioned()) {
+      builder.put("partitionColumns", 
JsonDescTableFormatter.createColumnsInfo(table.getPartCols(), new 
ArrayList<>()));

Review comment:
       Fixed.




----------------------------------------------------------------
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: 530277)
    Time Spent: 4h  (was: 3h 50m)

> Move show specific codes under DDL and cut MetaDataFormatter classes to pieces
> ------------------------------------------------------------------------------
>
>                 Key: HIVE-24509
>                 URL: https://issues.apache.org/jira/browse/HIVE-24509
>             Project: Hive
>          Issue Type: Sub-task
>          Components: Hive
>            Reporter: Miklos Gergely
>            Assignee: Miklos Gergely
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 4h
>  Remaining Estimate: 0h
>
> Lot of show ... specific codes are under theĀ  
> org.apache.hadoop.hive.ql.metadata.formatting package which are used only by 
> these commands. Also the two MetaDataFormatters (JsonMetaDataFormatter, 
> TextMetaDataFormatter) are trying to do everything, while they contain a lot 
> of code duplications. Their functionalities should be put under the 
> directories of the appropriate show commands.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to