MapBuilder can't build a MapArray with sorted keys

オープン 初心者向け
#12,468 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
68/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust

調査の方向性

Rust の MapBuilder 実装から始めます。finish_helper は keys_sorted に固定値 false を渡して MapArray::new_unchecked を呼び出しており、make_builder は DataType::Map の sorted フラグを無視しています。with_keys_field および with_values_field の隣に with_keys_sorted(bool) メソッドを追加し、フラグを保存して finish_helper に渡してください。issue の StructBuilder の例がパニックなしでビルドでき、結果の MapArray が keys_sorted を true と報告することをテストで確認できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

MapBuilder always builds maps with keys_sorted = false. finish_helper passes false to MapArray::new_unchecked and there's no way to change it. make_builder also ignores the flag on DataType::Map(field, sorted).

So a builder made from a schema that has a sorted map field produces a column that doesn't match its own field. Inside a struct it panics:

let fields = vec![Field::new_map(
    "m",
    "entries",
    Field::new("keys", DataType::Utf8, false),
    Field::new("values", DataType::Int32, true),
    true, // keys_sorted
    false,
)];
let mut builder = StructBuilder::from_fields(fields, 1);
builder
    .field_builder::<MapBuilder<Box<dyn ArrayBuilder>, Box<dyn ArrayBuilder>>>(0)
    .unwrap()
    .append(true)
    .unwrap();
builder.append(true);
builder.finish();
// panics: Incorrect datatype for StructArray field "m", expected a sorted Map, got an unsorted one

The only workaround today is to finish the map, take it apart with into_parts() and rebuild it with MapArray::new(.., true). That doesn't help when the map is a child of a StructBuilder or ListBuilder, because the parent calls ArrayBuilder::finish on the child itself. Downstream crates end up wrapping MapBuilder just to set the flag.

Describe the solution you'd like

  • Add MapBuilder::with_keys_sorted(bool), next to with_keys_field and with_values_field, defaulting to false.
  • Have make_builder pass the flag from DataType::Map.

The builder would only set the flag and not check key order, same as MapArray::try_new.

Describe alternatives you've considered

Validating the order in finish when the flag is set. That would need a comparison over arbitrary key types and would make finish fallible or panicking for something MapArray::try_new doesn't check either, so I'd leave it out.

Additional context

Related: #7100 / #7101 (with_keys_field), #11603 (FFI export dropped the keys sorted flag). I have a branch with the change and tests and can open a PR.

主要言語
Rust
スター
3.7k
フォーク
1.5k
平均マージ
2日 16時間
マージ済み PR(30日)
183

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/arrow-rs のほかの issue

apache/arrow-rs の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。