Exemplo n.º 1
0
    def test_should_drop_table(self):
        catalog_manager = CatalogManager()
        query = """LOAD DATA INFILE 'dummy.avi' INTO MyVideo;"""
        execute_query_fetch_all(query)

        metadata_obj = catalog_manager.get_dataset_metadata(None, "MyVideo")
        video_dir = metadata_obj.file_url
        self.assertFalse(metadata_obj is None)
        column_objects = catalog_manager.get_all_column_objects(metadata_obj)
        self.assertEqual(len(column_objects), 2)
        self.assertTrue(Path(video_dir).exists())
        drop_query = """DROP TABLE MyVideo;"""
        execute_query_fetch_all(drop_query)
        self.assertTrue(
            catalog_manager.get_dataset_metadata(None, "MyVideo") is None)
        column_objects = catalog_manager.get_all_column_objects(metadata_obj)
        self.assertEqual(len(column_objects), 0)
        self.assertFalse(Path(video_dir).exists())
Exemplo n.º 2
0
    def test_should_rename_table(self):
        catalog_manager = CatalogManager()
        query = """LOAD DATA INFILE 'dummy.avi' INTO MyVideo;"""
        execute_query_fetch_all(query)

        self.assertTrue(
            catalog_manager.get_dataset_metadata(None, "MyVideo") is not None
        )
        self.assertTrue(
            catalog_manager.get_dataset_metadata(None, "MyVideo1") is None
        )

        rename_query = """RENAME TABLE MyVideo TO MyVideo1;"""
        execute_query_fetch_all(rename_query)

        self.assertTrue(
            catalog_manager.get_dataset_metadata(None, "MyVideo") is None
        )
        self.assertTrue(
            catalog_manager.get_dataset_metadata(None, "MyVideo1") is not None
        )
Exemplo n.º 3
0
    def test_get_dataset_metadata_when_table_doesnot_exists(
            self, dcs_mock, ds_mock, initdb_mock):
        catalog = CatalogManager()
        dataset_name = "name"

        database_name = "database"
        metadata_obj = None

        ds_mock.return_value.dataset_object_by_name.return_value = metadata_obj

        actual = catalog.get_dataset_metadata(database_name, dataset_name)
        ds_mock.return_value.dataset_object_by_name.assert_called_with(
            database_name, dataset_name)
        dcs_mock.return_value.columns_by_id_and_dataset_id.assert_not_called()
        self.assertEqual(actual, metadata_obj)
Exemplo n.º 4
0
    def test_get_dataset_metadata_when_table_exists(self, dcs_mock, ds_mock,
                                                    initdb_mock):
        catalog = CatalogManager()
        dataset_name = "name"

        database_name = "database"
        schema = [1, 2, 3]
        id = 1
        metadata_obj = MagicMock(id=id, schema=None)
        ds_mock.return_value.dataset_object_by_name.return_value = metadata_obj
        dcs_mock.return_value. \
            columns_by_id_and_dataset_id.return_value = schema

        actual = catalog.get_dataset_metadata(database_name, dataset_name)
        ds_mock.return_value.dataset_object_by_name.assert_called_with(
            database_name, dataset_name)
        dcs_mock.return_value.columns_by_id_and_dataset_id.assert_called_with(
            id, None)
        self.assertEqual(actual.id, id)
        self.assertEqual(actual.schema, schema)
Exemplo n.º 5
0
def bind_table_info(table_info: TableInfo) -> DataFrameMetadata:
    """
    Uses catalog to bind the dataset information for given video string.

    Arguments:
         video_info (TableInfo): video information obtained in SQL query

    Returns:
        DataFrameMetadata  -  corresponding metadata for the input table info
    """
    catalog = CatalogManager()
    obj = catalog.get_dataset_metadata(table_info.database_name,
                                       table_info.table_name)
    if obj:
        table_info.table_obj = obj
    else:
        error = '{} does not exists. Create the table using \
                        CREATE TABLE.'.format(table_info.table_name)
        logger.error(error)
        raise RuntimeError(error)