forked from moj-analytical-services/splink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EP-2625 Use a transform to add a frame clause - required for redshift…
… conversion of generated sql
- Loading branch information
1 parent
2911daf
commit 1ec00a6
Showing
2 changed files
with
10 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,11 @@ | ||
import sqlglot | ||
from sqlglot import expressions as exp | ||
import re | ||
|
||
|
||
def cast_concat_as_varchar(node): | ||
if isinstance(node, exp.Column): | ||
if isinstance(node.parent, exp.Cast): | ||
return node | ||
def add_frame_clause(node): | ||
sql = node.sql() | ||
sql = re.sub(r'(partition by \w+ order by \w+ desc)', | ||
r'\1 rows between unbounded preceding and current row', | ||
sql, flags=re.IGNORECASE) | ||
return sqlglot.parse_one(sql) | ||
|
||
if node.find_ancestor(exp.DPipe): | ||
sql = f"cast({node.sql()} as varchar)" | ||
return sqlglot.parse_one(sql) | ||
|
||
return node |