Github user lianhuiwang commented on a diff in the pull request:
https://github.com/apache/spark/pull/13170#discussion_r63810569
--- 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 =>
+ if (location.isDefined) {
+ val path = new Path(location.get)
+ try {
+ val fs =
path.getFileSystem(sparkSession.sessionState.newHadoopConf())
--- End diff --
I think that's OK Because location maybe has different FileSystem and Hive
did like it.
---
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]