JkSelf commented on code in PR #8331:
URL: https://github.com/apache/incubator-gluten/pull/8331#discussion_r1897113281


##########
backends-velox/src/main/scala/org/apache/gluten/backendsapi/velox/VeloxBackend.scala:
##########
@@ -107,16 +109,24 @@ object VeloxBackendSettings extends BackendSettingsApi {
       val filteredRootPaths = distinctRootPaths(rootPaths)
       if (filteredRootPaths.nonEmpty) {
         val resolvedPaths =
-          if (
-            GlutenConfig.getConf.enableHdfsViewfs && 
filteredRootPaths.head.startsWith("viewfs")
-          ) {
+          if (GlutenConfig.getConf.enableHdfsViewfs) {
+            val viewfsToHdfsCache: mutable.Map[String, String] = 
mutable.Map.empty
             // Convert the viewfs path to hdfs path.
             filteredRootPaths.map {
-              viewfsPath =>
-                val viewPath = new Path(viewfsPath)
-                val viewFileSystem =
-                  FileSystem.get(viewPath.toUri, 
serializableHadoopConf.get.value)
-                viewFileSystem.resolvePath(viewPath).toString
+              path =>
+                if (path.startsWith("viewfs")) {
+                  val pathSplit = path.split(Path.SEPARATOR)

Review Comment:
   Can we move this code into a new method in the ViewFileSystemUtils object? 
This would help in keeping the code reusable.



##########
gluten-substrait/src/main/scala/org/apache/hadoop/fs/viewfs/ViewFileSystemUtils.scala:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.hadoop.fs.viewfs
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.fs.{FileSystem, Path}
+
+object ViewFileSystemUtils {
+
+  /**
+   * Convert the viewfs path to hdfs path. Similar to 
ViewFileSystem.resolvePath, but does not make
+   * RPC calls.
+   */
+  def convertViewfsToHdfs(f: String, hadoopConfig: Configuration): String = {
+    val path = new Path(f)
+    FileSystem.get(path.toUri, hadoopConfig) match {
+      case vfs: ViewFileSystem =>
+        val fsStateField = vfs.getClass.getDeclaredField("fsState")
+        fsStateField.setAccessible(true)
+        val fsState = fsStateField.get(vfs).asInstanceOf[InodeTree[FileSystem]]
+        val res = fsState.resolve(f, true)
+        if (res.isInternalDir) {
+          f
+        } else {
+          Path.mergePaths(new Path(res.targetFileSystem.getUri), 
res.remainingPath).toString
+        }

Review Comment:
   @wangyum It make sense to use Java reflection instead of modifying the code 
in Hadoop ViewFileSystem.
   
   > return Path.mergePaths(new Path(res.targetFileSystem.getUri()), 
res.remainingPath).toString();\
   
   Can we directly return the `new Path(res.targetFileSystem.getUri())`? It 
seems the code here 
https://github.com/apache/incubator-gluten/pull/8331/files#diff-68925b6a5ee67a942a976971ae6727a45a0b166d200d8d983454169e7c3bd1f6R124
 only retrieves the hdfs prefix not the full hdfs path? Correct me if wrong 
understand. Thanks.



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