@argh.arg('<STR_LIT>', help='<STR_LIT>', required=True)<EOL>@argh.arg('<STR_LIT>', help='<STR_LIT>', type=str)<EOL>@argh.arg('<STR_LIT>', '<STR_LIT>',<EOL>help='<STR_LIT>',<EOL>type=to_int,<EOL>default=int(<NUM_LIT>))<EOL>@argh.arg('<STR_LIT>', '<STR_LIT>', type=to_int)<EOL>@argh.arg('<STR_LIT:-c>', '<STR_LIT>', type=to_int)<EOL>@argh.arg('<STR_LIT>',<EOL>type=argparse.FileType('<STR_LIT:r>'),<EOL>help='<STR_LIT>')<EOL>@argh.wrap_errors([KeyboardInterrupt] + clients.client_errors)<EOL>def insert_fake_data(hosts=None,<EOL>table=None,<EOL>num_records=<NUM_LIT>,<EOL>bulk_size=<NUM_LIT:1000>,<EOL>concurrency=<NUM_LIT>,<EOL>mapping_file=None):
with clients.client(hosts, concurrency=<NUM_LIT:1>) as client:<EOL><INDENT>schema, table_name = parse_table(table)<EOL>columns = retrieve_columns(client, schema, table_name)<EOL><DEDENT>if not columns:<EOL><INDENT>sys.exit('<STR_LIT>'.format(table))<EOL><DEDENT>print('<STR_LIT>')<EOL>print(json.dumps(columns, sort_keys=True, indent=<NUM_LIT:4>))<EOL>mapping = None<EOL>if mapping_file:<EOL><INDENT>mapping = json.load(mapping_file)<EOL><DEDENT>bulk_size = min(num_records, bulk_size)<EOL>num_inserts = int(math.ceil(num_records / bulk_size))<EOL>gen_row = create_row_generator(columns, mapping)<EOL>stmt = to_insert('<STR_LIT>'.format(**locals()), columns)[<NUM_LIT:0>]<EOL>print('<STR_LIT>')<EOL>print(stmt)<EOL>print('<STR_LIT>'.format(<EOL>num_inserts, bulk_size))<EOL>print('<STR_LIT>')<EOL>q = asyncio.Queue(maxsize=concurrency)<EOL>with clients.client(hosts, concurrency=concurrency) as client:<EOL><INDENT>active = [True]<EOL>def stop():<EOL><INDENT>asyncio.ensure_future(q.put(None))<EOL>active.clear()<EOL>loop.remove_signal_handler(signal.SIGINT)<EOL><DEDENT>if sys.platform != '<STR_LIT:win32>':<EOL><INDENT>loop.add_signal_handler(signal.SIGINT, stop)<EOL><DEDENT>bulk_seq = _bulk_size_generator(num_records, bulk_size, active)<EOL>with ThreadPoolExecutor() as e:<EOL><INDENT>tasks = asyncio.gather(<EOL>_gen_data_and_insert(q, e, client, stmt, gen_row, bulk_seq),<EOL>consume(q, total=num_inserts)<EOL>)<EOL>loop.run_until_complete(tasks)<EOL><DEDENT><DEDENT>
Generate random data and insert it into a table.

    This will read the table schema and then find suitable random data providers.
    Which provider is choosen depends on the column name and data type.

    Example:

        A column named `name` will map to the `name` provider.
        A column named `x` of type int will map to `random_int` because there
        is no `x` provider.

    Available providers are listed here:
        https://faker.readthedocs.io/en/latest/providers.html

        Additional providers:
        - auto_inc:
            Returns unique incrementing numbers.
            Automatically used for columns named "id" of type int or long
        - geo_point
            Returns [<lon>, <lat>]
            Automatically used for columns of type geo_point

    Args:
        hosts: <host>:[<port>] of the Crate node
        table: The table name into which the data should be inserted.
            Either fully qualified: `<schema>.<table>` or just `<table>`
        num_records: Number of records to insert.
            Usually a number but expressions like `1e4` work as well.
        bulk_size: The bulk size of the insert statements.
        concurrency: How many operations to run concurrently.
        mapping_file: A JSON file that defines a mapping from column name to
            fake-factory provider.
            The format is as follows:
            {
                "column_name": ["provider_with_args", ["arg1", "arg"]],
                "x": ["provider_with_args", ["arg1"]],
                "y": "provider_without_args"
            }