dengzhhu653 commented on code in PR #5319:
URL: https://github.com/apache/hive/pull/5319#discussion_r1749996979


##########
ql/src/java/org/apache/hadoop/hive/ql/processors/ShowProcesslistProcessor.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.processors;
+
+import com.google.common.base.Joiner;
+import org.apache.hadoop.hive.metastore.api.FieldSchema;
+import org.apache.hadoop.hive.metastore.api.Schema;
+import org.apache.hadoop.hive.ql.session.ProcessListInfo;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+import static 
org.apache.hadoop.hive.serde.serdeConstants.SERIALIZATION_NULL_FORMAT;
+import static 
org.apache.hadoop.hive.serde2.MetadataTypedColumnsetSerDe.defaultNullString;
+
+/**
+ * List operations/queries being performed in sessions within hiveserver2
+ */
+public class ShowProcesslistProcessor implements CommandProcessor{
+  private static final Logger LOG = 
LoggerFactory.getLogger(ShowProcesslistProcessor.class.getName());
+  private static final SessionState.LogHelper console = new 
SessionState.LogHelper(LOG);
+  private List<ProcessListInfo> liveQueries = null;
+
+  public void setup(List<ProcessListInfo> liveQueries) {
+    this.liveQueries = liveQueries;
+  }
+
+  /**
+   * Creates a Schema object with running operation details
+   * @return
+   */
+  private Schema getSchema(){
+    Schema sch = new Schema();
+    sch.addToFieldSchemas(new FieldSchema("User Name", "string", ""));
+    sch.addToFieldSchemas(new FieldSchema("Ip Addr", "string", ""));
+    sch.addToFieldSchemas(new FieldSchema("Execution Engine", "string", ""));
+    sch.addToFieldSchemas(new FieldSchema("Session Id", "string", ""));
+    sch.addToFieldSchemas(new FieldSchema("Session Active Time (s)", "string", 
""));
+    sch.addToFieldSchemas(new FieldSchema("Session Idle Time (s)", "string", 
""));
+    sch.addToFieldSchemas(new FieldSchema("Query ID", "string", ""));
+    sch.addToFieldSchemas(new FieldSchema("State", "string", ""));
+    sch.addToFieldSchemas(new FieldSchema("Opened Timestamp", "string", ""));
+    sch.addToFieldSchemas(new FieldSchema("Elapsed Time (s)", "string", ""));
+    sch.addToFieldSchemas(new FieldSchema("Runtime (s)", "string", ""));
+    sch.putToProperties(SERIALIZATION_NULL_FORMAT, defaultNullString);
+    return sch;
+  }
+
+  @Override
+  public CommandProcessorResponse run(String command) throws 
CommandProcessorException {
+    try {
+      String[] tokens = command.split("\\s+");
+      boolean isCorrectSubCommand = 
"processlist".equalsIgnoreCase(tokens[0].toLowerCase());
+
+      if (tokens.length != 1 || ! isCorrectSubCommand) {
+        throw new CommandProcessorException("ShowProcessList Processor Failed: 
Unsupported sub-command option");
+      }
+      // TODO : Authorization?
+      if (liveQueries == null || liveQueries.isEmpty()) {
+        return new CommandProcessorResponse(getSchema(),"No queries running 
currently");
+      }
+      SessionState ss = SessionState.get();
+      liveQueries.forEach (query -> {
+            ss.out.println(
+                Joiner.on("\t").join(
+                    query.getUserName(),
+                    query.getIpAddr(),
+                    query.getExecutionEngine(),
+                    query.getSessionId(),
+                    query.getSessionActiveTime(),
+                    query.getSessionIdleTime(),
+                    query.getQueryId(),
+                    query.getState(),
+                    query.getBeginTime(),
+                    query.getElapsedTime(),
+                    query.getRuntime()
+                ));
+          }
+      );
+      return new CommandProcessorResponse(getSchema(), null);

Review Comment:
   how does the client get the result since the message is `null`?



-- 
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.

To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to