0

我尝试更新 BQ 中的 2K 行

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

我收到这个错误。我知道这太模糊了,不可能像这样调试。

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','用户代理':'gl-python/3.8.10 grpc/1.39.0 gax/2.0.0 gapic/2.26.0 gccl/2.26.0'})),最后一个例外:('连接中止。',RemoteDisconnected('远程结束关闭连接没有响应'))

我正在尝试消除错误。我的 BQ 更新在语法上是否正确?

BQ 更新超时是多少?

4

1 回答 1

1

UPDATE最后一条语句的几个问题:

  • 避免引用表名之类的标识符(除非 GBQ 允许)
  • SET应使用一次,用逗号分隔多个列
  • WHERE在需要括号的条件下插入方括号

考虑调整后的代码:

update_removal_error = " ".join(
    f"WHEN ad_id = '{ad_id}' THEN '{removal_error}'"
    for ad_id, removal_error in zip(ad_ids, removal_errors)
)

affected_rows += self.update_bq_ads_status(f"""
    UPDATE {table_full_name}
    SET status = 'Failed Removing'  
      , removal_error = CASE {update_removal_error} END 
     WHERE ad_id IN {tuple(ad_ids)}
""")
于 2021-09-14T02:37:55.703 回答