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

(WIP) Refactor blocking rule for clarity #1699

Closed
wants to merge 2 commits into from
Closed

Conversation

RobinL
Copy link
Member

@RobinL RobinL commented Nov 6, 2023

Type of PR

  • BUG
  • FEAT
  • MAINT
  • DOC

Summary

This PR attempts to clarify the BlockingRule class. It is a step towards enabling ExplodingBlockingRules

Things changed:

Clarify name of sql property

🤔 Previously BlockingRule had a sqlproperty which was unused, and a property calledblocking_rulewhich returned the sql. The later was confusing: did it return aBlockingRule` or a sql string?.

Solution: There's now a single property called blocking_rule_sql

Better iteration

-🤔 When UNION ALLing blocking rules, iteration was difficult because a salted blocking rule produces a list of blocking rules as br.salted_blocking_rules, but if it was not salted, you needed to access the blocking rules directly.

So iteration looks like this:

    for br in blocking_rules:
        # Apply our salted rules to resolve skew issues. If no salt was
        # selected to be added, then apply the initial blocking rule.
        if apply_salt:
            salted_blocking_rules = br.salted_blocking_rules
        else:
            salted_blocking_rules = [br.blocking_rule]

Solution: To access all blocking rules and salted blocking rules, the user should now use br.salted_blocking_rule_segments, which is iterable (has 1 element in the case of no salting)

Moving SQL up into BlockingRule class

Previously the SQL statement to be UNION ALLed didn't live with the BlockingRule

      sql = f"""
            select
            {sql_select_expr}
            , '{br.match_key}' as match_key
            {probability}
            from {linker._input_tablename_l} as l
            inner join {linker._input_tablename_r} as r
            on
            ({salted_br})
            {br.and_not_preceding_rules_sql}
            {where_condition}
            """

That was fine when there was only one variant, but to allow [ExplodingBlockingRules](https://github.com/moj-analytical-services/splink/pull/1692) this SQL will change depending on the type of blocking rule

@RobinL RobinL marked this pull request as draft November 6, 2023 16:41
@RobinL RobinL changed the title Refactor blocking rule for clarity (WIP) Refactor blocking rule for clarity Nov 6, 2023
@RobinL RobinL closed this Nov 7, 2023
@RobinL
Copy link
Member Author

RobinL commented Nov 7, 2023

Closed in favour of #1700 #1701

@RobinL RobinL deleted the refactor_blockingrule branch August 12, 2024 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant