-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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-33448][SQL] Support CACHE/UNCACHE TABLE commands for v2 tables #30403
Changes from 4 commits
3e532c8
f4ee301
a0687b3
f36bc59
b3fe647
4b2fba0
f232eba
8c0140c
9085189
0bdfcee
fc8a913
7ee6eb0
a5923ab
f22159c
c0e4f3e
47dc974
5e7227b
20b2474
b33d807
4c2d5e2
3c4a0cf
7f5a0b2
d0f49ef
ed1a6db
4e0e82f
911927d
7e788ce
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 |
---|---|---|
|
@@ -416,9 +416,9 @@ case class DropTable( | |
} | ||
|
||
/** | ||
* The logical plan for handling non-existing table for DROP TABLE command. | ||
* The logical plan for no-op command handling non-existing table. | ||
*/ | ||
case class NoopDropTable(multipartIdentifier: Seq[String]) extends Command | ||
case class NoopCommand(multipartIdentifier: Seq[String]) extends Command | ||
|
||
/** | ||
* The logical plan of the ALTER TABLE command. | ||
|
@@ -629,3 +629,21 @@ case class LoadData( | |
case class ShowCreateTable(child: LogicalPlan, asSerde: Boolean = false) extends Command { | ||
override def children: Seq[LogicalPlan] = child :: Nil | ||
} | ||
|
||
/** | ||
* The logical plan of the CACHE TABLE command. | ||
*/ | ||
case class CacheTable( | ||
child: LogicalPlan, | ||
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. After more thought, I think CACHE TABLE is not a DDL command that needs to interact with catalogs, and it doesn't need a v2 version. The current problem is that 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. I updated 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. Also, since it's not resolving to catalogs, we should move it out of |
||
plan: Option[LogicalPlan], | ||
isLazy: Boolean, | ||
options: Map[String, String]) extends Command { | ||
override def children: Seq[LogicalPlan] = child :: Nil | ||
} | ||
|
||
/** | ||
* The logical plan of the UNCACHE TABLE command. | ||
*/ | ||
case class UncacheTable(child: LogicalPlan, ifExists: Boolean) extends Command { | ||
override def children: Seq[LogicalPlan] = child :: Nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -441,19 +441,16 @@ class ResolveSessionCatalog( | |
ShowCreateTableCommand(ident.asTableIdentifier) | ||
} | ||
|
||
case CacheTableStatement(tbl, plan, isLazy, options) => | ||
val name = if (plan.isDefined) { | ||
// CACHE TABLE ... AS SELECT creates a temp view with the input query. | ||
// Temp view doesn't belong to any catalog and we shouldn't resolve catalog in the name. | ||
tbl | ||
} else { | ||
parseTempViewOrV1Table(tbl, "CACHE TABLE") | ||
} | ||
CacheTableCommand(name.asTableIdentifier, plan, isLazy, options) | ||
// CACHE TABLE ... AS SELECT creates a temp view with the input query. | ||
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. What's the behavior of it if the temp view already exists? overwrite? 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. It would fail with:
|
||
// Thus, use the identifier in UnresolvedTableOrView directly, | ||
case CacheTable(u: UnresolvedTableOrView, plan, isLazy, options) if plan.isDefined => | ||
CacheTableCommand(u.multipartIdentifier.asTableIdentifier, plan, isLazy, options) | ||
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. @cloud-fan Please let me know what you think about having 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. This is more like CTAS and the How about we have both 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. Good idea |
||
|
||
case UncacheTableStatement(tbl, ifExists) => | ||
val name = parseTempViewOrV1Table(tbl, "UNCACHE TABLE") | ||
UncacheTableCommand(name.asTableIdentifier, ifExists) | ||
case CacheTable(ResolvedV1TableOrViewIdentifier(ident), plan, isLazy, options) => | ||
CacheTableCommand(ident.asTableIdentifier, plan, isLazy, options) | ||
|
||
case UncacheTable(ResolvedV1TableOrViewIdentifier(ident), ifExists) => | ||
UncacheTableCommand(ident.asTableIdentifier, ifExists) | ||
|
||
case TruncateTableStatement(tbl, partitionSpec) => | ||
val v1TableName = parseV1Table(tbl, "TRUNCATE TABLE") | ||
|
@@ -570,12 +567,9 @@ class ResolveSessionCatalog( | |
"SHOW VIEWS, only SessionCatalog supports this command.") | ||
} | ||
|
||
case ShowTableProperties(ResolvedV1TableIdentifier(ident), propertyKey) => | ||
case ShowTableProperties(ResolvedV1TableOrViewIdentifier(ident), propertyKey) => | ||
imback82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ShowTablePropertiesCommand(ident.asTableIdentifier, propertyKey) | ||
|
||
case ShowTableProperties(r: ResolvedView, propertyKey) => | ||
ShowTablePropertiesCommand(r.identifier.asTableIdentifier, propertyKey) | ||
|
||
case DescribeFunction(ResolvedFunc(identifier), extended) => | ||
DescribeFunctionCommand(identifier.asFunctionIdentifier, extended) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,7 +231,7 @@ class DataSourceV2Strategy(session: SparkSession) extends Strategy with Predicat | |
case DropTable(r: ResolvedTable, ifExists, purge) => | ||
DropTableExec(session, r.catalog, r.table, r.identifier, ifExists, purge) :: Nil | ||
|
||
case _: NoopDropTable => | ||
case _: NoopCommand => | ||
LocalTableScanExec(Nil, Nil) :: Nil | ||
|
||
case AlterTable(catalog, ident, _, changes) => | ||
|
@@ -289,6 +289,12 @@ class DataSourceV2Strategy(session: SparkSession) extends Strategy with Predicat | |
case ShowCreateTable(_: ResolvedTable, _) => | ||
throw new AnalysisException("SHOW CREATE TABLE is not supported for v2 tables.") | ||
|
||
case CacheTable(_: ResolvedTable, _, _, _) => | ||
throw new AnalysisException("CACHE TABLE is not supported for v2 tables.") | ||
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. We don't need new v2 APIs to support it. This command touches 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. Ah OK. An existing bug, I guess? (it only supported temp view / v1 tables). Does it make sense to match 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. We can add a 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. Added v2 version. |
||
|
||
case UncacheTable(_: ResolvedTable, _) => | ||
throw new AnalysisException("UNCACHE TABLE is not supported for v2 tables.") | ||
|
||
case _ => Nil | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1963,13 +1963,8 @@ class DataSourceV2SQLSuite | |
val t = "testcat.ns1.ns2.tbl" | ||
withTable(t) { | ||
spark.sql(s"CREATE TABLE $t (id bigint, data string) USING foo") | ||
|
||
testV1CommandSupportingTempView("CACHE TABLE", t) | ||
|
||
val e = intercept[AnalysisException] { | ||
sql(s"CACHE LAZY TABLE $t") | ||
} | ||
assert(e.message.contains("CACHE TABLE is only supported with temp views or v1 tables")) | ||
testNotSupportedV2Command("CACHE TABLE", t) | ||
testNotSupportedV2Command("CACHE LAZY TABLE", t, sqlCommandInMessage = Some("CACHE TABLE")) | ||
} | ||
} | ||
|
||
|
@@ -1978,8 +1973,8 @@ class DataSourceV2SQLSuite | |
withTable(t) { | ||
sql(s"CREATE TABLE $t (id bigint, data string) USING foo") | ||
|
||
testV1CommandSupportingTempView("UNCACHE TABLE", t) | ||
testV1CommandSupportingTempView("UNCACHE TABLE", s"IF EXISTS $t") | ||
testNotSupportedV2Command("UNCACHE TABLE", t) | ||
testNotSupportedV2Command("UNCACHE TABLE", s"IF EXISTS $t") | ||
} | ||
} | ||
|
||
|
@@ -2486,11 +2481,15 @@ class DataSourceV2SQLSuite | |
} | ||
} | ||
|
||
private def testNotSupportedV2Command(sqlCommand: String, sqlParams: String): Unit = { | ||
private def testNotSupportedV2Command( | ||
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. unnecessary change. This is minor and let's fix it in your next PR. 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. Ok, will fix. |
||
sqlCommand: String, | ||
sqlParams: String, | ||
sqlCommandInMessage: Option[String] = None): Unit = { | ||
val e = intercept[AnalysisException] { | ||
sql(s"$sqlCommand $sqlParams") | ||
} | ||
assert(e.message.contains(s"$sqlCommand is not supported for v2 tables")) | ||
val cmdStr = sqlCommandInMessage.getOrElse(sqlCommand) | ||
assert(e.message.contains(s"$cmdStr is not supported for v2 tables")) | ||
} | ||
|
||
private def testV1Command(sqlCommand: String, sqlParams: String): Unit = { | ||
|
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.
We should probably add a
commandName: String
property, which can beDROP TABLE
,REFRESH TABLE
, etc., so that we can see the original commannd name from the EXPLAIN result.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.
Added
commandName
. NowEXPLAIN EXTENDED DROP TABLE
looks like the following:Btw, do we want to introduce
NoopCommandExec
for physical plan as well?