首页 > 解决方案 > ETL 从谷歌云存储加载到 biquery

问题描述

我想从谷歌云存储上的数百个 CSV 文件中加载数据,并每天使用云数据流(最好使用 python SDK)将它们附加到 Bigquery 上的单个表中。你能告诉我我怎么能做到这一点吗?

谢谢

标签: pythongoogle-cloud-platformgoogle-bigquerygoogle-cloud-storagedataflow

解决方案


我们也可以通过 Python 来实现。请找到以下代码片段。

def format_output_json(element):
    """
    :param element: is the row data in the csv
    :return: a dictionary with key as column name and value as real data in a row of the csv.

    :row_indices: I have hard-coded here, but can get it at the run time.
    """
    row_indices = ['time_stamp', 'product_name', 'units_sold', 'retail_price']
    row_data = element.split(',')
    dict1 = dict()
    for i in range(len(row_data)):
        dict1[row_indices[i]] = row_data[i]

    return [dict1]

推荐阅读