prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Improve guidance for streaming inserts
  Suggesting we update the insert_rows.py code to showcase how to explicitly define a schema to avoid excessive calls to get_table().
  
  </issue>
  <code>
  [start of samples/table_insert_rows.py]
  1 # Copyright 2019 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 #     https://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 
  16 def table_insert_rows(table_id):
  17 
  18     # [START bigquery_table_insert_rows]
  19 
  20     from google.cloud import bigquery
  21 
  22     # Construct a BigQuery client object.
  23     client = bigquery.Client()
  24 
  25     # TODO(developer): Set table_id to the ID of the model to fetch.
  26     # table_id = "your-project.your_dataset.your_table"
  27 
  28     table = client.get_table(table_id)  # Make an API request.
  29     rows_to_insert = [(u"Phred Phlyntstone", 32), (u"Wylma Phlyntstone", 29)]
  30 
  31     errors = client.insert_rows(table, rows_to_insert)  # Make an API request.
  32     if errors == []:
  33         print("New rows have been added.")
  34     # [END bigquery_table_insert_rows]
  35
  [end of samples/table_insert_rows.py]
  [start of samples/table_insert_rows_explicit_none_insert_ids.py]
  1 # Copyright 2019 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 #     https://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 
  16 def table_insert_rows_explicit_none_insert_ids(table_id):
  17 
  18     # [START bigquery_table_insert_rows_explicit_none_insert_ids]
  19 
  20     from google.cloud import bigquery
  21 
  22     # Construct a BigQuery client object.
  23     client = bigquery.Client()
  24 
  25     # TODO(developer): Set table_id to the ID of the model to fetch.
  26     # table_id = "your-project.your_dataset.your_table"
  27 
  28     table = client.get_table(table_id)  # Make an API request.
  29     rows_to_insert = [(u"Phred Phlyntstone", 32), (u"Wylma Phlyntstone", 29)]
  30 
  31     errors = client.insert_rows(
  32         table, rows_to_insert, row_ids=[None] * len(rows_to_insert)
  33     )  # Make an API request.
  34     if errors == []:
  35         print("New rows have been added.")
  36     # [END bigquery_table_insert_rows_explicit_none_insert_ids]
  37
  [end of samples/table_insert_rows_explicit_none_insert_ids.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/samples/table_insert_rows.py b/samples/table_insert_rows.py
  --- a/samples/table_insert_rows.py
  +++ b/samples/table_insert_rows.py
  @@ -16,19 +16,22 @@
   def table_insert_rows(table_id):
   
       # [START bigquery_table_insert_rows]
  -
       from google.cloud import bigquery
   
       # Construct a BigQuery client object.
       client = bigquery.Client()
   
  -    # TODO(developer): Set table_id to the ID of the model to fetch.
  +    # TODO(developer): Set table_id to the ID of table to append to.
       # table_id = "your-project.your_dataset.your_table"
   
  -    table = client.get_table(table_id)  # Make an API request.
  -    rows_to_insert = [(u"Phred Phlyntstone", 32), (u"Wylma Phlyntstone", 29)]
  +    rows_to_insert = [
  +        {u"full_name": u"Phred Phlyntstone", u"age": 32},
  +        {u"full_name": u"Wylma Phlyntstone", u"age": 29},
  +    ]
   
  -    errors = client.insert_rows(table, rows_to_insert)  # Make an API request.
  +    errors = client.insert_rows_json(table_id, rows_to_insert)  # Make an API request.
       if errors == []:
           print("New rows have been added.")
  +    else:
  +        print("Encountered errors while inserting rows: {}".format(errors))
       # [END bigquery_table_insert_rows]
  diff --git a/samples/table_insert_rows_explicit_none_insert_ids.py b/samples/table_insert_rows_explicit_none_insert_ids.py
  --- a/samples/table_insert_rows_explicit_none_insert_ids.py
  +++ b/samples/table_insert_rows_explicit_none_insert_ids.py
  @@ -16,21 +16,24 @@
   def table_insert_rows_explicit_none_insert_ids(table_id):
   
       # [START bigquery_table_insert_rows_explicit_none_insert_ids]
  -
       from google.cloud import bigquery
   
       # Construct a BigQuery client object.
       client = bigquery.Client()
   
  -    # TODO(developer): Set table_id to the ID of the model to fetch.
  +    # TODO(developer): Set table_id to the ID of table to append to.
       # table_id = "your-project.your_dataset.your_table"
   
  -    table = client.get_table(table_id)  # Make an API request.
  -    rows_to_insert = [(u"Phred Phlyntstone", 32), (u"Wylma Phlyntstone", 29)]
  +    rows_to_insert = [
  +        {u"full_name": u"Phred Phlyntstone", u"age": 32},
  +        {u"full_name": u"Wylma Phlyntstone", u"age": 29},
  +    ]
   
  -    errors = client.insert_rows(
  -        table, rows_to_insert, row_ids=[None] * len(rows_to_insert)
  +    errors = client.insert_rows_json(
  +        table_id, rows_to_insert, row_ids=[None] * len(rows_to_insert)
       )  # Make an API request.
       if errors == []:
           print("New rows have been added.")
  +    else:
  +        print("Encountered errors while inserting rows: {}".format(errors))
       # [END bigquery_table_insert_rows_explicit_none_insert_ids]
  
verification_info: {"golden_diff": "diff --git a/samples/table_insert_rows.py b/samples/table_insert_rows.py\n--- a/samples/table_insert_rows.py\n+++ b/samples/table_insert_rows.py\n@@ -16,19 +16,22 @@\n def table_insert_rows(table_id):\n \n     # [START bigquery_table_insert_rows]\n-\n     from google.cloud import bigquery\n \n     # Construct a BigQuery client object.\n     client = bigquery.Client()\n \n-    # TODO(developer): Set table_id to the ID of the model to fetch.\n+    # TODO(developer): Set table_id to the ID of table to append to.\n     # table_id = \"your-project.your_dataset.your_table\"\n \n-    table = client.get_table(table_id)  # Make an API request.\n-    rows_to_insert = [(u\"Phred Phlyntstone\", 32), (u\"Wylma Phlyntstone\", 29)]\n+    rows_to_insert = [\n+        {u\"full_name\": u\"Phred Phlyntstone\", u\"age\": 32},\n+        {u\"full_name\": u\"Wylma Phlyntstone\", u\"age\": 29},\n+    ]\n \n-    errors = client.insert_rows(table, rows_to_insert)  # Make an API request.\n+    errors = client.insert_rows_json(table_id, rows_to_insert)  # Make an API request.\n     if errors == []:\n         print(\"New rows have been added.\")\n+    else:\n+        print(\"Encountered errors while inserting rows: {}\".format(errors))\n     # [END bigquery_table_insert_rows]\ndiff --git a/samples/table_insert_rows_explicit_none_insert_ids.py b/samples/table_insert_rows_explicit_none_insert_ids.py\n--- a/samples/table_insert_rows_explicit_none_insert_ids.py\n+++ b/samples/table_insert_rows_explicit_none_insert_ids.py\n@@ -16,21 +16,24 @@\n def table_insert_rows_explicit_none_insert_ids(table_id):\n \n     # [START bigquery_table_insert_rows_explicit_none_insert_ids]\n-\n     from google.cloud import bigquery\n \n     # Construct a BigQuery client object.\n     client = bigquery.Client()\n \n-    # TODO(developer): Set table_id to the ID of the model to fetch.\n+    # TODO(developer): Set table_id to the ID of table to append to.\n     # table_id = \"your-project.your_dataset.your_table\"\n \n-    table = client.get_table(table_id)  # Make an API request.\n-    rows_to_insert = [(u\"Phred Phlyntstone\", 32), (u\"Wylma Phlyntstone\", 29)]\n+    rows_to_insert = [\n+        {u\"full_name\": u\"Phred Phlyntstone\", u\"age\": 32},\n+        {u\"full_name\": u\"Wylma Phlyntstone\", u\"age\": 29},\n+    ]\n \n-    errors = client.insert_rows(\n-        table, rows_to_insert, row_ids=[None] * len(rows_to_insert)\n+    errors = client.insert_rows_json(\n+        table_id, rows_to_insert, row_ids=[None] * len(rows_to_insert)\n     )  # Make an API request.\n     if errors == []:\n         print(\"New rows have been added.\")\n+    else:\n+        print(\"Encountered errors while inserting rows: {}\".format(errors))\n     # [END bigquery_table_insert_rows_explicit_none_insert_ids]\n", "issue": "Improve guidance for streaming inserts\nSuggesting we update the insert_rows.py code to showcase how to explicitly define a schema to avoid excessive calls to get_table().\n", "before_files": [{"content": "# Copyright 2019 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#     https://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\n\ndef table_insert_rows(table_id):\n\n    # [START bigquery_table_insert_rows]\n\n    from google.cloud import bigquery\n\n    # Construct a BigQuery client object.\n    client = bigquery.Client()\n\n    # TODO(developer): Set table_id to the ID of the model to fetch.\n    # table_id = \"your-project.your_dataset.your_table\"\n\n    table = client.get_table(table_id)  # Make an API request.\n    rows_to_insert = [(u\"Phred Phlyntstone\", 32), (u\"Wylma Phlyntstone\", 29)]\n\n    errors = client.insert_rows(table, rows_to_insert)  # Make an API request.\n    if errors == []:\n        print(\"New rows have been added.\")\n    # [END bigquery_table_insert_rows]\n", "path": "samples/table_insert_rows.py"}, {"content": "# Copyright 2019 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#     https://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\n\ndef table_insert_rows_explicit_none_insert_ids(table_id):\n\n    # [START bigquery_table_insert_rows_explicit_none_insert_ids]\n\n    from google.cloud import bigquery\n\n    # Construct a BigQuery client object.\n    client = bigquery.Client()\n\n    # TODO(developer): Set table_id to the ID of the model to fetch.\n    # table_id = \"your-project.your_dataset.your_table\"\n\n    table = client.get_table(table_id)  # Make an API request.\n    rows_to_insert = [(u\"Phred Phlyntstone\", 32), (u\"Wylma Phlyntstone\", 29)]\n\n    errors = client.insert_rows(\n        table, rows_to_insert, row_ids=[None] * len(rows_to_insert)\n    )  # Make an API request.\n    if errors == []:\n        print(\"New rows have been added.\")\n    # [END bigquery_table_insert_rows_explicit_none_insert_ids]\n", "path": "samples/table_insert_rows_explicit_none_insert_ids.py"}]}