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]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to