-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MINOR: modified nosql factory to not use pymongo (#15316)
- Loading branch information
Showing
7 changed files
with
97 additions
and
108 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
ingestion/src/metadata/profiler/adaptors/adaptor_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2024 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. | ||
""" | ||
factory for NoSQL adaptors that are used in the NoSQLProfiler. | ||
""" | ||
|
||
from metadata.generated.schema.entity.services.connections.database.mongoDBConnection import ( | ||
MongoDBConnection, | ||
) | ||
from metadata.profiler.adaptors.mongodb import MongoDB | ||
from metadata.profiler.factory import Factory | ||
from metadata.utils.logger import profiler_logger | ||
|
||
logger = profiler_logger() | ||
|
||
|
||
class NoSQLAdaptorFactory(Factory): | ||
def create(self, interface_type: str, *args, **kwargs) -> any: | ||
logger.debug(f"Creating NoSQL client for {interface_type}") | ||
client_class = self._interface_type.get(interface_type) | ||
if not client_class: | ||
raise ValueError(f"Unknown NoSQL source: {interface_type}") | ||
logger.debug(f"Using NoSQL client constructor: {client_class.__name__}") | ||
return client_class(*args, **kwargs) | ||
|
||
|
||
adaptors = profilers = { | ||
MongoDBConnection.__name__: MongoDB, | ||
} | ||
factory = NoSQLAdaptorFactory() | ||
factory.register_many(adaptors) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 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. | ||
|
||
""" | ||
Factory class for creating profiler interface objects | ||
""" | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class Factory(ABC): | ||
"""Creational factory for interface objects""" | ||
|
||
def __init__(self): | ||
self._interface_type = {} | ||
|
||
def register(self, interface_type: str, interface_class): | ||
"""Register a new interface""" | ||
self._interface_type[interface_type] = interface_class | ||
|
||
def register_many(self, interface_dict): | ||
""" | ||
Registers multiple profiler interfaces at once. | ||
Args: | ||
interface_dict: A dictionary mapping connection class names (strings) to their | ||
corresponding profiler interface classes. | ||
""" | ||
for interface_type, interface_class in interface_dict.items(): | ||
self.register(interface_type, interface_class) | ||
|
||
@abstractmethod | ||
def create(self, interface_type: str, *args, **kwargs) -> any: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters