google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

Batch commit can be better explained in MutationsBatcher documentation

Open BBeran opened this issue 4 years ago • 2 comments

Environment details

  • OS type and version: ChromeOS
  • Python version: Python 3.7.3
  • pip version: pip 18.1
  • google-cloud-bigtable version: 2.4.0

Steps to reproduce

  1. Read the docs for MutationBatcher. Which states " if it reaches the max number of rows it calls finish_batch() to mutate the current row batch."
  2. Use finish_batch(rows) or just finish_batch() in your code then observe error

Code example

client = Client(project='my-project-ID', credentials=credentials)
instance = client.instance('instanceName')
table = instance.table('tableName')
batcher = table.mutations_batcher(flush_count=100000)

for files in os.listdir():
    if files.startswith('prefix'):
        with open(files, newline='') as csvfile:
            csvreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
            for crow in csvreader:
                rows = []
                row = table.row(crow[0])
                row.set_cell("location", "latitude", crow[1])
                row.set_cell("location", "longitude", crow[2])
                rows.append(row)
                batcher.finish_batch(rows)

Stack trace

Traceback (most recent call last):
  File "bigtable.py", line 43, in <module>
    batcher.finish_batch(rows)
AttributeError: 'MutationsBatcher' object has no attribute 'finish_batch'

Using batcher.flush() instead works.

BBeran avatar Dec 22 '21 19:12 BBeran

Transferring to google-cloud-python as the code for python-bigtable will be migrated there in 1-3 weeks.

parthea avatar Jan 12 '26 21:01 parthea

This issue is being bulk closed due to inactivity. Please re-open if you think this still requires attention, and we'll take another look. Thanks!

daniel-sanche avatar May 28 '26 00:05 daniel-sanche