fsk119 commented on code in PR #21582:
URL: https://github.com/apache/flink/pull/21582#discussion_r1066565533


##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/operation/OperationExecutor.java:
##########
@@ -524,6 +533,47 @@ private ResultFetcher buildOkResultFetcher(OperationHandle 
handle) {
                         
TableResultInternal.TABLE_RESULT_OK.collectInternal()));
     }
 
+    public ResultFetcher callShowJobsOperation(
+            OperationHandle operationHandle, ShowJobsOperation 
showJobsOperation)
+            throws SqlExecutionException {
+        try {
+            Collection<JobStatusMessage> jobs =
+                    runClusterAction(
+                            operationHandle,
+                            clusterClient -> {
+                                try {
+                                    return clusterClient.listJobs().get();
+                                } catch (Exception e) {
+                                    throw new FlinkException(e);
+                                }
+                            });
+            List<RowData> resultRows =
+                    jobs.stream()
+                            .map(
+                                    job ->
+                                            GenericRowData.of(
+                                                    StringData.fromString(
+                                                            
job.getJobId().toString()),
+                                                    
StringData.fromString(job.getJobName()),
+                                                    StringData.fromString(
+                                                            
job.getJobState().toString()),
+                                                    
DateTimeUtils.toTimestampData(
+                                                            
job.getStartTime(), 3)))
+                            .collect(Collectors.toList());
+            return new ResultFetcher(
+                    operationHandle,
+                    ResolvedSchema.of(
+                            Column.physical(JOB_ID, DataTypes.STRING()),
+                            Column.physical(JOB_NAME, DataTypes.STRING()),
+                            Column.physical(STATUS, DataTypes.STRING()),
+                            Column.physical(
+                                    START_TIME, 
DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE())),
+                    resultRows);
+        } catch (FlinkException | RuntimeException e) {
+            throw new SqlExecutionException("Failed to list jobs in the 
cluster.", e);
+        }

Review Comment:
   Replace with 
   
   ```
    Collection<JobStatusMessage> jobs =
                   runClusterAction(
                           operationHandle,
                           clusterClient -> {
                               try {
                                   clusterClient.listJobs().get();
                               } catch (Exception e) {
                                   throw new SqlExecutionException("Failed to 
list jobs in the cluster.", e);
                               }
                           });
           List<RowData> resultRows =
                   jobs.stream()
                           .map(
                                   job ->
                                           GenericRowData.of(
                                                   
StringData.fromString(job.getJobId().toString()),
                                                   
StringData.fromString(job.getJobName()),
                                                   
StringData.fromString(job.getJobState().toString()),
                                                   
DateTimeUtils.toTimestampData(
                                                           job.getStartTime(), 
3)))
                           .collect(Collectors.toList());
           return new ResultFetcher(
                   operationHandle,
                   ResolvedSchema.of(
                           Column.physical(JOB_ID, DataTypes.STRING()),
                           Column.physical(JOB_NAME, DataTypes.STRING()),
                           Column.physical(STATUS, DataTypes.STRING()),
                           Column.physical(START_TIME, 
DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE())),
                   resultRows);
   ```
   
   We can remove the outter try-catch.



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/command/ShowJobsOperation.java:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.flink.table.operations.command;
+
+import org.apache.flink.table.operations.Operation;
+
+/** Operation to describe a SHOW JOBS statement. */
+public class ShowJobsOperation implements Operation {

Review Comment:
   Extend ShowOperation



##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/utils/Constants.java:
##########
@@ -22,9 +22,12 @@
 public class Constants {
 
     public static final String JOB_ID = "job id";
+    public static final String JOB_NAME = "job name";
+    public static final String STATUS = "status";
+    public static final String START_TIME = "start time";
     public static final String SET_KEY = "key";
     public static final String SET_VALUE = "value";
     public static final String COMPLETION_HINTS = "hints";
 

Review Comment:
   nit: I think we can remove this empty line



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to