Пример #1
0
def stream_insert_rows_to_bq(client: bigquery.client.Client, table: str,
                             rows: list) -> list:
    """
	Inserts rows into BigQuery

	Parameters
	----------
	client : google.cloud.bigquery.client.Client
		BigQuery Client

	table_id : str
		if of the table {dataset}.{tablename} e.g. stocks.quotes

	rows : list of dicts
		List of dictionaries to insert into table

	Returns
	-------
	List of Errors (if any).
	"""
    errors = client.insert_rows(table, rows)

    if not all(x == [] for x in errors):
        print('Error: Not all rows inserted...')

    return errors
Пример #2
0
def InsertintoDB(Bikelist: list, client: bigquery.client.Client) -> bool:
    """take a list of bike sales, output them into the DB
    Setup DB connection, for loop through insert rows
    """

    table_id = "CanyonOutletBikeSaleData.CanyonOutletBikeSaleDataTable"
    table = client.get_table(table_id)  # Make an API request.
    rows_to_insert = Bikelist

    errors = client.insert_rows(table, rows_to_insert)  # Make an API request.
    if errors != []:
        print("ERROR: New rows have not been added, errors = " + str(errors))
        return False
    else:
        print("rows inserted = " + str(len(Bikelist)))
        return True