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

Consistency in usage of sql_dialect, sql_dialect_str, sqlglot_dialect #2391

Merged
merged 21 commits into from
Sep 16, 2024

Conversation

RobinL
Copy link
Member

@RobinL RobinL commented Sep 9, 2024

This PR addresses inconsistent usage of variable names for SQL dialects across the Splink codebase.

Currently, there is ambiguity between variable names such as sql_dialect, sql_dialect_str, dialect, sqlglot_name, and sqlglot_dialect. The confusion stems from the differences between the SQLGlot library, which uses string representations of SQL dialects (e.g., "spark", "duckdb"), and Splink’s own SplinkDialect, which can be instantiated from strings (e.g., SplinkDialect.from_string("duckdb")). These representations can be inconsistent, such as "athena" in Splink being "presto" in SQLGlot.

This PR ensures consistent naming conventions:

  • sqlglot_dialect for referring to the SQL dialect string used by the SQLGlot library.
  • sql_dialect for the Splink dialect object.
  • sql_dialect_str for Splink's string representation of the dialect.

One important test I did to make sure this works correctly is in dialects.py modify to:

class DuckDBDialect(SplinkDialect):
    _dialect_name_for_factory = "splink_ddb_alias"

    @property
    def sql_dialect_str(self):
        return "splink_ddb_alias"

    @property
    def sqlglot_dialect(self):
        return "duckdb"

and run

Click to expand
import splink.comparison_library as cl
from splink import DuckDBAPI, Linker, SettingsCreator, block_on, splink_datasets

db_api = DuckDBAPI()

df = splink_datasets.fake_1000

settings = SettingsCreator(
    link_type="dedupe_only",
    comparisons=[
        cl.ExactMatch("first_name"),
        cl.ExactMatch("surname"),
        cl.ExactMatch("dob"),
        cl.ExactMatch("city").configure(term_frequency_adjustments=True),
        cl.ExactMatch("email"),
    ],
    blocking_rules_to_generate_predictions=[
        block_on("first_name"),
        block_on("surname"),
    ],
    max_iterations=2,
)

linker = Linker(df, settings, db_api)

linker.training.estimate_probability_two_random_records_match(
    [block_on("first_name", "surname")], recall=0.7
)

linker.training.estimate_u_using_random_sampling(max_pairs=1e6)

linker.training.estimate_parameters_using_expectation_maximisation(block_on("dob"))

pairwise_predictions = linker.inference.predict(threshold_match_weight=-10)



settings2 = linker.misc.save_model_to_json()

linker2 = Linker(df, settings2, db_api)

linker2.inference.predict(threshold_match_weight=-10)

To validate that it works, and that splink_ddb_alias appears for sql_dialect in the json settings dictionary

@ADBond I've asked you for a review no urgency on this one!

@RobinL RobinL changed the title (WIP) Consistency in usage of sql_dialect, sql_dialect_str, sqlglot_dialect Consistency in usage of sql_dialect, sql_dialect_str, sqlglot_dialect Sep 10, 2024
@RobinL RobinL requested a review from ADBond September 10, 2024 08:22
Copy link
Contributor

@ADBond ADBond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great!

Thanks for going through and fixing all of this, imagine it was fairly tedious to get this all aligned

@RobinL
Copy link
Member Author

RobinL commented Sep 16, 2024

Thanks. Yes it was, ha ha! Though the type hinting/mypy work you did made it far easier

@RobinL RobinL merged commit 13771e0 into master Sep 16, 2024
25 checks passed
@RobinL RobinL deleted the clarify_dialects branch September 16, 2024 15:53
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.

2 participants