Created
June 13, 2023 11:41
-
-
Save Hosuke/dfdab9cd571ee133afe54ec84ea8a4f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import os | |
import re | |
# Get the current directory | |
dir_path = os.getcwd() | |
pattern = re.compile(r'LEFT ANTI JOIN (\w+) t ON (t.\w+) = (\w+.\w+)') | |
def replace_anti_join(match): | |
table_name = match.group(1) | |
join_col = match.group(2) | |
target_col = match.group(3) | |
return f'LEFT JOIN {table_name} t ON {join_col} = {target_col} WHERE {join_col} IS NULL' | |
# Traverse all files and subdirectories in the current directory | |
for root, dirs, files in os.walk(dir_path): | |
for file_name in files: | |
# Rewrite TIMESTAMP()/timestamp() in the file content | |
with open(os.path.join(root, file_name), 'r') as f: | |
content = f.read() | |
updated_query = pattern.sub(replace_anti_join, content) | |
with open(os.path.join(root, file_name), 'w') as f: | |
f.write(updated_query) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment