Last active
June 30, 2023 04:54
-
-
Save Hosuke/ef62e8c4af75ae8a3977832b7d76fc31 to your computer and use it in GitHub Desktop.
script to translate spark sql `timestamp()` to dune sql `timestamp`
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() | |
# 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() | |
if 'TIMESTAMP(' or 'timestamp(' in content: | |
print(f'Rewriting TIMESTAMP()/timestamp()" in {file_name}') | |
new_content = re.sub('DATE\\(\'(.*?)\'\\)', 'DATE \'\\1\' ', content) | |
new_content = re.sub('date\\(\'(.*?)\'\\)', 'DATE \'\\1\' ', new_content) | |
new_content = re.sub('TIMESTAMP\\(\'(.*?)\'\\)', 'DATE \'\\1\' ', content) | |
new_content = re.sub('timestamp\\(\'(.*?)\'\\)', 'DATE \'\\1\' ', new_content) | |
with open(os.path.join(root, file_name), 'w') as f: | |
f.write(new_content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment