Skip to content

Python to construct CASE WHEN update SQL statement #970

@elad2109

Description

@elad2109

I try to update 2K rows in BQ

def update_bq_ads_status_failed(self, update_ads):
        affected_rows = 0
        for update_ads_chunk in split(update_ads, _UPDATE_CHUNK_SIZE):
            ad_ids = [item["ad_id"] for item in update_ads_chunk]
            removal_errors = [item["removal_error"] for item in update_ads_chunk]

            update_removal_error = ""
            for ad_id, removal_error in zip(ad_ids, removal_errors):
                update_removal_error = update_removal_error + \
                                       f''' WHEN ad_id = '{ad_id}' Then '{removal_error}' '''
            affected_rows += self.update_bq_ads_status(f"""
                            UPDATE '{table_full_name}' 
                            SET status = 'Failed Removing'  
                SET removal_error = CASE {update_removal_error} END 
                WHERE ad_id IN {str(ad_ids)}
                """)
        return affected_rows

I'm getting this error. I know it's too vague and not possible to debug like this.

timeout=300.0, headers={'X-Server-Timeout': '300.0',
'Accept-Encoding': 'gzip', 'Content-Type': 'application/json',
'X-Goog-API-Client': 'gl-python/3.8.10 grpc/1.39.0 gax/2.0.0
gapic/2.26.0 gccl/2.26.0', 'User-Agent': 'gl-python/3.8.10 grpc/1.39.0
gax/2.0.0 gapic/2.26.0 gccl/2.26.0'})), last exception: ('Connection
aborted.', RemoteDisconnected('Remote end closed connection without
response'))

I'm trying to eliminate errors. Is my BQ update syntactically correct?

What's the BQ update timeout?

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions