Skip to content

Commit

Permalink
Merge pull request #270 from moj-analytical-services/sql_dialect_fix
Browse files Browse the repository at this point in the history
fix sql dialect bug
  • Loading branch information
RobinL authored Feb 2, 2022
2 parents 50a1ebf + f320dc2 commit eb72e8a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

SQLGlot produces SQL in the wrong dialect in some instances. See [issue 269](https://github.com/moj-analytical-services/splink/issues/269)

## 2.1.3

### Fixed

Versions of sqlglot before 1.18.0 could not parse the spark sql `left` and `right` functions - see [here](https://github.com/tobymao/sqlglot/issues/58).

As a result, if `left` or `right` are used in the user's custom sql case expressions, Splink will produce an error.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "splink"
version = "2.1.3"
version = "2.1.4"
description = "Implementation of Fellegi-Sunter's canonical model of record linkage in Apache Spark, including EM algorithm to estimate parameters"
authors = ["Robin Linacre <[email protected]>", "Sam Lindsay", "Theodore Manassis"]
license = "MIT"
Expand Down
6 changes: 2 additions & 4 deletions splink/parse_case_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,9 @@ def _parse_top_level_case_statement_from_sql(top_level_case_tree):
for i in ifs:
lit = i.args["true"].sql()

# sql = i.args["this"].sql()
sql = i.sql()
sql = i.args["this"].sql(dialect="spark")
sql = f"WHEN {sql} THEN {lit}".format(sql=sql, lit=lit)

sql = re.sub(r"^CASE ", "", sql)
sql = re.sub(r" END$", "", sql)
parsed_case_expr.append({"sql_expr": sql, "label": f"level_{lit}"})

if top_level_case_tree.args.get("default") is not None:
Expand Down

0 comments on commit eb72e8a

Please sign in to comment.