morningman commented on code in PR #34516:
URL: https://github.com/apache/doris/pull/34516#discussion_r1593836662


##########
fe/fe-core/src/main/java/org/apache/doris/tablefunction/QueryTableValueFunction.java:
##########
@@ -0,0 +1,79 @@
+// 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.doris.tablefunction;
+
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.datasource.CatalogIf;
+import org.apache.doris.datasource.jdbc.JdbcExternalCatalog;
+import org.apache.doris.planner.PlanNodeId;
+import org.apache.doris.planner.ScanNode;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+
+public abstract class QueryTableValueFunction extends TableValuedFunctionIf {
+    public static final Logger LOG = 
LogManager.getLogger(QueryTableValueFunction.class);
+    public static final String NAME = "query";
+    private static final String CATALOG = "catalog";
+    private static final String QUERY = "query";
+    protected CatalogIf catalogIf;
+    protected final String query;
+
+    public QueryTableValueFunction(Map<String, String> params) throws 
AnalysisException {
+        if (params.size() != 2) {
+            throw new AnalysisException("Query TableValueFunction must have 2 
arguments: 'catalog' and 'query'");
+        }
+        if (!params.containsKey(CATALOG) || !params.containsKey(QUERY)) {
+            throw new AnalysisException("Query TableValueFunction must have 2 
arguments: 'catalog' and 'query'");
+        }
+        String catalogName = params.get(CATALOG);
+        this.query = params.get(QUERY);
+        this.catalogIf = 
Env.getCurrentEnv().getCatalogMgr().getCatalog(catalogName);
+    }
+
+    public static QueryTableValueFunction 
createQueryTableValueFunction(Map<String, String> params)

Review Comment:
   Missing authorization check.
   I think user need catalog level SELECT priv to exeute this tvf



##########
fe/fe-core/src/main/java/org/apache/doris/tablefunction/QueryTableValueFunction.java:
##########
@@ -0,0 +1,79 @@
+// 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.doris.tablefunction;
+
+import org.apache.doris.analysis.TupleDescriptor;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.datasource.CatalogIf;
+import org.apache.doris.datasource.jdbc.JdbcExternalCatalog;
+import org.apache.doris.planner.PlanNodeId;
+import org.apache.doris.planner.ScanNode;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+import java.util.Map;
+
+public abstract class QueryTableValueFunction extends TableValuedFunctionIf {
+    public static final Logger LOG = 
LogManager.getLogger(QueryTableValueFunction.class);
+    public static final String NAME = "query";
+    private static final String CATALOG = "catalog";
+    private static final String QUERY = "query";
+    protected CatalogIf catalogIf;
+    protected final String query;
+
+    public QueryTableValueFunction(Map<String, String> params) throws 
AnalysisException {
+        if (params.size() != 2) {
+            throw new AnalysisException("Query TableValueFunction must have 2 
arguments: 'catalog' and 'query'");
+        }
+        if (!params.containsKey(CATALOG) || !params.containsKey(QUERY)) {
+            throw new AnalysisException("Query TableValueFunction must have 2 
arguments: 'catalog' and 'query'");
+        }
+        String catalogName = params.get(CATALOG);
+        this.query = params.get(QUERY);
+        this.catalogIf = 
Env.getCurrentEnv().getCatalogMgr().getCatalog(catalogName);
+    }
+
+    public static QueryTableValueFunction 
createQueryTableValueFunction(Map<String, String> params)
+            throws AnalysisException {
+        String catalogName = params.get(CATALOG);
+        CatalogIf catalogIf = 
Env.getCurrentEnv().getCatalogMgr().getCatalog(catalogName);
+        if (catalogIf == null) {
+            throw new AnalysisException("Catalog not found: " + catalogName);
+        }
+        if (catalogIf instanceof JdbcExternalCatalog) {
+            return new JdbcQueryTableValueFunction(params);
+        } else {
+            throw new AnalysisException("Unsupported catalog type in query 
tvf: " + catalogName);

Review Comment:
   print "type" as well



-- 
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: commits-unsubscr...@doris.apache.org

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


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

Reply via email to