Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13170#discussion_r63814999
  
    --- 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)) {
    +      logWarning(s"table '$tableName' in TRUNCATE TABLE does not exist.")
    +    } else if (catalog.isTemporaryTable(tableName)) {
    +      logWarning(s"table '$tableName' in TRUNCATE TABLE is a temporary 
table.")
    +    } else {
    +      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 --
    
    Move `newHadoopConf` above this loop?


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to