boto3 icon indicating copy to clipboard operation
boto3 copied to clipboard

boto3.client('redshift-data') don't work with pg_last_copy_count()

Open dburtsev opened this issue 3 years ago • 2 comments
trafficstars

Describe the bug

pg_last_copy_count() Returns the number of rows that were loaded by the last COPY command run in the current session. boto3 returns 0

Expected Behavior

Returns the number of rows that were loaded by the last COPY command run in the current session.

Current Behavior

return 0

Reproduction Steps

import boto3

def ExecuteCopy(Boto3Client,ClusterIdentifier,Database,DbUser,Sql):
    boto3.set_stream_logger('')
    rows = 0
    Response1 = Boto3Client.execute_statement(ClusterIdentifier=ClusterIdentifier,Database=Database,DbUser=DbUser,Sql=Sql)
    Response2 = Boto3Client.describe_statement(Id=Response1['Id'])
    while Response2['Status'] in ['PICKED', 'STARTED', 'SUBMITTED']:
        Response2 = Boto3Client.describe_statement(Id=Response1['Id'])
    if Response2['Status'] != 'FINISHED':
        print("Expect FINISHED got " + Response2['Status'])
        raise ValueError("Expect FINISHED got " + Response2['Status'] + ' ' + Response2['Error'])
    Response1 = Boto3Client.execute_statement(ClusterIdentifier=ClusterIdentifier,Database=Database,DbUser=DbUser,Sql='select pg_last_copy_count();')
    Response2 = Boto3Client.describe_statement(Id=Response1['Id'])
    while Response2['Status'] in ['PICKED', 'STARTED', 'SUBMITTED']:
        Response2 = Boto3Client.describe_statement(Id=Response1['Id'])
    Response3 = sql_client.get_statement_result(Id=Response1['Id'])
    rows = Response3['Records'][0][0].get('longValue')
    print(Response3['Records'])
    return rows

sql_client = boto3.client('redshift-data', region_name = 'us-east-1')
ClusterIdentifier = 'qwe'
Database = 'qwe'
DbUser = 'qwe'
sql = "COPY dev.copy_test FROM 's3://mocsdw01/adhoc/copy_test.csv' FILLRECORD REMOVEQUOTES ESCAPE;"

i = ExecuteCopy(sql_client,ClusterIdentifier,Database,DbUser,sql)
print(i)

Possible Solution

No response

Additional Information/Context

No response

SDK version used

1.24.28

Environment details (OS name and version, etc.)

Windows 10

dburtsev avatar Aug 08 '22 17:08 dburtsev

stream logger stream_logger2.txt

dburtsev avatar Aug 08 '22 17:08 dburtsev

Hi @dburtsev thanks for reaching out. I saw that you created a few other recent issues related to the redshift-data service. Since these issues involve a service API rather than boto3, we try to track them in our cross-SDK repository.

Because there is already an internal ticket open with the Redshift team for one of your issues, it would probably be better to mention any related issues there so that we can continue updating the service team in the same ticket.

tim-finnigan avatar Aug 08 '22 21:08 tim-finnigan

Closing this and will follow up here on service API issue: https://github.com/aws/aws-sdk/issues/322

tim-finnigan avatar Aug 15 '22 16:08 tim-finnigan