Ejemplo n.º 1
0
    def exec(self):
        """Drop table executor"""
        catalog_manager = CatalogManager()
        if len(self.node.table_refs) > 1:
            logger.exception('Drop supports only single table')
        table_ref = self.node.table_refs[0]

        if not catalog_manager.check_table_exists(
                table_ref.table.database_name, table_ref.table.table_name):
            err_msg = "Table: {} does not exsits".format(table_ref)
            if self.node.if_exists:
                logger.warn(err_msg)
            else:
                logger.exception(err_msg)

        if table_ref.table.table_obj.is_video:
            VideoStorageEngine.drop(table=table_ref.table.table_obj)
        else:
            StorageEngine.drop(table=table_ref.table.table_obj)

        success = catalog_manager.drop_dataset_metadata(
            table_ref.table.database_name, table_ref.table.table_name)

        if not success:
            err_msg = "Failed to drop {}".format(table_ref)
            logger.exception(err_msg)

        yield Batch(
            pd.DataFrame(
                {
                    "Table Successfully dropped: {}".format(
                        table_ref.table.table_name)
                },
                index=[0],
            ))
Ejemplo n.º 2
0
 def test_drop_metadata(self, dcs_mock, ds_mock, initdb_mock):
     catalog = CatalogManager()
     catalog.drop_dataset_metadata('database', 'table')
     ds_name_mock = ds_mock.return_value.drop_dataset_by_name
     ds_name_mock.assert_called_with('database', 'table')