Github user xwu0226 commented on a diff in the pull request:
https://github.com/apache/spark/pull/13212#discussion_r64262960
--- 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(_))
--- End diff --
`ADD JARS` command will consider jar files with the same jar file name are
the same jar. For example:
```
spark-sql> add jar /Users/xinwu/spark-test/data/level1/test1.jar;
ADD JAR /Users/xinwu/spark-test/data/level1/test1.jar
Added [/Users/xinwu/spark-test/data/level1/test1.jar] to class path
Added resources: [/Users/xinwu/spark-test/data/level1/test1.jar]
0
Time taken: 1.928 seconds, Fetched 1 row(s)
spark-sql> add jar /Users/xinwu/spark-test/data/test1.jar;
ADD JAR /Users/xinwu/spark-test/data/test1.jar
Added [/Users/xinwu/spark-test/data/test1.jar] to class path
Added resources: [/Users/xinwu/spark-test/data/test1.jar]
16/05/23 11:11:12 ERROR SparkContext: Error adding jar
(java.lang.IllegalArgumentException: requirement failed: JAR test1.jar already
registered.), was the --addJars option used?
0
Time taken: 0.06 seconds, Fetched 1 row(s)
spark-sql> list jars;
spark://9.52.238.134:57281/jars/test1.jar,
Time taken: 0.052 seconds, Fetched 1 row(s)
```
So it looks like the jar is added to the command directory `jars`. So for
`list jars`, if I specify the full path of the source jar file, it will return
empty results.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]