Skip to content

sql_recommendations

sql_recommendations

Recommendations and assumptions for Magic ETL SQL conversion, loaded from YAML.

Package defaults ship in sql_recommendations.yaml. A project passes its own file of the same shape to load_recommendations. Config only: a rule sets a directive, there are no custom tile handler classes.

Resolution order for one directive on one tile, most to least specific: action type plus operation, action type, operation, default. Within a level a project rule beats a package rule.

Recommendation dataclass

Recommendation(
    id: str,
    directive: str,
    value: Any,
    why: str,
    source: str,
    action_type: str | None = None,
    operation: str | None = None,
)

One rule: set directive to value for tiles matching action_type/operation.

level property

level: int

0 = action type + operation, 1 = action type, 2 = operation, 3 = default.

RecommendationConfigError

Bases: ValueError

A recommendations YAML file is malformed.

RecommendationSet dataclass

RecommendationSet(rules: tuple[Recommendation, ...])

The rules in force for one conversion run.

resolve

resolve(
    action_type: str, operation: str | None, directive: str
) -> Recommendation | None

Return the most specific rule for directive, or None when no rule matches.

Source code in src/crew_dcs/classes/DomoDataflow/action/sql_recommendations.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def resolve(
    self, action_type: str, operation: str | None, directive: str
) -> Recommendation | None:
    """Return the most specific rule for ``directive``, or None when no rule matches."""
    tile_type = action_type.lower()
    best: Recommendation | None = None
    for rule in self.rules:
        if rule.directive != directive:
            continue
        if rule.action_type and rule.action_type.lower() != tile_type:
            continue
        if rule.operation and rule.operation.lower() != (operation or "").lower():
            continue
        if best is None or _rank(rule) < _rank(best):
            best = rule
    return best

load_recommendations

load_recommendations(
    project_path: Path | str | None = None,
    *,
    package_path: Path | str | None = None,
    include_defaults: bool = True,
) -> RecommendationSet

Load package defaults and an optional project override file.

Parameters:

Name Type Description Default
project_path Path | str | None

Project override YAML. Must exist when given.

None
package_path Path | str | None

Replace the shipped defaults file (used by tests and forks).

None
include_defaults bool

False loads only project_path.

True

Raises:

Type Description
FileNotFoundError

a given path does not exist.

RecommendationConfigError

a file is malformed.

Source code in src/crew_dcs/classes/DomoDataflow/action/sql_recommendations.py
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
def load_recommendations(
    project_path: Path | str | None = None,
    *,
    package_path: Path | str | None = None,
    include_defaults: bool = True,
) -> RecommendationSet:
    """Load package defaults and an optional project override file.

    Args:
        project_path: Project override YAML. Must exist when given.
        package_path: Replace the shipped defaults file (used by tests and forks).
        include_defaults: False loads only ``project_path``.

    Raises:
        FileNotFoundError: a given path does not exist.
        RecommendationConfigError: a file is malformed.
    """
    rules: list[Recommendation] = []
    if include_defaults:
        if package_path is not None:
            origin = str(package_path)
            text = Path(package_path).read_text(encoding="utf-8")
        else:
            origin = PACKAGE_RULES_RESOURCE
            text = (
                resources.files(__package__)
                .joinpath(PACKAGE_RULES_RESOURCE)
                .read_text(encoding="utf-8")
            )
        rules.extend(_parse_rules(text, _SOURCE_PACKAGE, origin))
    if project_path is not None:
        path = Path(project_path)
        rules.extend(
            _parse_rules(path.read_text(encoding="utf-8"), _SOURCE_PROJECT, str(path))
        )
    return RecommendationSet(rules=tuple(rules))