@@ -28,16 +28,26 @@ def _remove_trailing_slash(s):
28
28
def _prefix (pfx , schema , table ):
29
29
return _remove_trailing_slash (pfx ).format (schema = schema , table = table )
30
30
31
- def attach_trino_engine (env_var_prefix = 'TRINO' ):
32
- sqlstring = 'trino://{user}@{host}:{port}/ ' .format (
31
+ def attach_trino_engine (env_var_prefix = 'TRINO' , catalog = None , schema = None , verbose = False ):
32
+ sqlstring = 'trino://{user}@{host}:{port}' .format (
33
33
user = os .environ [f'{ env_var_prefix } _USER' ],
34
34
host = os .environ [f'{ env_var_prefix } _HOST' ],
35
35
port = os .environ [f'{ env_var_prefix } _PORT' ]
36
36
)
37
+ if catalog is not None :
38
+ sqlstring += f'/{ catalog } '
39
+ if schema is not None :
40
+ if catalog is None :
41
+ raise ValueError (f'connection schema specified without a catalog' )
42
+ sqlstring += f'/{ schema } '
43
+
37
44
sqlargs = {
38
45
'auth' : trino .auth .JWTAuthentication (os .environ [f'{ env_var_prefix } _PASSWD' ]),
39
46
'http_scheme' : 'https'
40
47
}
48
+
49
+ if verbose : print (f'using connect string: { sqlstring } ' )
50
+
41
51
engine = create_engine (sqlstring , connect_args = sqlargs )
42
52
connection = engine .connect ()
43
53
return engine
@@ -90,13 +100,16 @@ def ingest_unmanaged_parquet(df, schema, table, bucket, partition_columns=[], ap
90
100
if verbose : print (f'{ tmp } --> { dst } ' )
91
101
bucket .upload_file (tmp , dst )
92
102
93
- def unmanaged_parquet_tabledef (df , catalog , schema , table , bucket , partition_columns = [], verbose = False ):
103
+ def unmanaged_parquet_tabledef (df , catalog , schema , table , bucket ,
104
+ partition_columns = [],
105
+ typemap = {}, colmap = {},
106
+ verbose = False ):
94
107
if not isinstance (df , pd .DataFrame ):
95
108
raise ValueError ("df must be a pandas DataFrame" )
96
109
if not isinstance (partition_columns , list ):
97
110
raise ValueError ("partition_columns must be list of column names" )
98
111
99
- columnschema = create_table_schema_pairs (df )
112
+ columnschema = create_table_schema_pairs (df , typemap = typemap , colmap = colmap )
100
113
101
114
tabledef = f"create table if not exists { catalog } .{ schema } .{ table } (\n "
102
115
tabledef += f"{ columnschema } \n "
0 commit comments