

class ChunkedInsert(object):
    """Batch up insert operations
    with ChunkedStorer(my_table) as storer:
        table.insert(row)

    Rows will be inserted in groups of 1000
    """

    def __init__(self, table, chunksize=1000):
        self.queue = []
        self.table = table
        self.chunksize = chunksize

    def insert(self, item):
        self.queue.append(item)
        if len(self.queue) > self.chunksize:
            self.table.insert_many(self.queue)
            self.queue = []

    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.table.insert_many(self.queue)
        self.queue = []

@@ -253,16 +253,44 @@
 ue = %5B%5D%0A
+        self.fields = set()%0A
         
@@ -356,151 +356,350 @@
 def 
-insert(self, item):%0A        self.queue.append(item)%0A        if len(self.queue) %3E self.chunksize:%0A            self.table.insert_many(self.queue)
+flush(self):%0A        for item in self.queue:%0A            for field in self.fields:%0A                item%5Bfield%5D = item.get(field)%0A        self.table.insert_many(self.queue)%0A        self.queue = %5B%5D%0A%0A    def insert(self, item):%0A        self.fields.update(item.keys())%0A        self.queue.append(item)%0A        if len(self.queue) %3E= self.chunksize:
 %0A   
@@ -708,34 +708,31 @@
        self.
-queue = %5B%5D
+flush()
 %0A%0A    def __
@@ -835,58 +835,12 @@
 elf.
-table.insert_many(self.queue)%0A        self.queue = %5B%5D
+flush()
 %0A

make sure all records have the same fields.