hackergin commented on code in PR #25988:
URL: https://github.com/apache/flink/pull/25988#discussion_r1919477022


##########
flink-table/flink-sql-gateway/src/main/java/org/apache/flink/table/gateway/service/materializedtable/MaterializedTableManager.java:
##########
@@ -1123,31 +1129,59 @@ private static JobStatus getJobStatus(
     }
 
     private static void cancelJob(
-            OperationExecutor operationExecutor, OperationHandle handle, 
String jobId) {
+            OperationExecutor operationExecutor,
+            OperationHandle handle,
+            ContinuousRefreshHandler refreshHandler) {
         operationExecutor.callStopJobOperation(
-                operationExecutor.getTableEnvironment(),
+                getTableEnvironment(operationExecutor, refreshHandler),
                 handle,
-                new StopJobOperation(jobId, false, false));
+                new StopJobOperation(refreshHandler.getJobId(), false, false));
     }
 
     private static String stopJobWithSavepoint(
-            OperationExecutor executor, OperationHandle handle, String jobId) {
+            OperationExecutor executor,
+            OperationHandle handle,
+            ContinuousRefreshHandler refreshHandler) {
         // check savepoint dir is configured
         Optional<String> savepointDir =
                 
executor.getSessionContext().getSessionConf().getOptional(SAVEPOINT_DIRECTORY);
-        if (!savepointDir.isPresent()) {
+        if (savepointDir.isEmpty()) {
             throw new ValidationException(
                     "Savepoint directory is not configured, can't stop job 
with savepoint.");
         }
+        String jobId = refreshHandler.getJobId();
         ResultFetcher resultFetcher =
                 executor.callStopJobOperation(
-                        executor.getTableEnvironment(),
+                        getTableEnvironment(executor, refreshHandler),
                         handle,
                         new StopJobOperation(jobId, true, false));
         List<RowData> results = fetchAllResults(resultFetcher);
         return results.get(0).getString(0).toString();
     }
 
+    /**
+     * Using the target and session cluster id configuration get the 
TableEnvironment.
+     *
+     * @param executor OperationExecutor
+     * @param refreshHandler ContinuousRefreshHandler contains jobId and target
+     * @return TableEnvironment
+     */
+    private static TableEnvironmentInternal getTableEnvironment(
+            OperationExecutor executor, ContinuousRefreshHandler 
refreshHandler) {
+
+        String target = refreshHandler.getExecutionTarget();
+        Configuration sessionConfiguration = new Configuration();
+        sessionConfiguration.set(TARGET, target);
+        String clusterIdKeyName = convertClusterIdKeyName(target);
+        if (clusterIdKeyName != null && 
refreshHandler.getClusterId().isPresent()) {
+            sessionConfiguration.setString(clusterIdKeyName, 
refreshHandler.getClusterId().get());
+        }
+
+        return executor.getTableEnvironment(

Review Comment:
   We need to use the target and clusterId in the refresh handler to build a 
new tableEnviroment for connecting to the session cluster or application 
cluster corresponding to the materialized table.



-- 
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: issues-unsubscr...@flink.apache.org

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

Reply via email to