Skip to content

Commit af258ce

Browse files
committed
export/import add tempfile_dir param
1 parent 47f4dc7 commit af258ce

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

aws_s3--1.0.0.sql

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ CREATE OR REPLACE FUNCTION aws_s3.table_import_from_s3 (
4949
secret_key text default null,
5050
session_token text default null,
5151
endpoint_url text default null,
52-
read_timeout integer default 60
52+
read_timeout integer default 60,
53+
tempfile_dir text default '/var/lib/postgresql/data/'
5354
) RETURNS int
5455
LANGUAGE plpython3u
5556
AS $$
@@ -112,7 +113,7 @@ AS $$
112113
body = response['Body']
113114
user_content_encoding = response.get('x-amz-meta-content-encoding')
114115

115-
with tempfile.NamedTemporaryFile() as fd:
116+
with tempfile.NamedTemporaryFile(dir=tempfile_dir) as fd:
116117
if (content_encoding and content_encoding.lower() == 'gzip') or (user_content_encoding and user_content_encoding.lower() == 'gzip'):
117118
with gzip.GzipFile(fileobj=body) as gzipfile:
118119
while fd.write(gzipfile.read(204800)):
@@ -144,14 +145,15 @@ CREATE OR REPLACE FUNCTION aws_s3.table_import_from_s3(
144145
s3_info aws_commons._s3_uri_1,
145146
credentials aws_commons._aws_credentials_1,
146147
endpoint_url text default null,
147-
read_timeout integer default 60
148+
read_timeout integer default 60,
149+
tempfile_dir text default '/var/lib/postgresql/data/'
148150
) RETURNS INT
149151
LANGUAGE plpython3u
150152
AS $$
151153

152154
plan = plpy.prepare(
153-
'SELECT aws_s3.table_import_from_s3($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) AS num_rows',
154-
['TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'INTEGER']
155+
'SELECT aws_s3.table_import_from_s3($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) AS num_rows',
156+
['TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'INTEGER', 'TEXT']
155157
)
156158
return plan.execute(
157159
[
@@ -182,6 +184,7 @@ CREATE OR REPLACE FUNCTION aws_s3.query_export_to_s3(
182184
endpoint_url text default null,
183185
read_timeout integer default 60,
184186
override boolean default false,
187+
tempfile_dir text default '/var/lib/postgresql/data/',
185188
OUT rows_uploaded bigint,
186189
OUT files_uploaded bigint,
187190
OUT bytes_uploaded bigint
@@ -245,7 +248,7 @@ AS $$
245248
counter += 1
246249
upload_file_path = get_unique_file_path(base_name, counter, extension)
247250

248-
with tempfile.NamedTemporaryFile() as fd:
251+
with tempfile.NamedTemporaryFile(dir=tempfile_dir) as fd:
249252
plan = plpy.prepare(
250253
"COPY ({query}) TO '{filename}' {options}".format(
251254
query=query,
@@ -278,15 +281,16 @@ CREATE OR REPLACE FUNCTION aws_s3.query_export_to_s3(
278281
endpoint_url text default null,
279282
read_timeout integer default 60,
280283
override boolean default false,
284+
tempfile_dir text default '/var/lib/postgresql/data/',
281285
OUT rows_uploaded bigint,
282286
OUT files_uploaded bigint,
283287
OUT bytes_uploaded bigint
284288
) RETURNS SETOF RECORD
285289
LANGUAGE plpython3u
286290
AS $$
287291
plan = plpy.prepare(
288-
'SELECT * FROM aws_s3.query_export_to_s3($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)',
289-
['TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'INTEGER', 'BOOLEAN']
292+
'SELECT * FROM aws_s3.query_export_to_s3($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)',
293+
['TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'INTEGER', 'BOOLEAN', 'TEXT']
290294
)
291295
return plan.execute(
292296
[

0 commit comments

Comments
 (0)