>_ SEEDOFWHALE / INDEX

技术笔记目录

按主题找文章。点标题看正文,技术索引可直达原文或视频。

[译] Hardwood Beta 支持 S3 直读与 Parquet 谓词下推

授权转载与 AI 辅助翻译(非官方)
原作者及版权:© Gunnar Morling;首发:2026-04-02
英文原文:Hardwood Reaches Beta: S3, Predicate Push-Down, CLI, and More
授权:英文原文及本简体中文译文均按 CC BY-SA 4.0 分享。编辑改动:增加中文翻译、译注和分类导航;保留完整英文正文,调整排版,外嵌演示以链接呈现。未暗示原作者认可本译文。

分类:基础与工程作品 · Java、Parquet、S3、开源工具
博客首页目录 · 一手技术资料总索引

中文译文

译注:这是 1.0.0.Beta1 的历史发布说明,不是当前版本或新项目的安装推荐。

很高兴宣布 Hardwood 1.0.0.Beta1 发布!

Hardwood 是一个面向 Apache Parquet 的新解析器,着重减少依赖、提高性能。项目几周前首次发布后,一群规模不大但很活跃的贡献者聚到一起,推动了不少改进。这次发布加入了 S3 后端,可以直接解析对象存储里的文件;本地和远程文件都支持谓词下推。此外还有 Avro 绑定、用于检查 Parquet 文件的命令行工具等。项目网站 hardwood.dev 也上线了,里面有文档和 API 参考。

下面逐项展开。

S3 后端

Hardwood 现在可以解析 Amazon S3 上的文件,也能接入兼容其 API 的对象存储,比如 Cloudflare R2 或 Google Cloud Storage。这样不用先下载远程文件,就能直接解析。再配合列投影与谓词下推(见下文),只读一部分数据时可以显著减少网络 I/O;查询数据湖里的 Parquet 文件时,这一点尤其重要。

为了保住依赖少的特点,S3 功能不增加强制依赖,尤其没有引入 AWS S3 SDK 这样比较重的库。Hardwood 用 Java 内置 HTTP 客户端请求 S3 REST API,并自行实现 AWS SigV4 给请求签名。项目用整套官方 SigV4 测试向量验证签名器,以确保兼容参考实现。

认证通过一个简单的回调 API 完成。最简单的情况,可以像下面这样传访问密钥 ID 和访问密钥:

S3Source source = S3Source.builder()
  .region("us-east-1")
  .credentials(S3Credentials.of("AKIA...", "secret"))
  .build();

try (ParquetFileReader reader = ParquetFileReader.open(
    source.inputFile("s3://my-bucket/data/trips.parquet"))) {

  try (RowReader rows = reader.createRowReader()) {
    while (rows.hasNext()) {
      rows.next();
      long id = rows.getLong("id");
    }
  }
}

如果凭据是动态的或需要定期刷新,可以实现 S3CredentialsProvider 函数式接口:

S3Source source = S3Source.builder()
    .region("us-east-1")
    .credentials(() -> fetchCredentialsFromVault())
    .build();

也可以加装可选的 hardwood-aws-auth 模块,使用 AWS 的完整凭据链(环境变量、~/.aws/credentials、EC2/ECS 实例配置、SSO、Web Identity 等)。它依赖官方 AWS SDK 的 software.amazon.awssdk:auth 模块:

<dependency>
  <groupId>dev.hardwood</groupId>
  <artifactId>hardwood-aws-auth</artifactId>
</dependency>
import dev.hardwood.aws.auth.SdkCredentialsProviders;

S3Source source = S3Source.builder()
  .region("us-east-1")
  .credentials(SdkCredentialsProviders.defaultChain())
  .build();

S3 兼容服务、超时、重试等选项见 S3 后端文档。

谓词下推

查询远程存储里的文件,要尽可能少取数据。这样能减少网络 I/O、缩短查询时间,也能降低可能的流量费用。除了支持列投影,Hardwood 现在也支持谓词下推。Parquet 文件可以选择保存行组统计信息和列块各数据页的统计信息。在行组级别,若统计信息足以证明没有任何行符合条件,解析器就跳过整个行组。保留下来的行组还能借助列索引(逐页最小值和最大值)跳过部分数据页,避免不必要的解压和解码。

FilterPredicate API 可以用 eq、notEq、lt、ltEq、gt、gtEq、in、isNull 和 isNotNull 生成过滤条件:

// Simple filter
FilterPredicate filter = FilterPredicate.gt("age", 21);

// IN filter
FilterPredicate filter = FilterPredicate.in("department_id", 1, 3, 7);
FilterPredicate filter = FilterPredicate.inStrings(
    "city", "NYC", "LA", "Chicago");

// NULL checks
FilterPredicate filter = FilterPredicate.isNull("middle_name");
FilterPredicate filter = FilterPredicate.isNotNull("email");

可以用逻辑运算符 and、or 和 not 组合基本条件:

// Compound filter
FilterPredicate filter = FilterPredicate.and(
    FilterPredicate.gtEq("salary", 50000L),
    FilterPredicate.lt("age", 65)
);

获取 Parquet 行读取器或列读取器时,传入过滤谓词:

try (ParquetFileReader fileReader = ParquetFileReader.open(
    InputFile.of(path));

  RowReader rowReader = fileReader.createRowReader(filter)) {

  while (rowReader.hasNext()) {
    rowReader.next();
    // Only rows from non-skipped row groups are returned
  }
}

参考文档详谈了谓词下推,包括怎样和列投影配合、当前实现有什么限制。

Avro 绑定

如果应用本来就在处理 Avro 记录,比如 Kafka 流水线或 Flink 作业,可以用新模块 hardwood-avro 把 Parquet 文件直接读成 GenericRecord。把它和 hardwood-core 一起引入:

<dependency>
  <groupId>dev.hardwood</groupId>
  <artifactId>hardwood-avro</artifactId>
</dependency>

然后用 AvroReaders 获取读取器:

try (ParquetFileReader fileReader = ParquetFileReader.open(
      InputFile.of(path));

  AvroRowReader reader = AvroReaders.createRowReader(fileReader)) {

  while (reader.hasNext()) {
    GenericRecord record = reader.next();
    long id = (Long) record.get("id");
    GenericRecord address = (GenericRecord) record.get("address");
  }
}

列投影和谓词下推仍完整支持,不会比原生行读取 API 少功能。Schema 转换和类型映射与 parquet-java 的 AvroReadSupport 一致,所以迁移应当比较直接。完整细节见 Avro 文档。

hardwood-cli

我早有为 Hardwood 做命令行客户端的想法,本来打算 1.0 发布后再动手。结果我还没开始,Brandon Brown 就先做出了 CLI 的第一个版本。它能检查本地或对象存储上的 Parquet 文件:查看元数据和 Schema,检查字典和列索引,打印几行了解数据内容,也可以转成 JSON、CSV 等。

观看 asciinema 的功能演示。

想用 Hardwood CLI,可以从 GitHub 下载适合你平台的原生二进制。该版本提供 Linux 和 macOS(两者均有 x86_64、aarch64)以及 Windows(x86_64)的构建。

小结

除了这些主要变化,还支持键值元数据、数据页 CRC 校验等。细节见发布说明,新版本可从 Maven Central获取。感谢所有贡献者:Arnav Balyan、Said Boudjelda、Brandon Brown、Manish Ghildiyal、Nicolas Grondin、Rion Williams 和 Romain Manni-Bucau。谢谢大家!

Hardwood 到这里已经覆盖常见的 Parquet 读取场景。1.0 系列后续计划专注于性能优化、补齐 Bloom Filter 一类缺口并稳定公开 API。作者在发文时预计一两周内出首个 1.0 候选版,争取当月晚些时候发布 1.0.0.Final。按当时的计划,稍后在当年发布的 1.1 将重点加入写入能力及 VARIANT 列等当时还不太普及的 Parquet 特性。


English Original

Hardwood Reaches Beta: S3, Predicate Push-Down, CLI, and More

I am pleased to announce the release of Hardwood 1.0.0.Beta1!

Hardwood is a new parser for Apache Parquet, optimized for minimal dependencies and great performance. Since the project’s initial release just a few weeks back, a small yet very active community has come together and evolved Hardwood significantly. Today, we are shipping an S3 backend, allowing to parse files directly from object storage, predicate pushdown for both local and remote files, Avro bindings, a CLI for inspecting Parquet files, and much more. We’re also excited to launch a website for the project, hardwood.dev, which contains the documentation and API reference.

Let’s dig in.

S3 Backend

Hardwood now allows you to parse files from Amazon S3, or any API-compatible object storage such as Cloudflare R2 or Google Cloud Storage. This means you can parse remote files directly, without having to download them first. Together with column projection and predicate push-down (see below), this can drastically reduce network IO if you only want to access a certain subset of your data, which is key when querying Parquet files in a data lake.

Living up to Hardwood’s premise of having a minimal dependency footprint, the S3 feature adds no mandatory dependencies, in particular avoiding pulling in heavy dependencies such as the AWS S3 SDK. Instead, Hardwood issues requests to the S3 REST API using Java’s built-in HTTP client; requests are signed using a custom implementation of the AWS SigV4 algorithm. Complete compatibility with the reference implementation is ensured by validating the signer against the complete suite of the official SigV4 test vectors.

Authentication is done via a simple callback API; in the simplest case, access key id and secret access key can be specified like so:

S3Source source = S3Source.builder()
  .region("us-east-1")
  .credentials(S3Credentials.of("AKIA...", "secret"))
  .build();

try (ParquetFileReader reader = ParquetFileReader.open(
    source.inputFile("s3://my-bucket/data/trips.parquet"))) {

  try (RowReader rows = reader.createRowReader()) {
    while (rows.hasNext()) {
      rows.next();
      long id = rows.getLong("id");
    }
  }
}

For dynamic or refreshable credentials, you can implement the S3CredentialsProvider functional interface:

S3Source source = S3Source.builder()
    .region("us-east-1")
    .credentials(() -> fetchCredentialsFromVault())
    .build();

If you’d like to use the full AWS credential chain (env vars, ~/.aws/credentials, EC2/ECS instance profile, SSO, web identity), you can do so by adding the optional hardwood-aws-auth module (which in turn relies on the software.amazon.awssdk:auth module from the official AWS SDK):

<dependency>
  <groupId>dev.hardwood</groupId>
  <artifactId>hardwood-aws-auth</artifactId>
</dependency>
import dev.hardwood.aws.auth.SdkCredentialsProviders;

S3Source source = S3Source.builder()
  .region("us-east-1")
  .credentials(SdkCredentialsProviders.defaultChain())
  .build();

For S3-compatible services, timeout and retry configuration, and other options, see the S3 backend documentation.

Predicate Push-Down

When querying files on remote storage, it is essential to limit the amount of fetched data as much as possible, reducing network I/O and thus minimizing query times as well as any potential data transfer fees. For this purpose, Hardwood now also supports predicate push-down in addition to column projections. Parquet files can optionally contain statistics for row groups as well as for specific chunk pages. At the row-group level, entire row groups whose statistics prove no rows can match are skipped. Within matching row groups, the Column Index (per-page min/max statistics) is used to skip individual pages, avoiding unnecessary decompression and decoding.

The FilterPredicate API allows you to create filters based on the operators eq, notEq, lt, ltEq, gt, gtEq, in, isNull, and isNotNull.

// Simple filter
FilterPredicate filter = FilterPredicate.gt("age", 21);

// IN filter
FilterPredicate filter = FilterPredicate.in("department_id", 1, 3, 7);
FilterPredicate filter = FilterPredicate.inStrings(
    "city", "NYC", "LA", "Chicago");

// NULL checks
FilterPredicate filter = FilterPredicate.isNull("middle_name");
FilterPredicate filter = FilterPredicate.isNotNull("email");

The logical operators and, or, and not can be used to combine basic filters:

// Compound filter
FilterPredicate filter = FilterPredicate.and(
    FilterPredicate.gtEq("salary", 50000L),
    FilterPredicate.lt("age", 65)
);

Then, when obtaining a Parquet row or column reader, specify the filter predicate like so:

try (ParquetFileReader fileReader = ParquetFileReader.open(
    InputFile.of(path));

  RowReader rowReader = fileReader.createRowReader(filter)) {

  while (rowReader.hasNext()) {
    rowReader.next();
    // Only rows from non-skipped row groups are returned
  }
}

The reference documentation discusses predicate push-down in full depth, for instance touching on how to use this together with column projections as well as on some limitations of the current implementation.

Avro Bindings

If your application already works with Avro records, for instance in a Kafka pipeline or Flink job, the new hardwood-avro module lets you read Parquet files directly into GenericRecord instances. Add it alongside hardwood-core:

<dependency>
  <groupId>dev.hardwood</groupId>
  <artifactId>hardwood-avro</artifactId>
</dependency>

Then use the AvroReaders class to obtain a reader:

try (ParquetFileReader fileReader = ParquetFileReader.open(
      InputFile.of(path));

  AvroRowReader reader = AvroReaders.createRowReader(fileReader)) {

  while (reader.hasNext()) {
    GenericRecord record = reader.next();
    long id = (Long) record.get("id");
    GenericRecord address = (GenericRecord) record.get("address");
  }
}

Column projection and predicate push-down are fully supported, so you’re not giving anything up compared to the native row API. The schema conversion and type mapping match the behavior of parquet-java’s AvroReadSupport, which should make migration straightforward. See the Avro documentation for the full details.

hardwood-cli

Building a command line client for Hardwood was something which had been on my mind for a while, but initially I had planned to only do so after the 1.0 release. However, Brandon Brown stepped up to build a first version of the CLI before I even got around to it. It lets you examine Parquet files (both locally and on object storage), e.g. to take a look at their metadata and schema, inspect dictionaries and column indexes, print a few lines for getting a quick understanding of a file’s contents, convert them to JSON and CSV, and more.

You can see some of the features in action in this recording:

View the terminal recording on asciinema

To get started with the Hardwood CLI, download the right native binary for your platform from GitHub; we currently provide binaries for Linux (x86_64 and aarch64), macOS (x86_64 and aarch64), and Windows (x86_64).

Wrapping Up

Besides these key features, there’s also support for key/value metadata, Page CRC verification, and more. See the release notes for the details. You can grab the new release from Maven Central.

Hardwood wouldn’t be possible without the help of the following amazing folks from the open-source community, who contributed to this release: Arnav Balyan, Said Boudjelda, Brandon Brown, Manish Ghildiyal, Nicolas Grondin, Rion Williams, and Romain Manni-Bucau. Thank you all!

At this point, Hardwood handles the common Parquet reading use cases. For the remainder of the 1.0 release train, we are planning to focus on performance optimizations, close some gaps like Bloom filters, and stabilize the public API. You should expect a first 1.0 candidate in a week or two, with the 1.0.0.Final release hopefully following later this month.

Key features for the 1.1 release later this year will be write support as well as support for less widely adopted Parquet features such as VARIANT columns.

posted @ 2026-12-04 13:13  西门咬狗  阅读(4)  评论(0)    收藏  举报