Skip to content

Commit 9e10983

Browse files
committed
mv func to SQLTestUtils
1 parent 7125a1b commit 9e10983

File tree

6 files changed

+31
-18
lines changed

6 files changed

+31
-18
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/ExternalCatalogUtils.scala

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package org.apache.spark.sql.catalyst.catalog
1919

2020
import java.net.URI
2121

22-
import org.apache.hadoop.conf.Configuration
2322
import org.apache.hadoop.fs.Path
2423
import org.apache.hadoop.util.Shell
2524

@@ -165,17 +164,6 @@ object CatalogUtils {
165164
BucketSpec(numBuckets, normalizedBucketCols, normalizedSortCols)
166165
}
167166

168-
/**
169-
* This method is used to make the given path qualified, when a path
170-
* does not contain a scheme, this path will not be changed after the default
171-
* FileSystem is changed.
172-
*/
173-
def makeQualifiedPath(path: URI, hadoopConf: Configuration): URI = {
174-
val hadoopPath = new Path(path)
175-
val fs = hadoopPath.getFileSystem(hadoopConf)
176-
fs.makeQualified(hadoopPath).toUri
177-
}
178-
179167
/**
180168
* Convert URI to String.
181169
* Since URI.toString does not decode the uri, e.g. change '%25' to '%'.

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ class SessionCatalog(
126126
CacheBuilder.newBuilder().maximumSize(cacheSize).build[QualifiedTableName, LogicalPlan]()
127127
}
128128

129+
/**
130+
* This method is used to make the given path qualified before we
131+
* store this path in the underlying external catalog. So, when a path
132+
* does not contain a scheme, this path will not be changed after the default
133+
* FileSystem is changed.
134+
*/
135+
private def makeQualifiedPath(path: URI): URI = {
136+
val hadoopPath = new Path(path)
137+
val fs = hadoopPath.getFileSystem(hadoopConf)
138+
fs.makeQualified(hadoopPath).toUri
139+
}
140+
129141
private def requireDbExists(db: String): Unit = {
130142
if (!databaseExists(db)) {
131143
throw new NoSuchDatabaseException(db)
@@ -159,7 +171,7 @@ class SessionCatalog(
159171
"you cannot create a database with this name.")
160172
}
161173
validateName(dbName)
162-
val qualifiedPath = CatalogUtils.makeQualifiedPath(dbDefinition.locationUri, hadoopConf)
174+
val qualifiedPath = makeQualifiedPath(dbDefinition.locationUri)
163175
externalCatalog.createDatabase(
164176
dbDefinition.copy(name = dbName, locationUri = qualifiedPath),
165177
ignoreIfExists)

sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import org.apache.spark.sql.catalyst.catalog._
3030
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec
3131
import org.apache.spark.sql.internal.SQLConf
3232
import org.apache.spark.sql.internal.StaticSQLConf.CATALOG_IMPLEMENTATION
33-
import org.apache.spark.sql.test.SharedSQLContext
33+
import org.apache.spark.sql.test.{SharedSQLContext, SQLTestUtils}
3434
import org.apache.spark.sql.types._
3535
import org.apache.spark.util.Utils
3636

@@ -133,7 +133,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
133133
}
134134

135135
private def makeQualifiedPath(path: String): URI = {
136-
CatalogUtils.makeQualifiedPath(
136+
SQLTestUtils.makeQualifiedPath(
137137
CatalogUtils.stringToURI(path), spark.sessionState.newHadoopConf())
138138
}
139139

sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
package org.apache.spark.sql.test
1919

2020
import java.io.File
21+
import java.net.URI
2122
import java.util.UUID
2223

2324
import scala.language.implicitConversions
2425
import scala.util.Try
2526
import scala.util.control.NonFatal
2627

2728
import org.apache.hadoop.conf.Configuration
29+
import org.apache.hadoop.fs.Path
2830
import org.scalatest.BeforeAndAfterAll
2931

3032
import org.apache.spark.SparkFunSuite
@@ -337,4 +339,15 @@ private[sql] object SQLTestUtils {
337339
None
338340
}
339341
}
342+
343+
/**
344+
* This method is used to make the given path qualified, when a path
345+
* does not contain a scheme, this path will not be changed after the default
346+
* FileSystem is changed.
347+
*/
348+
def makeQualifiedPath(path: URI, hadoopConf: Configuration): URI = {
349+
val hadoopPath = new Path(path)
350+
val fs = hadoopPath.getFileSystem(hadoopConf)
351+
fs.makeQualified(hadoopPath).toUri
352+
}
340353
}

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import org.scalatest.BeforeAndAfterEach
2727
import org.apache.spark.SparkException
2828
import org.apache.spark.sql.{AnalysisException, QueryTest, Row, SaveMode}
2929
import org.apache.spark.sql.catalyst.analysis.{NoSuchPartitionException, TableAlreadyExistsException}
30-
import org.apache.spark.sql.catalyst.catalog._
30+
import org.apache.spark.sql.catalyst.catalog.{CatalogDatabase, CatalogTable, CatalogTableType, CatalogUtils, ExternalCatalogUtils}
3131
import org.apache.spark.sql.catalyst.TableIdentifier
3232
import org.apache.spark.sql.execution.command.DDLUtils
3333
import org.apache.spark.sql.hive.HiveExternalCatalog
@@ -66,7 +66,7 @@ class HiveDDLSuite
6666
}
6767

6868
private def makeQualifiedPath(path: String): URI = {
69-
CatalogUtils.makeQualifiedPath(
69+
SQLTestUtils.makeQualifiedPath(
7070
CatalogUtils.stringToURI(path), spark.sessionState.newHadoopConf())
7171
}
7272

sql/hive/src/test/scala/org/apache/spark/sql/sources/HadoopFsRelationTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ abstract class HadoopFsRelationTest extends QueryTest with SQLTestUtils with Tes
4646
protected def supportsDataType(dataType: DataType): Boolean = true
4747

4848
protected def makeQualifiedPath(path: String): URI = {
49-
CatalogUtils.makeQualifiedPath(CatalogUtils.stringToURI(path), SparkHadoopUtil.get.conf)
49+
SQLTestUtils.makeQualifiedPath(CatalogUtils.stringToURI(path), SparkHadoopUtil.get.conf)
5050
}
5151

5252
val dataSchema =

0 commit comments

Comments
 (0)