-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
43 lines (30 loc) · 1.18 KB
/
test.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
33
34
35
36
37
38
39
40
41
42
43
from jinja2 import Template
from utils.snow_connect import SnowflakeConnection
EXTERNAL_FUNC = "_snowsend" # The name of the external function
TRANSLATOR_UDF = "_request_translator"
class SnowSendTest:
"""
This class is used to deploy transalotor UDF & test the external function.
Attributes:
session: The session of the Snowflake connection.
Methods:
execute_sql_from_file: Execute the SQL commands from the file.
"""
def __init__(self):
self.session = SnowflakeConnection().get_session()
def execute_sql_from_file(self, filename):
with open(f"utils/{filename}", "r") as f:
sql_commands = f.read()
template = Template(sql_commands)
sql_commands = template.render(
func_name=EXTERNAL_FUNC, translator_func_name=TRANSLATOR_UDF
)
print(f"The SQL commands to be executed:\n {sql_commands}")
self.session.sql(sql_commands).collect()
if __name__ == "__main__":
executor = SnowSendTest()
try:
executor.execute_sql_from_file("request_translator.sql")
executor.execute_sql_from_file("alter_external_function.sql")
except Exception as e:
print(e)