aajisaka commented on code in PR #7455:
URL: https://github.com/apache/kyuubi/pull/7455#discussion_r3256352273


##########
extensions/spark/kyuubi-spark-connector-yarn/src/main/scala/org/apache/kyuubi/spark/connector/yarn/YarnCatalog.scala:
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.kyuubi.spark.connector.yarn
+
+import java.util
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.catalyst.analysis.NoSuchTableException
+import org.apache.spark.sql.connector.catalog._
+import org.apache.spark.sql.connector.expressions.Transform
+import org.apache.spark.sql.types.StructType
+import org.apache.spark.sql.util.CaseInsensitiveStringMap
+
+class YarnCatalog extends TableCatalog with Logging {
+  private var catalogName: String = _
+
+  override def name: String = this.catalogName
+
+  override def initialize(
+      name: String,
+      caseInsensitiveStringMap: CaseInsensitiveStringMap): Unit = {
+    catalogName = name
+  }
+
+  override def listTables(namespace: Array[String]): Array[Identifier] = {
+    Array(Identifier.of(namespace, "app_logs"))
+  }

Review Comment:
   This catalog is not aware of namespace and it makes 
`catalog.any_namespace.app_logs` resolve to the same table. We need to at least 
document the limitation.



##########
extensions/spark/kyuubi-spark-connector-yarn/src/main/scala/org/apache/kyuubi/spark/connector/yarn/YarnLogBatchScan.scala:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.kyuubi.spark.connector.yarn
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hadoop.fs.{FileStatus, Path}
+import org.apache.hadoop.yarn.conf.YarnConfiguration
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.SparkSession
+import org.apache.spark.sql.connector.read._
+import org.apache.spark.sql.sources.{EqualTo, Filter}
+import org.apache.spark.sql.types.StructType
+import org.apache.spark.sql.util.CaseInsensitiveStringMap
+import org.apache.spark.util.SerializableConfiguration
+
+case class YarnLogBatchScan(
+    options: CaseInsensitiveStringMap,
+    schema: StructType,
+    pushedFilters: Array[Filter])
+  extends Scan with Batch with Logging {
+
+  override def readSchema(): StructType = schema
+
+  protected val hadoopConf: Configuration =
+    SparkSession.active.sessionState.newHadoopConf()
+
+  private val _formats = 
hadoopConf.get(YarnConfiguration.LOG_AGGREGATION_FILE_FORMATS, "TFile")
+  if (!_formats.equalsIgnoreCase("TFile")) {
+    throw new UnsupportedOperationException(
+      "Currently, only TFile format is supported. While " +
+        s"${YarnConfiguration.LOG_AGGREGATION_FILE_FORMATS} was set to 
${_formats}.")
+  }
+
+  private val remoteAppLogDir = hadoopConf.get(
+    YarnConfiguration.NM_REMOTE_APP_LOG_DIR,
+    YarnConfiguration.DEFAULT_NM_REMOTE_APP_LOG_DIR)
+
+  private val remoteAppLogDirSuffix = hadoopConf.get(
+    YarnConfiguration.NM_REMOTE_APP_LOG_DIR_SUFFIX,
+    YarnConfiguration.DEFAULT_NM_REMOTE_APP_LOG_DIR_SUFFIX)
+
+  // given a path in hdfs, then get all files under it, supports *
+  private def listFiles(pathStr: String): Array[FileStatus] = {
+    val path = new Path(pathStr)
+    val fs = path.getFileSystem(hadoopConf)
+
+    val start = System.currentTimeMillis()
+    val files = fs.globStatus(path)

Review Comment:
   In case of Observer NameNode setup, would you call `fs.msync()` before 
listing files to avoid stale reads?



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