-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.py
32 lines (23 loc) · 950 Bytes
/
translate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Reads queries from Metabase, translates the SQL and stores the translations in report_card_migrations table.
"""
from metabase import Properties, ReportCardRepo
from translator import SqlTranslator
def main():
props = Properties(open('metabase.yaml', 'r'))
repo = ReportCardRepo(props)
report_cards = repo.fetchall()
#report_cards = repo.fetch_by_ids([1024])
print(f"Retrieved {len(report_cards)} native queries")
report_card_migrations = []
for report_card in report_cards:
sql = report_card.dataset_query['native']['query']
translator = SqlTranslator(sql)
new_sql = translator.sql()
if new_sql != sql:
report_card_migrations.append(
repo.create_migration(report_card, new_sql))
repo.insert_migrations(report_card_migrations)
print(f"Wrote {len(report_card_migrations)} rows to report_card_migration")
if __name__ == '__main__':
main()