spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xwu0226 <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-15431][SQL] Support LIST FILE(s)|JAR(s)...
Date Mon, 23 May 2016 18:09:03 GMT
Github user xwu0226 commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13212#discussion_r64261638
  
    --- 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 =>
    --- End diff --
    
    Will do.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message