The SparkSession.catalog object has a bunch of methods to interact with the metastore, namely:
['cacheTable',
'clearCache',
'createExternalTable',
'createTable',
'currentDatabase',
'dropGlobalTempView',
'dropTempView',
'isCached',
'listColumns',
'listDatabases',
'listFunctions',
'listTables',
'recoverPartitions',
'refreshByPath',
'refreshTable',
'registerFunction',
'setCurrentDatabase',
'uncacheTable']
Unfortunately, there seems to have no programmatic way to drop a table.
There are multiple ways to achieve this like
spark.sql(f"drop table my_table")
or
spark._jsparkSession.sharedState().externalCatalog().dropTable(db, table, True, True)
but they look a little bit hackish compared to a simple, nonetheless missing, dropTable method?
Is there a better way ?