如何快速遍历Iceberg中一张非常大的表

问题描述 投票:0回答:1

我有一个关于查询大表的问题。

我们有一个 Hive 表,总共有 360 万条记录,每条记录有 120 个字段。并且我们想把这个表中的所有记录转移到其他数据库,比如pg、kafka等

目前我们这样做:

 Dataset<Row> dataset = connection.client.read().format("iceberg").load("default.table");
// here will  stuck for a very long time
dataset.foreachPartition(par ->{
    par.forEachRemaining(row ->{
       ```
    });
});

但它可能会在 foreach 过程中卡住很长时间。

我尝试了下面的方法,过程并没有长时间卡住,但是遍历速度很慢,遍历效率约为50条记录/秒。

HiveCatalog hiveCatalog = createHiveCatalog(props);
Table table = hiveCatalog.loadTable(TableIdentifier.of("default.table"));
CloseableIterable<Record> records = IcebergGenerics.read(table) .build();
records.forEach( record ->{
    ```
});

这两种方式都不能满足我们的需求。我的代码需要修改吗?

apache-spark hive apache-iceberg
1个回答
1
投票

除了逐行阅读之外,这里还有一个想法。

如果您的目标数据库可以直接导入文件,请尝试从 Iceberg 中检索文件并将其直接导入到数据库中。

示例代码如下:

   Iterable<DataFile> files = FindFiles.in(table)
        .inPartition(table.spec(), StaticDataTask.Row.of(1))
        .inPartition(table.spec(), StaticDataTask.Row.of(2))
        .collect();

您可以从数据文件中获取文件路径和格式。

© www.soinside.com 2019 - 2024. All rights reserved.