Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed resolution of MQM factories #117

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions lib/dl_api_lib/dl_api_lib/query/registry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import (
Collection,
Optional,
Sequence,
Type,
)

Expand Down Expand Up @@ -87,25 +88,42 @@ class MQMFactorySettingItem:
_MQM_FACTORY_REGISTRY: dict[MQMFactoryKey, Type[MultiQueryMutatorFactoryBase]] = {}


def _get_default_mqm_factory_cls() -> Type[MultiQueryMutatorFactoryBase]:
return DefaultMultiQueryMutatorFactory


def get_multi_query_mutator_factory(
query_proc_mode: QueryProcessingMode,
backend_type: SourceBackendType,
dialect: DialectCombo,
result_schema: ResultSchema,
) -> Optional[MultiQueryMutatorFactoryBase]:
factory_cls = _MQM_FACTORY_REGISTRY.get(
# First try with exact dialect
) -> MultiQueryMutatorFactoryBase:
prioritized_keys = (
# First try with exact dialect and mode (exact match)
MQMFactoryKey(query_proc_mode=query_proc_mode, backend_type=backend_type, dialect=dialect),
_MQM_FACTORY_REGISTRY.get(
# Then try without the dialect, just the backend
MQMFactoryKey(query_proc_mode=query_proc_mode, backend_type=backend_type, dialect=None),
DefaultMultiQueryMutatorFactory, # If still nothing, then use the default
),
# Now the fallbacks begin...
# Try without the dialect (all dialects within backend), just the backend and mode
MQMFactoryKey(query_proc_mode=query_proc_mode, backend_type=backend_type, dialect=None),
# Fall back to `basic` mode (but still within the backend type)
# First try with the specific dialect
MQMFactoryKey(query_proc_mode=QueryProcessingMode.basic, backend_type=backend_type, dialect=dialect),
# If still nothing, try without specifying the dialect (all dialects within backend)
MQMFactoryKey(query_proc_mode=QueryProcessingMode.basic, backend_type=backend_type, dialect=None),
)

# Now iterate over all of these combinations IN THAT VERY ORDER(!)
factory_cls: Optional[Type[MultiQueryMutatorFactoryBase]] = None
for key in prioritized_keys:
factory_cls = _MQM_FACTORY_REGISTRY.get(key)
if factory_cls is not None:
break # found something

if factory_cls is None:
return None
# Not found for any of the combinations
# Use the ultimate default
factory_cls = _get_default_mqm_factory_cls()

assert factory_cls is not None
return factory_cls(result_schema=result_schema)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import abc
import logging
from typing import Sequence

import attr
Expand All @@ -14,6 +15,9 @@
from dl_query_processing.multi_query.mutators.base import MultiQueryMutatorBase


LOGGER = logging.getLogger(__name__)


class SRMultiQueryMutatorFactory(abc.ABC):
@abc.abstractmethod
def get_mqm_factory(
Expand Down Expand Up @@ -51,14 +55,10 @@ def get_mqm_factory(
dialect=dialect,
result_schema=dataset.result_schema,
)
if factory is None:
# Try again for the basic mode
factory = get_multi_query_mutator_factory(
query_proc_mode=QueryProcessingMode.basic,
backend_type=backend_type,
dialect=dialect,
result_schema=dataset.result_schema,
)

assert factory is not None
LOGGER.info(
f"Resolved MQM factory for backend_type {backend_type.name} "
f"and dialect {dialect.common_name_and_version} "
f"in {self._query_proc_mode.name} mode "
f"to {type(factory).__name__}"
)
return factory
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)
from dl_api_lib.query.registry import MQMFactorySettingItem
from dl_constants.enums import QueryProcessingMode
from dl_query_processing.multi_query.factory import NoCompengMultiQueryMutatorFactory

from dl_connector_bitrix_gds.api.api_schema.connection import BitrixGDSConnectionSchema
from dl_connector_bitrix_gds.api.connection_form.form_config import BitrixGDSConnectionFormFactory
Expand Down Expand Up @@ -47,6 +48,10 @@ class BitrixGDSApiConnector(ApiConnector):
query_proc_mode=QueryProcessingMode.basic,
factory_cls=BitrixGDSMultiQueryMutatorFactory,
),
MQMFactorySettingItem(
query_proc_mode=QueryProcessingMode.no_compeng,
factory_cls=NoCompengMultiQueryMutatorFactory,
),
)
connection_definitions = (BitrixGDSApiConnectionDefinition,)
source_definitions = (BitrixGDSApiSourceDefinition,)
Expand Down
Loading