prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Python to construct CASE WHEN update SQL statement
  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?
  
  </issue>
  <code>
  [start of google/cloud/bigquery/retry.py]
  1 # Copyright 2018 Google LLC
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #     http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 
  15 from google.api_core import exceptions
  16 from google.api_core import retry
  17 from google.auth import exceptions as auth_exceptions
  18 import requests.exceptions
  19 
  20 
  21 _RETRYABLE_REASONS = frozenset(
  22     ["rateLimitExceeded", "backendError", "internalError", "badGateway"]
  23 )
  24 
  25 _UNSTRUCTURED_RETRYABLE_TYPES = (
  26     ConnectionError,
  27     exceptions.TooManyRequests,
  28     exceptions.InternalServerError,
  29     exceptions.BadGateway,
  30     requests.exceptions.ChunkedEncodingError,
  31     requests.exceptions.ConnectionError,
  32     requests.exceptions.Timeout,
  33     auth_exceptions.TransportError,
  34 )
  35 
  36 _DEFAULT_JOB_DEADLINE = 60.0 * 10.0  # seconds
  37 
  38 
  39 def _should_retry(exc):
  40     """Predicate for determining when to retry.
  41 
  42     We retry if and only if the 'reason' is 'backendError'
  43     or 'rateLimitExceeded'.
  44     """
  45     if not hasattr(exc, "errors") or len(exc.errors) == 0:
  46         # Check for unstructured error returns, e.g. from GFE
  47         return isinstance(exc, _UNSTRUCTURED_RETRYABLE_TYPES)
  48 
  49     reason = exc.errors[0]["reason"]
  50     return reason in _RETRYABLE_REASONS
  51 
  52 
  53 DEFAULT_RETRY = retry.Retry(predicate=_should_retry, deadline=600.0)
  54 """The default retry object.
  55 
  56 Any method with a ``retry`` parameter will be retried automatically,
  57 with reasonable defaults. To disable retry, pass ``retry=None``.
  58 To modify the default retry behavior, call a ``with_XXX`` method
  59 on ``DEFAULT_RETRY``. For example, to change the deadline to 30 seconds,
  60 pass ``retry=bigquery.DEFAULT_RETRY.with_deadline(30)``.
  61 """
  62 
  63 DEFAULT_TIMEOUT = 5.0 * 60.0
  64 """The default API timeout.
  65 
  66 This is the time to wait per request. To adjust the total wait time, set a
  67 deadline on the retry object.
  68 """
  69 
  70 job_retry_reasons = "rateLimitExceeded", "backendError"
  71 
  72 
  73 def _job_should_retry(exc):
  74     if not hasattr(exc, "errors") or len(exc.errors) == 0:
  75         return False
  76 
  77     reason = exc.errors[0]["reason"]
  78     return reason in job_retry_reasons
  79 
  80 
  81 DEFAULT_JOB_RETRY = retry.Retry(
  82     predicate=_job_should_retry, deadline=_DEFAULT_JOB_DEADLINE
  83 )
  84 """
  85 The default job retry object.
  86 """
  87
  [end of google/cloud/bigquery/retry.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/google/cloud/bigquery/retry.py b/google/cloud/bigquery/retry.py
  --- a/google/cloud/bigquery/retry.py
  +++ b/google/cloud/bigquery/retry.py
  @@ -60,7 +60,7 @@
   pass ``retry=bigquery.DEFAULT_RETRY.with_deadline(30)``.
   """
   
  -DEFAULT_TIMEOUT = 5.0 * 60.0
  +DEFAULT_TIMEOUT = None
   """The default API timeout.
   
   This is the time to wait per request. To adjust the total wait time, set a
  
verification_info: {"golden_diff": "diff --git a/google/cloud/bigquery/retry.py b/google/cloud/bigquery/retry.py\n--- a/google/cloud/bigquery/retry.py\n+++ b/google/cloud/bigquery/retry.py\n@@ -60,7 +60,7 @@\n pass ``retry=bigquery.DEFAULT_RETRY.with_deadline(30)``.\n \"\"\"\n \n-DEFAULT_TIMEOUT = 5.0 * 60.0\n+DEFAULT_TIMEOUT = None\n \"\"\"The default API timeout.\n \n This is the time to wait per request. To adjust the total wait time, set a\n", "issue": "Python to construct CASE WHEN update SQL statement\nI try to update 2K rows in BQ \r\n\r\n\r\n\r\n\r\n```\r\ndef update_bq_ads_status_failed(self, update_ads):\r\n        affected_rows = 0\r\n        for update_ads_chunk in split(update_ads, _UPDATE_CHUNK_SIZE):\r\n            ad_ids = [item[\"ad_id\"] for item in update_ads_chunk]\r\n            removal_errors = [item[\"removal_error\"] for item in update_ads_chunk]\r\n\r\n            update_removal_error = \"\"\r\n            for ad_id, removal_error in zip(ad_ids, removal_errors):\r\n                update_removal_error = update_removal_error + \\\r\n                                       f''' WHEN ad_id = '{ad_id}' Then '{removal_error}' '''\r\n            affected_rows += self.update_bq_ads_status(f\"\"\"\r\n                            UPDATE '{table_full_name}' \r\n                            SET status = 'Failed Removing'  \r\n                SET removal_error = CASE {update_removal_error} END \r\n                WHERE ad_id IN {str(ad_ids)}\r\n                \"\"\")\r\n        return affected_rows\r\n```\r\n\r\n\r\nI'm getting this error. I know it's too vague and not possible to debug like this.\r\n\r\n> timeout=300.0, headers={'X-Server-Timeout': '300.0',\r\n> 'Accept-Encoding': 'gzip', 'Content-Type': 'application/json',\r\n> 'X-Goog-API-Client': 'gl-python/3.8.10 grpc/1.39.0 gax/2.0.0\r\n> gapic/2.26.0 gccl/2.26.0', 'User-Agent': 'gl-python/3.8.10 grpc/1.39.0\r\n> gax/2.0.0 gapic/2.26.0 gccl/2.26.0'})), last exception: ('Connection\r\n> aborted.', RemoteDisconnected('Remote end closed connection without\r\n> response'))\r\n\r\n\r\nI'm trying to eliminate errors. Is my BQ update syntactically correct? \r\n\r\nWhat's the BQ update timeout?\n", "before_files": [{"content": "# Copyright 2018 Google LLC\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nfrom google.api_core import exceptions\nfrom google.api_core import retry\nfrom google.auth import exceptions as auth_exceptions\nimport requests.exceptions\n\n\n_RETRYABLE_REASONS = frozenset(\n    [\"rateLimitExceeded\", \"backendError\", \"internalError\", \"badGateway\"]\n)\n\n_UNSTRUCTURED_RETRYABLE_TYPES = (\n    ConnectionError,\n    exceptions.TooManyRequests,\n    exceptions.InternalServerError,\n    exceptions.BadGateway,\n    requests.exceptions.ChunkedEncodingError,\n    requests.exceptions.ConnectionError,\n    requests.exceptions.Timeout,\n    auth_exceptions.TransportError,\n)\n\n_DEFAULT_JOB_DEADLINE = 60.0 * 10.0  # seconds\n\n\ndef _should_retry(exc):\n    \"\"\"Predicate for determining when to retry.\n\n    We retry if and only if the 'reason' is 'backendError'\n    or 'rateLimitExceeded'.\n    \"\"\"\n    if not hasattr(exc, \"errors\") or len(exc.errors) == 0:\n        # Check for unstructured error returns, e.g. from GFE\n        return isinstance(exc, _UNSTRUCTURED_RETRYABLE_TYPES)\n\n    reason = exc.errors[0][\"reason\"]\n    return reason in _RETRYABLE_REASONS\n\n\nDEFAULT_RETRY = retry.Retry(predicate=_should_retry, deadline=600.0)\n\"\"\"The default retry object.\n\nAny method with a ``retry`` parameter will be retried automatically,\nwith reasonable defaults. To disable retry, pass ``retry=None``.\nTo modify the default retry behavior, call a ``with_XXX`` method\non ``DEFAULT_RETRY``. For example, to change the deadline to 30 seconds,\npass ``retry=bigquery.DEFAULT_RETRY.with_deadline(30)``.\n\"\"\"\n\nDEFAULT_TIMEOUT = 5.0 * 60.0\n\"\"\"The default API timeout.\n\nThis is the time to wait per request. To adjust the total wait time, set a\ndeadline on the retry object.\n\"\"\"\n\njob_retry_reasons = \"rateLimitExceeded\", \"backendError\"\n\n\ndef _job_should_retry(exc):\n    if not hasattr(exc, \"errors\") or len(exc.errors) == 0:\n        return False\n\n    reason = exc.errors[0][\"reason\"]\n    return reason in job_retry_reasons\n\n\nDEFAULT_JOB_RETRY = retry.Retry(\n    predicate=_job_should_retry, deadline=_DEFAULT_JOB_DEADLINE\n)\n\"\"\"\nThe default job retry object.\n\"\"\"\n", "path": "google/cloud/bigquery/retry.py"}]}