Skip to content

Commit 47f4dc7

Browse files
committed
export_s3 add override param
1 parent 1a97a7d commit 47f4dc7

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

aws_s3--1.0.0.sql

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ CREATE OR REPLACE FUNCTION aws_s3.query_export_to_s3(
181181
options text default null,
182182
endpoint_url text default null,
183183
read_timeout integer default 60,
184+
override boolean default false,
184185
OUT rows_uploaded bigint,
185186
OUT files_uploaded bigint,
186187
OUT bytes_uploaded bigint
@@ -233,14 +234,16 @@ AS $$
233234
**aws_settings
234235
)
235236

236-
# generate unique file path
237-
file_path_parts = re.match(r'^(.*?)(\.[^.]*$|$)', file_path)
238-
base_name = file_path_parts.group(1)
239-
extension = file_path_parts.group(2)
240-
counter = 0
241-
while file_exists(bucket, get_unique_file_path(base_name, counter, extension), s3):
242-
counter += 1
243-
unique_file_path = get_unique_file_path(base_name, counter, extension)
237+
upload_file_path = file_path
238+
if not override:
239+
# generate unique file path
240+
file_path_parts = re.match(r'^(.*?)(\.[^.]*$|$)', upload_file_path)
241+
base_name = file_path_parts.group(1)
242+
extension = file_path_parts.group(2)
243+
counter = 0
244+
while file_exists(bucket, get_unique_file_path(base_name, counter, extension), s3):
245+
counter += 1
246+
upload_file_path = get_unique_file_path(base_name, counter, extension)
244247

245248
with tempfile.NamedTemporaryFile() as fd:
246249
plan = plpy.prepare(
@@ -261,7 +264,7 @@ AS $$
261264
num_lines += buffer.count(b'\n')
262265
size += len(buffer)
263266
fd.seek(0)
264-
s3.upload_fileobj(fd, bucket, unique_file_path)
267+
s3.upload_fileobj(fd, bucket, upload_file_path)
265268
if 'HEADER TRUE' in options.upper():
266269
num_lines -= 1
267270
yield (num_lines, 1, size)
@@ -274,15 +277,16 @@ CREATE OR REPLACE FUNCTION aws_s3.query_export_to_s3(
274277
options text default null,
275278
endpoint_url text default null,
276279
read_timeout integer default 60,
280+
override boolean default false,
277281
OUT rows_uploaded bigint,
278282
OUT files_uploaded bigint,
279283
OUT bytes_uploaded bigint
280284
) RETURNS SETOF RECORD
281285
LANGUAGE plpython3u
282286
AS $$
283287
plan = plpy.prepare(
284-
'SELECT * FROM aws_s3.query_export_to_s3($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
285-
['TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'TEXT', 'INTEGER']
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']
286290
)
287291
return plan.execute(
288292
[

0 commit comments

Comments
 (0)