[
https://issues.apache.org/jira/browse/HIVE-24509?focusedWorklogId=530280&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-530280
]
ASF GitHub Bot logged work on HIVE-24509:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 02/Jan/21 21:46
Start Date: 02/Jan/21 21:46
Worklog Time Spent: 10m
Work Description: miklosgergely commented on a change in pull request
#1756:
URL: https://github.com/apache/hive/pull/1756#discussion_r550924522
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/info/desc/formatter/JsonDescTableFormatter.java
##########
@@ -0,0 +1,265 @@
+/*
+ * 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.desc.formatter;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.api.ColumnStatisticsData;
+import org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.ql.ddl.ShowUtils;
+import org.apache.hadoop.hive.ql.metadata.CheckConstraint;
+import org.apache.hadoop.hive.ql.metadata.DefaultConstraint;
+import org.apache.hadoop.hive.ql.metadata.ForeignKeyInfo;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.NotNullConstraint;
+import org.apache.hadoop.hive.ql.metadata.Partition;
+import org.apache.hadoop.hive.ql.metadata.PrimaryKeyInfo;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.metadata.UniqueConstraint;
+import org.apache.hadoop.hive.ql.metadata.formatting.MapBuilder;
+
+import java.io.DataOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Formats DESC TABLE results to json format.
+ */
+public class JsonDescTableFormatter extends DescTableFormatter {
+ private static final String COLUMN_NAME = "name";
+ private static final String COLUMN_TYPE = "type";
+ private static final String COLUMN_COMMENT = "comment";
+ private static final String COLUMN_MIN = "min";
+ private static final String COLUMN_MAX = "max";
+ private static final String COLUMN_NUM_NULLS = "numNulls";
+ private static final String COLUMN_NUM_TRUES = "numTrues";
+ private static final String COLUMN_NUM_FALSES = "numFalses";
+ private static final String COLUMN_DISTINCT_COUNT = "distinctCount";
+ private static final String COLUMN_AVG_LENGTH = "avgColLen";
+ private static final String COLUMN_MAX_LENGTH = "maxColLen";
+
+ @Override
+ public void describeTable(HiveConf conf, DataOutputStream out, String
columnPath, String tableName, Table table,
+ Partition partition, List<FieldSchema> columns, boolean isFormatted,
boolean isExtended, boolean isOutputPadded,
+ List<ColumnStatisticsObj> columnStats) throws HiveException {
+ MapBuilder builder = MapBuilder.create();
+ builder.put("columns", createColumnsInfo(columns, columnStats));
+
+ if (isExtended) {
+ addExtendedInfo(table, partition, builder);
+ }
+
+ ShowUtils.asJson(out, builder.build());
+ }
+
+ public static List<Map<String, Object>> createColumnsInfo(List<FieldSchema>
columns,
+ List<ColumnStatisticsObj> columnStatisticsList) {
+ List<Map<String, Object>> columnsInfo = 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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 530280)
Time Spent: 4.5h (was: 4h 20m)
> 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: 4.5h
> 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)