-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-39506][SQL] Make CacheTable, isCached, UncacheTable, setCurrentCatalog, currentCatalog, listCatalogs 3l namespace compatible #36904
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3a4cf19
[SPARK-39506] Make CacheTable, isCached, UncacheTable, setCurrentCata…
amaliujia 21393da
update
amaliujia c4b70ef
update
amaliujia ec2d2fe
update
amaliujia 58a91e8
update
amaliujia fdf6de6
update
amaliujia ba7a1c2
update
amaliujia 7184665
update
amaliujia ddbf48f
Update sql/core/src/main/scala/org/apache/spark/sql/catalog/Catalog.s…
cloud-fan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,7 @@ import java.io.File | |
|
|
||
| import org.scalatest.BeforeAndAfter | ||
|
|
||
| import org.apache.spark.sql.AnalysisException | ||
| import org.apache.spark.sql.{AnalysisException, DataFrame} | ||
| import org.apache.spark.sql.catalog.{Column, Database, Function, Table} | ||
| import org.apache.spark.sql.catalyst.{FunctionIdentifier, ScalaReflection, TableIdentifier} | ||
| import org.apache.spark.sql.catalyst.analysis.AnalysisTest | ||
|
|
@@ -63,6 +63,12 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf | |
| sessionCatalog.createTable(utils.newTable(name, db), ignoreIfExists = false) | ||
| } | ||
|
|
||
| private def createTable(name: String, db: String, catalog: String, source: String, | ||
| schema: StructType, option: Map[String, String], description: String): DataFrame = { | ||
| spark.catalog.createTable(Array(catalog, db, name).mkString("."), source, | ||
| schema, description, option) | ||
| } | ||
|
|
||
| private def createTempTable(name: String): Unit = { | ||
| createTempView(sessionCatalog, name, Range(1, 2, 3, 4), overrideIfExists = true) | ||
| } | ||
|
|
@@ -579,12 +585,8 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf | |
| val tableSchema = new StructType().add("i", "int") | ||
| val description = "this is a test table" | ||
|
|
||
| val df = spark.catalog.createTable( | ||
| tableName = Array(catalogName, dbName, tableName).mkString("."), | ||
| source = classOf[FakeV2Provider].getName, | ||
| schema = tableSchema, | ||
| description = description, | ||
| options = Map.empty[String, String]) | ||
| val df = createTable(tableName, dbName, catalogName, classOf[FakeV2Provider].getName, | ||
| tableSchema, Map.empty[String, String], description) | ||
| assert(df.schema.equals(tableSchema)) | ||
|
|
||
| val testCatalog = | ||
|
|
@@ -603,12 +605,8 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf | |
| val tableSchema = new StructType().add("i", "int") | ||
| val description = "this is a test table" | ||
|
|
||
| val df = spark.catalog.createTable( | ||
| tableName = Array(catalogName, dbName, tableName).mkString("."), | ||
| source = classOf[FakeV2Provider].getName, | ||
| schema = tableSchema, | ||
| description = description, | ||
| options = Map("path" -> dir.getAbsolutePath)) | ||
| val df = createTable(tableName, dbName, catalogName, classOf[FakeV2Provider].getName, | ||
| tableSchema, Map("path" -> dir.getAbsolutePath), description) | ||
| assert(df.schema.equals(tableSchema)) | ||
|
|
||
| val testCatalog = | ||
|
|
@@ -630,23 +628,13 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf | |
| val tableName = "my_table" | ||
| val tableSchema = new StructType().add("i", "int") | ||
| val description = "this is a test managed table" | ||
|
|
||
| spark.catalog.createTable( | ||
| tableName = Array(catalogName, dbName, tableName).mkString("."), | ||
| source = classOf[FakeV2Provider].getName, | ||
| schema = tableSchema, | ||
| description = description, | ||
| options = Map.empty[String, String]) | ||
| createTable(tableName, dbName, catalogName, classOf[FakeV2Provider].getName, tableSchema, | ||
| Map.empty[String, String], description) | ||
|
|
||
| val tableName2 = "my_table2" | ||
| val description2 = "this is a test external table" | ||
|
|
||
| spark.catalog.createTable( | ||
| tableName = Array(catalogName, dbName, tableName2).mkString("."), | ||
| source = classOf[FakeV2Provider].getName, | ||
| schema = tableSchema, | ||
| description = description2, | ||
| options = Map("path" -> dir.getAbsolutePath)) | ||
| createTable(tableName2, dbName, catalogName, classOf[FakeV2Provider].getName, tableSchema, | ||
| Map("path" -> dir.getAbsolutePath), description2) | ||
|
|
||
| val tables = spark.catalog.listTables("testcat.my_db").collect() | ||
| assert(tables.size == 2) | ||
|
|
@@ -689,12 +677,8 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf | |
| val tableSchema = new StructType().add("i", "int") | ||
| val description = "this is a test table" | ||
|
|
||
| spark.catalog.createTable( | ||
| tableName = Array(catalogName, dbName, tableName).mkString("."), | ||
| source = classOf[FakeV2Provider].getName, | ||
| schema = tableSchema, | ||
| description = description, | ||
| options = Map.empty[String, String]) | ||
| createTable(tableName, dbName, catalogName, classOf[FakeV2Provider].getName, tableSchema, | ||
| Map.empty[String, String], description) | ||
|
|
||
| val t = spark.catalog.getTable(Array(catalogName, dbName, tableName).mkString(".")) | ||
| val expectedTable = | ||
|
|
@@ -721,13 +705,8 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf | |
| val tableSchema = new StructType().add("i", "int") | ||
|
|
||
| assert(!spark.catalog.tableExists(Array(catalogName, dbName, tableName).mkString("."))) | ||
|
|
||
| spark.catalog.createTable( | ||
| tableName = Array(catalogName, dbName, tableName).mkString("."), | ||
| source = classOf[FakeV2Provider].getName, | ||
| schema = tableSchema, | ||
| description = "", | ||
| options = Map.empty[String, String]) | ||
| createTable(tableName, dbName, catalogName, classOf[FakeV2Provider].getName, tableSchema, | ||
| Map.empty[String, String], "") | ||
|
|
||
| assert(spark.catalog.tableExists(Array(catalogName, dbName, tableName).mkString("."))) | ||
| } | ||
|
|
@@ -743,4 +722,31 @@ class CatalogSuite extends SharedSparkSession with AnalysisTest with BeforeAndAf | |
| val catalogName2 = "catalog_not_exists" | ||
| assert(!spark.catalog.databaseExists(Array(catalogName2, dbName).mkString("."))) | ||
| } | ||
|
|
||
| test("SPARK-39506: three layer namespace compatibility - cache table, isCached and" + | ||
| "uncacheTable") { | ||
| val tableSchema = new StructType().add("i", "int") | ||
| createTable("my_table", "my_db", "testcat", classOf[FakeV2Provider].getName, | ||
| tableSchema, Map.empty[String, String], "") | ||
| createTable("my_table2", "my_db", "testcat", classOf[FakeV2Provider].getName, | ||
| tableSchema, Map.empty[String, String], "") | ||
|
|
||
| spark.catalog.cacheTable("testcat.my_db.my_table", StorageLevel.DISK_ONLY) | ||
| assert(spark.table("testcat.my_db.my_table").storageLevel == StorageLevel.DISK_ONLY) | ||
| assert(spark.catalog.isCached("testcat.my_db.my_table")) | ||
|
|
||
| spark.catalog.cacheTable("testcat.my_db.my_table2") | ||
| assert(spark.catalog.isCached("testcat.my_db.my_table2")) | ||
|
|
||
| spark.catalog.uncacheTable("testcat.my_db.my_table") | ||
| assert(!spark.catalog.isCached("testcat.my_db.my_table")) | ||
| } | ||
|
|
||
| test("SPARK-39506: test setCurrentCatalog, currentCatalog and listCatalogs") { | ||
| spark.catalog.setCurrentCatalog("testcat") | ||
| assert(spark.catalog.currentCatalog().equals("testcat")) | ||
| spark.catalog.setCurrentCatalog("spark_catalog") | ||
| assert(spark.catalog.currentCatalog().equals("spark_catalog")) | ||
| assert(spark.catalog.listCatalogs().collect().map(c => c.name).toSet == Set("testcat")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not related to this PR, but we should figure out why |
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.