簡體   English   中英

谷歌雲數據流示例

[英]Google cloud data flow exmaple

我試圖使用以下鏈接將多個 csv 文件從雲存儲插入到大查詢中,但出現錯誤“ attributeerror: 'filecoder' object has no attribute 'to_type_hint' ”。 有人可以幫我嗎

https://github.com/GoogleCloudPlatform/professional-services/blob/main/examples/dataflow-python-examples/batch-examples/cookbook-examples/pipelines/data_ingestion_configurable.py

看起來 FileCoder 錯誤地沒有從beam.coders.Coder繼承; 我懷疑修復此問題將使問題 go 消失。

無論如何,這里實際上最好使用 DoFn 而不是 Coder,例如

class CsvLineDecoder(beam.DoFn):
    """Encode and decode CSV data coming from the files."""

    def __init__(self, columns):
        self._columns = columns
        self._num_columns = len(columns)
        self._delimiter = ","

    def process(self, value):
        st = io.StringIO(value)
        cr = csv.DictWriter(st,
                            self._columns,
                            delimiter=self._delimiter,
                            quotechar='"',
                            quoting=csv.QUOTE_MINIMAL)
        return next(cr)

然后將其用作

(p
 | 'Read From Text - ' + input_file >> beam.io.ReadFromText(gs_path, skip_header_lines=1)
 | beam.ParDo(CsvLineDecoder(list(fields.keys())))
 ...)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM