def as_bulk_queries(queries, bulk_size):
stmt_dict = defaultdict(list)<EOL>for stmt, args in queries:<EOL><INDENT>bulk_args = stmt_dict[stmt]<EOL>bulk_args.append(args)<EOL>if len(bulk_args) == bulk_size:<EOL><INDENT>yield stmt, bulk_args<EOL>del stmt_dict[stmt]<EOL><DEDENT><DEDENT>for stmt, bulk_args in stmt_dict.items():<EOL><INDENT>yield stmt, bulk_args<EOL><DEDENT>
Group a iterable of (stmt, args) by stmt into (stmt, bulk_args).

    bulk_args will be a list of the args grouped by stmt.

    len(bulk_args) will be <= bulk_size