mirror of
				https://github.com/open-metadata/OpenMetadata.git
				synced 2025-10-31 02:29:03 +00:00 
			
		
		
		
	 95982b9395
			
		
	
	
		95982b9395
		
			
		
	
	
	
	
		
			
			* ref(profiler): use di for system profile - use source classes that can be overridden in system profiles - use a manifest class instead of factory to specify which class to resolve for connectors - example usage can be seen in redshift and snowflake * - added manifests for all custom profilers - used super() dependency injection in order for system metrics source - formatting * - implement spec for all source types - added docs for the new specification - added some pylint ignores in the importer module * remove TYPE_CHECKING in core.py * - deleted valuedispatch function - deleted get_system_metrics_by_dialect - implemented BigQueryProfiler with a system metrics source - moved import_source_class to BaseSpec * - removed tests related to the profiler factory * - reverted start_time - removed DML_STAT_TO_DML_STATEMENT_MAPPING - removed unused logger * - reverted start_time - removed DML_STAT_TO_DML_STATEMENT_MAPPING - removed unused logger * fixed tests * format * bigquery system profile e2e tests * fixed module docstring * - removed import_side_effects from redshift. we still use it in postgres for the orm conversion maps. - removed leftover methods * - tests for BaseSpec - moved get_class_path to importer * - moved constructors around to get rid of useless kwargs * - changed test_system_metric * - added linage and usage to service_spec - fixed postgres native lineage test * add comments on collaborative constructors
		
			
				
	
	
		
			113 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			113 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| #  Copyright 2021 Collate
 | |
| #  Licensed under the Apache License, Version 2.0 (the "License");
 | |
| #  you may not use this file except in compliance with the License.
 | |
| #  You may obtain a copy of the License at
 | |
| #  http://www.apache.org/licenses/LICENSE-2.0
 | |
| #  Unless required by applicable law or agreed to in writing, software
 | |
| #  distributed under the License is distributed on an "AS IS" BASIS,
 | |
| #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | |
| #  See the License for the specific language governing permissions and
 | |
| #  limitations under the License.
 | |
| 
 | |
| """
 | |
| Test import utilities
 | |
| """
 | |
| from unittest import TestCase
 | |
| 
 | |
| from metadata.generated.schema.entity.services.connections.database.mysqlConnection import (
 | |
|     MysqlConnection,
 | |
| )
 | |
| from metadata.generated.schema.entity.services.serviceType import ServiceType
 | |
| from metadata.utils.importer import (
 | |
|     get_class_name_root,
 | |
|     get_module_name,
 | |
|     get_source_module_name,
 | |
|     import_bulk_sink_type,
 | |
|     import_connection_fn,
 | |
|     import_from_module,
 | |
|     import_processor_class,
 | |
|     import_sink_class,
 | |
|     import_stage_class,
 | |
| )
 | |
| from metadata.utils.service_spec.service_spec import import_source_class
 | |
| 
 | |
| 
 | |
| # pylint: disable=import-outside-toplevel
 | |
| class ImporterTest(TestCase):
 | |
|     """
 | |
|     Validate that we properly convert
 | |
|     module paths and load classes.
 | |
|     """
 | |
| 
 | |
|     def test_get_module_name(self) -> None:
 | |
|         self.assertEqual(get_source_module_name("mysql"), "metadata")
 | |
|         self.assertEqual(get_source_module_name("redshift-usage"), "usage")
 | |
| 
 | |
|         self.assertEqual(get_module_name("query-parser"), "query_parser")
 | |
| 
 | |
|     def test_get_class_name(self) -> None:
 | |
|         self.assertEqual(get_class_name_root("mysql"), "Mysql")
 | |
|         self.assertEqual(get_class_name_root("redshift-usage"), "RedshiftUsage")
 | |
| 
 | |
|     def test_import_class(self) -> None:
 | |
|         from metadata.ingestion.source.database.mysql.metadata import MysqlSource
 | |
| 
 | |
|         self.assertEqual(
 | |
|             import_from_module(
 | |
|                 "metadata.ingestion.source.database.mysql.metadata.MysqlSource"
 | |
|             ),
 | |
|             MysqlSource,
 | |
|         )
 | |
| 
 | |
|     def test_import_source_class(self) -> None:
 | |
|         from metadata.ingestion.source.database.mysql.metadata import MysqlSource
 | |
| 
 | |
|         self.assertEqual(
 | |
|             import_source_class(service_type=ServiceType.Database, source_type="mysql"),
 | |
|             MysqlSource,
 | |
|         )
 | |
| 
 | |
|     def test_import_processor_class(self) -> None:
 | |
|         from metadata.ingestion.processor.query_parser import QueryParserProcessor
 | |
| 
 | |
|         self.assertEqual(
 | |
|             import_processor_class(processor_type="query-parser"),
 | |
|             QueryParserProcessor,
 | |
|         )
 | |
| 
 | |
|     def test_import_stage_class(self) -> None:
 | |
|         from metadata.ingestion.stage.table_usage import TableUsageStage
 | |
| 
 | |
|         self.assertEqual(import_stage_class(stage_type="table-usage"), TableUsageStage)
 | |
| 
 | |
|     def test_import_sink_class(self) -> None:
 | |
|         from metadata.ingestion.sink.metadata_rest import MetadataRestSink
 | |
| 
 | |
|         self.assertEqual(import_sink_class(sink_type="metadata-rest"), MetadataRestSink)
 | |
| 
 | |
|     def test_import_bulk_sink_type(self) -> None:
 | |
|         from metadata.ingestion.bulksink.metadata_usage import MetadataUsageBulkSink
 | |
| 
 | |
|         self.assertEqual(
 | |
|             import_bulk_sink_type(bulk_sink_type="metadata-usage"),
 | |
|             MetadataUsageBulkSink,
 | |
|         )
 | |
| 
 | |
|     def test_import_get_connection(self) -> None:
 | |
|         connection = MysqlConnection(
 | |
|             username="name",
 | |
|             hostPort="hostPort",
 | |
|         )
 | |
| 
 | |
|         get_connection_fn = import_connection_fn(
 | |
|             connection=connection, function_name="get_connection"
 | |
|         )
 | |
|         self.assertIsNotNone(get_connection_fn)
 | |
| 
 | |
|         self.assertRaises(
 | |
|             AttributeError,
 | |
|             import_connection_fn,
 | |
|             connection=connection,
 | |
|             function_name="random",
 | |
|         )
 |