-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqlglot.py
More file actions
30 lines (26 loc) · 706 Bytes
/
sqlglot.py
File metadata and controls
30 lines (26 loc) · 706 Bytes
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
import sqlglot
def handler(pd: "pipedream"):
print(pd.steps["trigger"]["context"]["id"])
event = pd.steps["trigger"]["event"]
if event['path'] != '/translate':
return
# read body
body = pd.steps["trigger"]["event"]['body']
read_format = body['read_format']
write_format = body['write_format']
origin_sql = body['origin_sql']
result = sqlglot.transpile(origin_sql,
read=read_format,
write=write_format)
print(result)
translate_sql = result[0]
# Return data for use in future steps
body = {
'status': 0,
'msg': 'transpile successe',
'data': {
'translate_sql': translate_sql,
}
}
pd.respond({'status': 200, 'body': body})
return