-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-22940][SQL] HiveExternalCatalogVersionsSuite should succeed on platforms that don't have wget #20147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-22940][SQL] HiveExternalCatalogVersionsSuite should succeed on platforms that don't have wget #20147
Changes from 3 commits
5fe679f
92e82d4
c5e835e
8b71ea3
e85b813
51f3589
46225e8
3dbfffd
7b58d99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,12 +17,16 @@ | |
|
|
||
| package org.apache.spark.sql.hive | ||
|
|
||
| import java.io.File | ||
| import java.io.{File, FileInputStream} | ||
| import java.nio.file.Files | ||
|
|
||
| import scala.io.Codec | ||
| import scala.io.Source | ||
| import scala.sys.process._ | ||
|
|
||
| import org.apache.spark.TestUtils | ||
| import org.apache.hadoop.conf.Configuration | ||
|
|
||
| import org.apache.spark.{SecurityManager, SparkConf, TestUtils} | ||
| import org.apache.spark.sql.{QueryTest, Row, SparkSession} | ||
| import org.apache.spark.sql.catalyst.TableIdentifier | ||
| import org.apache.spark.sql.catalyst.catalog.CatalogTableType | ||
|
|
@@ -56,10 +60,11 @@ class HiveExternalCatalogVersionsSuite extends SparkSubmitTestUtils { | |
| // Try mirrors a few times until one succeeds | ||
| for (i <- 0 until 3) { | ||
| val preferredMirror = | ||
| Seq("wget", "https://www.apache.org/dyn/closer.lua?preferred=true", "-q", "-O", "-").!!.trim | ||
| val url = s"$preferredMirror/spark/spark-$version/spark-$version-bin-hadoop2.7.tgz" | ||
| getStringFromUrl("https://www.apache.org/dyn/closer.lua?preferred=true") | ||
| val filename = s"spark-$version-bin-hadoop2.7.tgz" | ||
| val url = s"$preferredMirror/spark/spark-$version/" + filename | ||
| logInfo(s"Downloading Spark $version from $url") | ||
| if (Seq("wget", url, "-q", "-P", path).! == 0) { | ||
| if (getFileFromUrl(url, path, filename)) { | ||
| return | ||
| } | ||
| logWarning(s"Failed to download Spark $version from $url") | ||
|
|
@@ -85,6 +90,43 @@ class HiveExternalCatalogVersionsSuite extends SparkSubmitTestUtils { | |
| new File(tmpDataDir, name).getCanonicalPath | ||
| } | ||
|
|
||
| private def getFileFromUrl(urlString: String, targetDir: String, filename: String): Boolean = { | ||
| val conf = new SparkConf | ||
| val securityManager = new SecurityManager(conf) | ||
| val hadoopConf = new Configuration | ||
|
|
||
| val outDir = new File(targetDir) | ||
| if (!outDir.exists()) { | ||
| outDir.mkdirs() | ||
| } | ||
|
|
||
| try { | ||
| val result = Utils.doFetchFile(urlString, outDir, filename, conf, securityManager, hadoopConf) | ||
|
||
| result.exists() | ||
|
||
| } catch { | ||
| case ex: Exception => logError("Could not get file from url " + urlString + ": " | ||
|
||
| + ex.getMessage) | ||
| false | ||
| } | ||
| } | ||
|
|
||
| private def getStringFromUrl(urlString: String, encoding: String = "UTF-8"): String = { | ||
|
||
| val outDir = Files.createTempDirectory("string-") | ||
|
||
| val filename = "string-out.txt" | ||
|
|
||
| if (!getFileFromUrl(urlString, outDir.toString, filename)) { | ||
| throw new java.io.IOException("Could not get string from url " + urlString) | ||
|
||
| } | ||
|
|
||
| val outputFile = new File(outDir.toString + File.separator + filename) | ||
|
||
| val fis = new FileInputStream(outputFile) | ||
| val result = Source.fromInputStream(fis)(Codec(encoding)).mkString | ||
| fis.close() | ||
|
||
| outputFile.delete() | ||
| outDir.toFile.delete() | ||
| result | ||
| } | ||
|
|
||
| override def beforeAll(): Unit = { | ||
| super.beforeAll() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
filenamein interpolation also?