我试图使用Spectrify以Parquet格式将数据从Redshift卸载到S3,但是由于无法理解某些事情,我陷入了困境。 Spectrify文档不是很好,我在互联网上找不到任何实现示例。我在StackOverflow上也发现了类似的问题,但是可以接受的答案是建议使用Spectrify并没有太大帮助。

这是问题所在(这是其文档中的代码):

from spectrify.export import RedshiftDataExporter
from spectrify.convert import ConcurrentManifestConverter
from spectrify.utils.schema import SqlAlchemySchemaReader

RedshiftDataExporter(sa_engine, s3_config).export_to_csv('my_table')

csv_path_template = 's3://my-bucket/my-table/csv/{start.year}/{start.month:02d}/{start.day:02d}'
spectrum_path_template = 's3://my-bucket/my-table/spectrum/partition_key={start}'
csv_path = csv_path_template.format(start=start_date)
spectrum_path = spectrum_path_template.format(start=start_date)
s3_config = SimpleS3Config(csv_path, spectrum_path)

sa_table = SqlAlchemySchemaReader(engine).get_table_schema('my_table')
ConcurrentManifestConverter(sa_table, s3_config).convert_manifest()




RedshiftDataExporter用于将数据导出到CSV,sa_engine是Redshift引擎的连接。

他们的文档在转换过程中含糊不清。在Python 3.x脚本中使用Spectrify时,应如何使用该过程将数据卸载到CSV,然后将其转换为Parquet格式?我应该如何修改上面的代码,我还缺少什么?

最佳答案

您现在可以在没有任何第三方应用程序的情况下以Parquet格式将Redshift数据卸载到S3。 Redshift现在支持该新功能:

UNLOAD ('select-statement')
TO 's3://object-path/name-prefix'
FORMAT PARQUET


可以在UNLOAD - Amazon Redshift上找到文档

07-24 09:45
查看更多