我正在尝试使用Apache从Google获取文件。我试过了
filenames = ['https://drive.google.com/file/d/<file_id>']
with beam.Pipeline() as pipeline:
lines = (pipeline | beam.Create(filenames))
print(lines)
这将返回一个类似于PCollection[[19]: Create/Map(decode).None]
的字符串
我需要从Google读取一个文件,并将其写入GCS桶中。如何从Apache读取G驱动器文件?
发布于 2022-11-12 08:29:56
如果您没有要应用的复杂转换,我认为在这种情况下最好不要使用Beam
。
您可以使用Google Collab
( Google上的Juypiter),挂载您的gDrive并使用gCloud CLI复制文件。
您可以检查以下链接:
stackoverflow-copy-file-from-google-drive-to-gcs
您还可以使用API从Google Drive
检索文件并将它们复制到Cloud Storage
。
例如,您可以使用Python
客户端和以下软件包开发Python
脚本:
google-api-python-client
google-auth-httplib2
google-auth-oauthlib
google-cloud-storage
这个文章展示了一个例子。
发布于 2022-11-14 09:28:04
如果您想使用Beam进行此操作,可以编写一个函数。
def read_from_gdrive_and_yield_records(path):
...
然后把它当作
filenames = ['https://drive.google.com/file/d/<file_id>']
with beam.Pipeline() as pipeline:
paths = pipeline | beam.Create(filenames)
records = paths | beam.FlatMap(read_from_gdrive_and_emit_records)
records | beam.io.WriteToText('gs://...')
尽管如前所述,除非您有大量的文件,否则这可能是过分的。
https://stackoverflow.com/questions/74412693
复制