Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/13170#discussion_r63791413
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala ---
@@ -271,6 +274,54 @@ case class LoadData(
}
/**
+ * A command to truncate table.
+ *
+ * The syntax of this command is:
+ * {{{
+ * TRUNCATE TABLE tablename [PARTITION (partcol1=val1, partcol2=val2 ...)]
+ * }}}
+ */
+case class TruncateTable(
+ tableName: TableIdentifier,
+ partitionSpec: Option[TablePartitionSpec]) extends RunnableCommand {
+
+ override def run(sparkSession: SparkSession): Seq[Row] = {
+ val catalog = sparkSession.sessionState.catalog
+ if (!catalog.tableExists(tableName)) {
+ throw new AnalysisException(s"table in TRUNCATE TABLE does not
exist: '$tableName'")
+ }
+ if (catalog.isTemporaryTable(tableName)) {
+ throw new AnalysisException(s"table in TRUNCATE TABLE cannot be
temporary: '$tableName'")
+ }
+ val locations = if (partitionSpec.isDefined) {
+ catalog.listPartitions(tableName,
partitionSpec).map(_.storage.locationUri)
+ } else {
+ val table = catalog.getTableMetadata(tableName)
+ if (table.partitionColumnNames.nonEmpty) {
+ catalog.listPartitions(tableName).map(_.storage.locationUri)
+ } else {
+ Seq(table.storage.locationUri)
+ }
+ }
+ locations.foreach { location =>
--- End diff --
This is actually my only concern. Shouldn't this be an atomic operation? If
it fails we will end up with a partially truncated table. Can we make this
atomic? What are Hive's semantics?
---
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]