EmmyMiao87 commented on a change in pull request #6067:
URL: https://github.com/apache/incubator-doris/pull/6067#discussion_r659441923



##########
File path: docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW 
CREATE ROUTINE LOAD.md
##########
@@ -0,0 +1,42 @@
+---
+{
+    "title": "SHOW CREATE ROUTINE LOAD",
+    "language": "zh-CN"
+}
+---
+
+<!-- 
+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.
+-->
+
+# SHOW CREATE ROUTINE LOAD
+## description
+    该语句用于展示用户自定义例行导入作业的创建语句

Review comment:
       ```suggestion
       该语句用于展示例行导入作业的创建语句
   ```

##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/load/routineload/KafkaRoutineLoadJob.java
##########
@@ -17,6 +17,7 @@
 
 package org.apache.doris.load.routineload;
 
+import java.util.HashMap;

Review comment:
       Pay attention to the ordering of imports

##########
File path: fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
##########
@@ -1834,7 +1837,56 @@ private void handleShowQueryProfile() throws 
AnalysisException {
 
         resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
     }
-
+    
+    private void handleShowCreateRoutineLoad() throws AnalysisException {
+        ShowCreateRoutineLoadStmt showCreateRoutineLoadStmt = 
(ShowCreateRoutineLoadStmt) stmt;
+        List<List<String>> rows = Lists.newArrayList();
+        String dbName = showCreateRoutineLoadStmt.getDb();
+        String labelName = showCreateRoutineLoadStmt.getLabel();
+        // if include history return all create load
+        if (showCreateRoutineLoadStmt.isIncludeHistory()) {
+            List<RoutineLoadJob> routineLoadJobList = new ArrayList<>();
+            try {
+                routineLoadJobList = 
Catalog.getCurrentCatalog().getRoutineLoadManager().getJob(dbName, labelName, 
true);
+            } catch (MetaNotFoundException e) {
+                LOG.warn(new LogBuilder(LogKey.ROUTINE_LOAD_JOB, labelName)
+                        .add("error_msg", "Routine load cannot be found by 
this name")
+                        .build(), e);
+            }
+            for (RoutineLoadJob job : routineLoadJobList) {
+                String tableName = "";
+                try {
+                    tableName = job.getTableName();
+                } catch (MetaNotFoundException e) {
+                    LOG.warn(new LogBuilder(LogKey.ROUTINE_LOAD_JOB, 
job.getId())
+                            .add("error_msg", "The table name for this routine 
load does not exist")
+                            .build(), e);
+                }
+                if 
(!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ConnectContext.get(),
+                        dbName,
+                        tableName,
+                        PrivPredicate.LOAD)) {
+                    
ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, 
"LOAD",
+                            ConnectContext.get().getQualifiedUser(),
+                            ConnectContext.get().getRemoteIP(),
+                            tableName);
+                }
+                rows.add(Lists.newArrayList(String.valueOf(job.getId()), 
showCreateRoutineLoadStmt.getLabel(), job.getShowCreateInfo()));
+            }
+        } else {
+            // if job exists
+            RoutineLoadJob routineLoadJob;
+            try {
+                routineLoadJob = 
Catalog.getCurrentCatalog().getRoutineLoadManager().checkPrivAndGetJob(dbName, 
labelName);
+                // get routine load info
+                
rows.add(Lists.newArrayList(String.valueOf(routineLoadJob.getId()), 
showCreateRoutineLoadStmt.getLabel(), routineLoadJob.getShowCreateInfo()));
+            } catch (Exception e) {

Review comment:
       The exception caught here is too broad

##########
File path: fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
##########
@@ -1834,7 +1837,56 @@ private void handleShowQueryProfile() throws 
AnalysisException {
 
         resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
     }
-
+    
+    private void handleShowCreateRoutineLoad() throws AnalysisException {
+        ShowCreateRoutineLoadStmt showCreateRoutineLoadStmt = 
(ShowCreateRoutineLoadStmt) stmt;
+        List<List<String>> rows = Lists.newArrayList();
+        String dbName = showCreateRoutineLoadStmt.getDb();
+        String labelName = showCreateRoutineLoadStmt.getLabel();
+        // if include history return all create load
+        if (showCreateRoutineLoadStmt.isIncludeHistory()) {
+            List<RoutineLoadJob> routineLoadJobList = new ArrayList<>();
+            try {
+                routineLoadJobList = 
Catalog.getCurrentCatalog().getRoutineLoadManager().getJob(dbName, labelName, 
true);
+            } catch (MetaNotFoundException e) {
+                LOG.warn(new LogBuilder(LogKey.ROUTINE_LOAD_JOB, labelName)
+                        .add("error_msg", "Routine load cannot be found by 
this name")
+                        .build(), e);
+            }
+            for (RoutineLoadJob job : routineLoadJobList) {
+                String tableName = "";
+                try {
+                    tableName = job.getTableName();
+                } catch (MetaNotFoundException e) {
+                    LOG.warn(new LogBuilder(LogKey.ROUTINE_LOAD_JOB, 
job.getId())
+                            .add("error_msg", "The table name for this routine 
load does not exist")
+                            .build(), e);
+                }
+                if 
(!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ConnectContext.get(),
+                        dbName,
+                        tableName,
+                        PrivPredicate.LOAD)) {
+                    
ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, 
"LOAD",

Review comment:
       If user don’t have permission, we can simply not display it without 
reporting an error

##########
File path: fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
##########
@@ -1834,7 +1837,56 @@ private void handleShowQueryProfile() throws 
AnalysisException {
 
         resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
     }
-
+    
+    private void handleShowCreateRoutineLoad() throws AnalysisException {
+        ShowCreateRoutineLoadStmt showCreateRoutineLoadStmt = 
(ShowCreateRoutineLoadStmt) stmt;
+        List<List<String>> rows = Lists.newArrayList();
+        String dbName = showCreateRoutineLoadStmt.getDb();
+        String labelName = showCreateRoutineLoadStmt.getLabel();
+        // if include history return all create load
+        if (showCreateRoutineLoadStmt.isIncludeHistory()) {
+            List<RoutineLoadJob> routineLoadJobList = new ArrayList<>();
+            try {
+                routineLoadJobList = 
Catalog.getCurrentCatalog().getRoutineLoadManager().getJob(dbName, labelName, 
true);

Review comment:
       The 'getJob' function will return null when there is no routine load has 
been found.




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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to