You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2021/03/29 15:41:22 UTC

[GitHub] [iceberg] danielcweeks commented on a change in pull request #2266: Implement python drop_table

danielcweeks commented on a change in pull request #2266:
URL: https://github.com/apache/iceberg/pull/2266#discussion_r603402589



##########
File path: python/iceberg/hive/hive_tables.py
##########
@@ -34,12 +40,40 @@ def __init__(self, conf):
     def new_table_ops(self, conf, database, table):
         return HiveTableOperations(conf, self.get_client(), database, table)
 
-    def drop(self, database, table):
-        raise RuntimeError("Not yet implemented")
+    def drop(self, database: str, table: str, purge: bool = False) -> None:
+        ops = self.new_table_ops(self.conf, database, table)
+        metadata = ops.current()
 
-    def get_client(self):
+        with self.get_client() as open_client:
+            _logger.info("Deleting {database}.{table} from Hive Metastore".format(database=database, table=table))
+            open_client.drop_table(database, table, deleteData=False)
+
+        if purge:
+            if metadata is not None:
+                with Pool(self.conf.get(WORKER_THREAD_POOL_SIZE_PROP,
+                                        cpu_count())) as delete_pool:
+                    for s in metadata.snapshots:
+                        for m in s.manifests:
+                            delete_pool.map(self._delete_file(ops),
+                                            (i.path() for i in s.get_filtered_manifest(m.manifest_path).iterator()))
+                        delete_pool.map(self._delete_file(ops), (m.manifest_path for m in s.manifests))
+                        if s.manifest_location is not None:
+                            delete_pool.map(self._delete_file(ops), [s.manifest_location])
+                    delete_pool.map(self._delete_file(ops), [ops.current_metadata_location])
+
+    def get_client(self) -> HMSClient:
         from urllib.parse import urlparse
         metastore_uri = urlparse(self.conf[HiveTables.THRIFT_URIS])
 
         client = hmsclient.HMSClient(host=metastore_uri.hostname, port=metastore_uri.port)
         return client
+
+    @staticmethod
+    def _delete_file(ops: HiveTableOperations) -> Callable[[str], None]:
+        def _delete_file_internal(path: str) -> None:
+            _logger.info("Deleting file: {path}".format(path=path))
+            try:
+                ops.delete_file(path)
+            except OSError:
+                pass

Review comment:
       Feels like we should at least log warning level message in the event the files cannot be deleted.  It looks like we're silently swallowing files that would be dangling after this operation.




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org