def update_fact_params(client: bigquery.client.Client, params: Dict[str, Any]):
    """Updates params with lists of facts, and numerical and categorical facts."""
    sessions_table = client.get_table(params['sessions_table'])
    params['facts'] = fact.Fact.extract_facts(sessions_table)
    params['numeric_facts'] = fact.Fact.get_numeric_facts(params['facts'])
    params['categorical_facts'] = fact.Fact.get_categorical_facts(
        params['facts'])
Esempio n. 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
Esempio n. 3
0
    def upload_path_summary(self, client: bigquery.client.Client,
                            path_summary_table: str) -> None:
        """Uploads the path summary data to the given path_summary_table.

    Args:
      client: BigQuery Client
      path_summary_table: Name of the table to write the path summaries.
    """
        job_config = bigquery.LoadJobConfig()
        job_config.source_format = bigquery.SourceFormat.NEWLINE_DELIMITED_JSON
        job_config.autodetect = False
        job = client.load_table_from_file(
            self._path_summary_to_json_stringio(),
            client.get_table(path_summary_table),
            job_config=job_config)
        job.result()  # Waits for table load to complete.