[
https://issues.apache.org/jira/browse/HIVE-24509?focusedWorklogId=530267&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-530267
]
ASF GitHub Bot logged work on HIVE-24509:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 02/Jan/21 21:36
Start Date: 02/Jan/21 21:36
Worklog Time Spent: 10m
Work Description: miklosgergely commented on a change in pull request
#1756:
URL: https://github.com/apache/hive/pull/1756#discussion_r550923722
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/ddl/database/show/ShowDatabasesFormatter.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.database.show;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.ddl.ShowUtils;
+import org.apache.hadoop.hive.ql.exec.Utilities;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.formatting.MapBuilder;
+import org.apache.hadoop.hive.ql.metadata.formatting.MetaDataFormatUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * Formats SHOW DATABASES results.
+ */
+abstract class ShowDatabasesFormatter {
+ static ShowDatabasesFormatter getFormatter(HiveConf conf) {
+ if (MetaDataFormatUtils.isJson(conf)) {
+ return new JsonShowDatabasesFormatter();
+ } else {
+ return new TextShowDatabasesFormatter();
+ }
+ }
+
+ abstract void showDatabases(DataOutputStream out, List<String> databases)
throws HiveException;
+
+ // ------ Implementations ------
+
+ static class JsonShowDatabasesFormatter extends ShowDatabasesFormatter {
+ @Override
+ void showDatabases(DataOutputStream out, List<String> databases) throws
HiveException {
+ ShowUtils.asJson(out, MapBuilder.create().put("databases",
databases).build());
+ }
+ }
+
+ static class TextShowDatabasesFormatter extends ShowDatabasesFormatter {
+ @Override
+ void showDatabases(DataOutputStream out, List<String> databases) throws
HiveException {
+ try {
+ for (String database : databases) {
+ out.write(database.getBytes("UTF-8"));
Review comment:
Fixed.
##########
File path:
ql/src/java/org/apache/hadoop/hive/ql/ddl/database/desc/DescDatabaseFormatter.java
##########
@@ -0,0 +1,115 @@
+/*
+ * 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.database.desc;
+
+import org.apache.commons.collections.MapUtils;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.api.PrincipalType;
+import org.apache.hadoop.hive.ql.ddl.ShowUtils;
+import org.apache.hadoop.hive.ql.exec.Utilities;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.metadata.formatting.MapBuilder;
+import org.apache.hadoop.hive.ql.metadata.formatting.MetaDataFormatUtils;
+import org.apache.hive.common.util.HiveStringUtils;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * Formats DESC DATABASES results.
+ */
+abstract class DescDatabaseFormatter {
+ static DescDatabaseFormatter getFormatter(HiveConf conf) {
+ if (MetaDataFormatUtils.isJson(conf)) {
+ return new JsonDescDatabaseFormatter();
+ } else {
+ return new TextDescDatabaseFormatter();
+ }
+ }
+
+ abstract void showDatabaseDescription(DataOutputStream out, String database,
String comment, String location,
+ String managedLocation, String ownerName, PrincipalType ownerType,
Map<String, String> params)
+ throws HiveException;
+
+ // ------ Implementations ------
+
+ static class JsonDescDatabaseFormatter extends DescDatabaseFormatter {
+ @Override
+ void showDatabaseDescription(DataOutputStream out, String database, String
comment, String location,
+ String managedLocation, String ownerName, PrincipalType ownerType,
Map<String, String> params)
+ throws HiveException {
+ MapBuilder builder = MapBuilder.create()
+ .put("database", database)
+ .put("comment", comment)
+ .put("location", location);
+ if (managedLocation != null) {
+ builder.put("managedLocation", managedLocation);
+ }
+ if (ownerName != null) {
+ builder.put("owner", ownerName);
+ }
+ if (ownerType != null) {
+ builder.put("ownerType", ownerType.name());
+ }
+ if (MapUtils.isNotEmpty(params)) {
+ builder.put("params", params);
+ }
+ ShowUtils.asJson(out, builder.build());
+ }
+ }
+
+ static class TextDescDatabaseFormatter extends DescDatabaseFormatter {
+ @Override
+ void showDatabaseDescription(DataOutputStream out, String database, String
comment, String location,
+ String managedLocation, String ownerName, PrincipalType ownerType,
Map<String, String> params)
+ throws HiveException {
+ try {
+ out.write(database.getBytes("UTF-8"));
+ out.write(Utilities.tabCode);
+ if (comment != null) {
+ out.write(HiveStringUtils.escapeJava(comment).getBytes("UTF-8"));
+ }
+ out.write(Utilities.tabCode);
+ if (location != null) {
+ out.write(location.getBytes("UTF-8"));
+ }
+ out.write(Utilities.tabCode);
+ if (managedLocation != null) {
+ out.write(managedLocation.getBytes("UTF-8"));
+ }
+ out.write(Utilities.tabCode);
+ if (ownerName != null) {
+ out.write(ownerName.getBytes("UTF-8"));
+ }
+ out.write(Utilities.tabCode);
+ if (ownerType != null) {
+ out.write(ownerType.name().getBytes("UTF-8"));
+ }
+ out.write(Utilities.tabCode);
+ if (MapUtils.isNotEmpty(params)) {
+ out.write(params.toString().getBytes("UTF-8"));
+ }
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: 530267)
Time Spent: 2.5h (was: 2h 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: 2.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)