rdblue commented on a change in pull request #1481:
URL: https://github.com/apache/iceberg/pull/1481#discussion_r493968385
##########
File path: core/src/main/java/org/apache/iceberg/hadoop/HadoopTables.java
##########
@@ -144,6 +147,52 @@ public Table create(Schema schema, PartitionSpec spec,
SortOrder order,
return new BaseTable(ops, location);
}
+ /**
+ * Drop a table and delete all data and metadata files. Throws
NoSuchTableException if the table does not exists.
+ *
+ * @param location a path URI (e.g. hdfs:///warehouse/my_table)
+ * @return true if the table was dropped
+ */
+ public boolean dropTable(String location) {
+ return dropTable(location, true);
+ }
+
+ /**
+ * Drop a table; optionally delete data and metadata files.
+ * <p>
+ * If purge is set to true the implementation should delete all data and
metadata files.
+ * Throws NoSuchTableException if the table does not exists.
+ *
+ * @param location a path URI (e.g. hdfs:///warehouse/my_table)
+ * @param purge if true, delete all data and metadata files in the table
+ * @return true if the table was dropped
+ */
+ public boolean dropTable(String location, boolean purge) {
+ // Just for checking if the table exists or not
+ load(location);
+
+ TableOperations ops = newTableOps(location);
+ TableMetadata lastMetadata;
+ if (purge && ops.current() != null) {
+ lastMetadata = ops.current();
+ } else {
+ lastMetadata = null;
+ }
+
+ try {
+ if (purge && lastMetadata != null) {
+ // Since the data files and the metadata files may store in different
locations,
+ // so it has to call dropTableData to force delete the data file.
+ CatalogUtil.dropTableData(ops.io(), lastMetadata);
+ }
+ Path tablePath = new Path(location);
+ Util.getFs(tablePath, conf).delete(tablePath, true /* recursive */);
Review comment:
Nevermind, I just remembered. And there's already a comment for it.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]