Github user xwu0226 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13212#discussion_r64281350
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/resources.scala 
---
    @@ -46,3 +51,52 @@ case class AddFileCommand(path: String) extends 
RunnableCommand {
         Seq.empty[Row]
       }
     }
    +
    +/**
    + * Return a list of file paths that are added to resources.
    + * If file paths are provided, return the ones that are added to resources.
    + */
    +case class ListFilesCommand(files: Seq[String] = Seq.empty[String]) 
extends RunnableCommand {
    +  override val output: Seq[Attribute] = {
    +    AttributeReference("Results", StringType, nullable = false)() :: Nil
    +  }
    +  override def run(sparkSession: SparkSession): Seq[Row] = {
    +    val fileList = sparkSession.sparkContext.listFiles()
    +    if (files.size > 0) {
    +      files.map { f =>
    +        val uri = new URI(f)
    +        val schemeCorrectedPath = uri.getScheme match {
    +          case null | "local" => new 
File(f).getCanonicalFile.toURI.toString
    +          case _ => f
    +        }
    +        new Path(schemeCorrectedPath).toUri.toString
    +      }.collect {
    +        case f if fileList.contains(f) => f
    +      }.map(Row(_))
    +    } else {
    +      fileList.map(Row(_))
    +    }
    +  }
    +}
    +
    +/**
    + * Return a list of jar files that are added to resources.
    + * If jar files are provided, return the ones that are added to resources.
    + */
    +case class ListJarsCommand(jars: Seq[String] = Seq.empty[String]) extends 
RunnableCommand {
    +  override val output: Seq[Attribute] = {
    +    AttributeReference("Results", StringType, nullable = false)() :: Nil
    +  }
    +  override def run(sparkSession: SparkSession): Seq[Row] = {
    +    val jarList = sparkSession.sparkContext.listJars()
    +    if (jars.size > 0) {
    +      jars.map { f =>
    +        new Path(f).getName
    +      }.flatMap {f =>
    +        jarList.filter(_.contains(f))
    +      }.map(Row(_))
    +    } else {
    +      jarList.map(Row(_))
    +    }
    +  }
    --- End diff --
    
    Yes. this looks nicer. I will update to use this format. Thanks!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to