BePPPower commented on code in PR #17404:
URL: https://github.com/apache/doris/pull/17404#discussion_r1287212295


##########
fe/fe-core/src/main/java/org/apache/doris/planner/external/TVFScanNode.java:
##########
@@ -62,6 +66,21 @@ public TVFScanNode(PlanNodeId id, TupleDescriptor desc, 
boolean needCheckColumnP
     }
 
     @Override
+    protected void initBackendPolicy() throws UserException {
+        List<String> preferLocations = new ArrayList<>();
+        if (tableValuedFunction instanceof LocalTableValuedFunction) {
+            // For local tvf, the backend was specified by backendId
+            Long backendId = ((LocalTableValuedFunction) 
tableValuedFunction).getBackendId();
+            Backend backend = Env.getCurrentSystemInfo().getBackend(backendId);
+            if (backend == null) {
+                throw new UserException("Backend " + backendId + " does not 
exist");
+            }
+            preferLocations.add(backend.getHost());
+        }
+        backendPolicy.init(preferLocations);
+        numNodes = backendPolicy.numBackends();
+    }
+
     protected String getFsName(FileSplit split) {
         return tableValuedFunction.getFsName();
     }

Review Comment:
   ```suggestion
       @Override
       protected String getFsName(FileSplit split) {
           return tableValuedFunction.getFsName();
       }
   ```



##########
be/src/io/fs/local_file_system.cpp:
##########
@@ -428,5 +429,54 @@ const std::shared_ptr<LocalFileSystem>& 
global_local_filesystem() {
     return local_fs;
 }
 
+Status LocalFileSystem::canonicalize_local_file(const std::string& dir,
+                                                const std::string& file_path,
+                                                std::string* full_path) {
+    const std::string absolute_path = dir + "/" + file_path;
+    std::string canonical_path;
+    RETURN_IF_ERROR(canonicalize(absolute_path, &canonical_path));
+    if (!contain_path(dir, canonical_path)) {
+        return Status::InvalidArgument("file path is not allowed: {}", 
canonical_path);
+    }
+
+    *full_path = canonical_path;
+    return Status::OK();
+}
+
+Status LocalFileSystem::safe_glob(const std::string& path, 
std::vector<FileInfo>* res) {
+    if (path.find("..") != std::string::npos) {
+        return Status::InvalidArgument("can not contain '..' in path");
+    }
+    std::string full_path = config::user_files_secure_path + "/" + path;
+    std::vector<std::string> files;
+    RETURN_IF_ERROR(_glob(full_path, &files));
+    for (auto& file : files) {
+        FileInfo fi;
+        fi.is_file = true;
+        RETURN_IF_ERROR(canonicalize_local_file("", file, &(fi.file_name)));
+        RETURN_IF_ERROR(file_size_impl(fi.file_name, &(fi.file_size)));
+        res->push_back(std::move(fi));
+    }
+    return Status::OK();
+}
+
+Status LocalFileSystem::_glob(const std::string& pattern, 
std::vector<std::string>* res) {
+    glob_t glob_result;
+    memset(&glob_result, 0, sizeof(glob_result));
+
+    int rc = glob(pattern.c_str(), GLOB_TILDE, NULL, &glob_result);

Review Comment:
   ```suggestion
       int rc = glob(pattern.c_str(), GLOB_TILDE, nullptr, &glob_result);
   ```



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