14
14
import base64
15
15
import json
16
16
import os
17
- from app .model import MySqlConnectionInfo
17
+ from app .model import MySqlConnectionInfo , PostgresConnectionInfo
18
18
import sqlglot
19
19
import sys
20
20
30
30
sql = sys .stdin .read ()
31
31
32
32
33
- load_dotenv ()
33
+ load_dotenv (override = True )
34
34
manifest_json_path = os .getenv ("WREN_MANIFEST_JSON_PATH" )
35
35
function_list_path = os .getenv ("REMOTE_FUNCTION_LIST_PATH" )
36
36
connection_info_path = os .getenv ("CONNECTION_INFO_PATH" )
59
59
60
60
print ("### Starting the session context ###" )
61
61
print ("#" )
62
- session_context = SessionContext (encoded_str , function_list_path + f"{ data_source } .csv" )
62
+ session_context = SessionContext (encoded_str , function_list_path + f"/ { data_source } .csv" )
63
63
planned_sql = session_context .transform_sql (sql )
64
64
print ("# Planned SQL:\n " , planned_sql )
65
65
66
66
# Transpile the planned SQL
67
- dialect_sql = sqlglot .transpile (planned_sql , read = "trino" , write = data_source )[0 ]
67
+ dialect_sql = sqlglot .transpile (planned_sql , read = None , write = data_source )[0 ]
68
68
print ("# Dialect SQL:\n " , dialect_sql )
69
69
print ("#" )
70
70
71
71
if data_source == "bigquery" :
72
72
connection_info = BigQueryConnectionInfo .model_validate_json (json .dumps (connection_info ))
73
73
connection = DataSourceExtension .get_bigquery_connection (connection_info )
74
- df = connection .sql (dialect_sql ).limit (10 ).to_pandas ()
75
- print ("### Result ###" )
76
- print ("" )
77
- print (df )
78
74
elif data_source == "mysql" :
79
75
connection_info = MySqlConnectionInfo .model_validate_json (json .dumps (connection_info ))
80
76
connection = DataSourceExtension .get_mysql_connection (connection_info )
81
- df = connection .sql (dialect_sql ).limit (10 ).to_pandas ()
82
- print ("### Result ###" )
83
- print ("" )
84
- print (df )
77
+ elif data_source == "postgres" :
78
+ connection_info = PostgresConnectionInfo .model_validate_json (json .dumps (connection_info ))
79
+ connection = DataSourceExtension .get_postgres_connection (connection_info )
85
80
else :
86
- print ("Unsupported data source:" , data_source )
81
+ raise Exception ("Unsupported data source:" , data_source )
82
+
83
+ df = connection .sql (dialect_sql ).limit (10 ).to_pandas ()
84
+ print ("### Result ###" )
85
+ print ("" )
86
+ print (df )
0 commit comments