kgyrtkirk commented on a change in pull request #543: HIVE-21292: Break up 
DDLTask 1 - extract Database related operations
URL: https://github.com/apache/hive/pull/543#discussion_r259295178
 
 

 ##########
 File path: 
ql/src/java/org/apache/hadoop/hive/ql/exec/ddl/database/ShowDatabasesOperation.java
 ##########
 @@ -0,0 +1,58 @@
+/*
+ * 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.exec.ddl.database;
+
+import java.io.DataOutputStream;
+import java.util.List;
+
+import org.apache.hadoop.hive.ql.ErrorMsg;
+import org.apache.hadoop.hive.ql.exec.ddl.DDLOperation;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.io.IOUtils;
+
+/**
+ * Operation process of locking a database.
+ */
+public class ShowDatabasesOperation extends DDLOperation<ShowDatabasesDesc> {
+  @Override
+  public int execute() throws HiveException {
+    // get the databases for the desired pattern - populate the output stream
+    List<String> databases = null;
+    if (ddlDesc.getPattern() != null) {
+      LOG.debug("pattern: {}", ddlDesc.getPattern());
+      databases = db.getDatabasesByPattern(ddlDesc.getPattern());
+    } else {
+      databases = db.getAllDatabases();
+    }
+
+    LOG.info("Found {} database(s) matching the SHOW DATABASES statement.", 
databases.size());
+
+    // write the results in the file
+    DataOutputStream outStream = getOutputStream(ddlDesc.getResFile());
+    try {
+      formatter.showDatabases(outStream, databases);
 
 Review comment:
   there seems to be a `formatter` for each of these operations; I guess there 
are less formatter than operations; but I think the formatters should also 
"find" a new home

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


With regards,
Apache Git Services

Reply via email to