【问题标题】:Loading larger than memory data into bcolz from Redshift从 Redshift 将大于内存的数据加载到 bcolz
【发布时间】:2016-05-22 20:04:30
【问题描述】:

我想在本地保存红移查询的输出。我曾尝试使用blaze/odo,但默认设置会在写入之前尝试将所有数据加载到内存中并尝试流式传输数据会引发其他错误,描述了另一个问题:Streaming results with Blaze and SqlAlchemy

由于该问题没有任何答案,我正在寻找一种替代方法。

什么是从 Redshift 将大于内存的查询结果加载到 bcolz 的简单、可靠且相当有效的方法?

【问题讨论】:

    标签: python sqlalchemy psycopg2 amazon-redshift bcolz


    【解决方案1】:

    我知道这是一个老问题,但如果遇到同样问题的人偶然发现它,我会回答它以提供帮助。我假设您使用 Blaze 访问 Redshift。您必须在某些列上对表进行分区并迭代地执行此操作,如下所示:

    import blaze as bz
    table = bz.Data('postgresql://server@example.com::table_name')
    val_list = bz.odo(table['column_name'].distinct(), list)
    np_dtype = table.schema[0].to_numpy_dtype()
    for val in val_list:
        table_partition = table[table['column_name'] == val]
        partition_len = int(table_partition.count())
        bcolz.fromiter(table_partition, np_dtype, partition_len,
                       rootdir='rootdir_for_partition', mode='w',
                       cparams=compression_params)
    

    然后使用 bcolz.walk 迭代结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 2018-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-28
      • 1970-01-01
      相关资源
      最近更新 更多