にファイルこんにちは、私は特定のS3バケットは、エラーの下に取得する赤方偏移から複数のテーブルをアンロードしようとしています:アンロード複数の赤方偏移からS3
psycopg2.InternalError: Specified unload destination on S3 is not empty. Consider using a different bucket/prefix, manually removing the target files in S3, or using the ALLOWOVERWRITE option.
私はunload_functionで「allowoverwrite」オプションを追加する場合、それは前overwrittingされますS3で最後のテーブルをアンロードします。あなたが同じ宛先にデータを保存していることを不平を言っている
import psycopg2
def unload_data(r_conn, aws_iam_role, datastoring_path, region, table_name):
unload = '''unload ('select * from {}')
to '{}'
credentials 'aws_iam_role={}'
manifest
gzip
delimiter ',' addquotes escape parallel off '''.format(table_name, datastoring_path, aws_iam_role)
print ("Exporting table to datastoring_path")
cur = r_conn.cursor()
cur.execute(unload)
r_conn.commit()
def main():
host_rs = 'dataingestion.*********.us******2.redshift.amazonaws.com'
port_rs = '5439'
database_rs = '******'
user_rs = '******'
password_rs = '********'
rs_tables = [ 'Employee', 'Employe_details' ]
iam_role = 'arn:aws:iam::************:role/RedshiftCopyUnload'
s3_datastoring_path = 's3://mysamplebuck/'
s3_region = 'us_*****_2'
print ("Exporting from source")
src_conn = psycopg2.connect(host = host_rs,
port = port_rs,
database = database_rs,
user = user_rs,
password = password_rs)
print ("Connected to RS")
for i, tabe in enumerate(rs_tables):
if tabe[0] == tabe[-1]:
print("No files to read!")
unload_data(src_conn, aws_iam_role = iam_role, datastoring_path = s3_datastoring_path, region = s3_region, table_name = rs_tables[i])
print (rs_tables[i])
if __name__=="__main__":
main()
あなたは「allowoverwrite」オプションを使用して問題があったことを言ったが、私は本当にあなたが何を意味するのか従ってdidntの - してくださいそれをより良く/異なって説明できますか? –
ありがとうございます。 iは以下のようにアンロード変数の 'allowoverwrite' 追加した場合: 'アン= '' アンロード ' に{} ' クレデンシャル 'aws_iam_role = {}' GZIP デリミタマニフェスト'(' *から{}を選択)'、 'addquotes escape allowoverwrite' '.format(table_name、datastoring_path、aws_iam_role)すべてのテーブルは、同時に次のテーブルで上書きするs3バケットに書き込むことができます。最後に、s3バケットの最後のテーブルを見ることができます。 –