Parquet content-defined chunking hashes values it does not write for some list columns, and panics on list views
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 22/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- rust
- Ambito
- data-engineering
Direzione di ricerca
Start with the nested branch of ContentDefinedChunker::calculate in parquet/src/column/chunker/cdc.rs, where the hash reads values[leaf_offset], and with ArrayLevels::slice_for_chunk and non_null_indices in parquet/src/arrow/arrow_writer/levels.rs. Run the four reproduction tests in the issue (sliced_list, fixed_size_list_with_null_rows, list_view_in_reverse, overlapping_list_views) in a debug build. Done when the two page-boundary tests produce identical pages for equal data, and the two list-view tests no longer panic.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
With content-defined chunking enabled, ArrowWriter chooses the page boundaries of a column with repetition levels by hashing values[leaf_offset], where leaf_offset counts the column's leaf levels from 0. This happens in the nested branch of ContentDefinedChunker::calculate, in parquet/src/column/chunker/cdc.rs, where #9644 added leaf_offset. It assumes that the written values are the first slots of the leaf array, in order, which is not true for:
- lists and maps whose offsets don't start at 0, such as a sliced
ListArray, or the parts of a batch thatArrowWriter::writesplits between row groups - the child slots of the null rows of a
FixedSizeListArray, and of null list entries that own child values, which have no levels ListViewArrays, whose offsets can go backwards or overlap
So page boundaries depend on values that are not written, and the same data can be written with different pages. List views can also panic. When offsets go backwards, ArrayLevels::slice_for_chunk subtracts the first index of a chunk from smaller ones. When views overlap, hashing reads past the end of the values.
To Reproduce
As an integration test of the parquet crate:
use std::sync::Arc;
use arrow_array::types::Int32Type;
use arrow_array::{
Array, ArrayRef, FixedSizeListArray, Int32Array, ListArray, ListViewArray, RecordBatch,
UInt32Array,
};
use arrow_buffer::{NullBuffer, ScalarBuffer};
use arrow_schema::{DataType, Field};
use arrow_select::take::take;
use bytes::Bytes;
use parquet::arrow::ArrowWriter;
use parquet::file::properties::{CdcOptions, WriterProperties};
use parquet::file::reader::{FileReader, SerializedFileReader};
use parquet::file::serialized_reader::ReadOptionsBuilder;
/// Writes `array` with content-defined chunking, and returns the first row of each page
fn page_starts(array: ArrayRef) -> Vec<i64> {
let batch = RecordBatch::try_from_iter([("c", array)]).unwrap();
let cdc = CdcOptions {
min_chunk_size: 256,
max_chunk_size: 1024,
norm_level: 0,
};
let props = WriterProperties::builder()
.set_content_defined_chunking(Some(cdc))
.build();
let mut buffer = Vec::new();
let mut writer = ArrowWriter::try_new(&mut buffer, batch.schema(), Some(props)).unwrap();
writer.write(&batch).unwrap();
writer.close().unwrap();
let options = ReadOptionsBuilder::new().with_page_index().build();
let reader = SerializedFileReader::new_with_options(Bytes::from(buffer), options).unwrap();
let pages = reader.metadata().page_index().unwrap().page_locations(0, 0).unwrap();
pages.iter().map(|page| page.first_row_index).collect()
}
fn values(n: i32) -> impl Iterator<Item = Option<Vec<Option<i32>>>> {
(0..n).map(|i| Some(vec![Some(i), (i % 7 != 0).then_some(i * 3)]))
}
#[test]
fn sliced_list() {
let list = ListArray::from_iter_primitive::<Int32Type, _, _>(values(10_000));
let sliced = list.slice(1000, 5000);
// The same rows, with offsets that start at 0
let copy = take(&sliced, &UInt32Array::from_iter_values(0..5000), None).unwrap();
assert_eq!(sliced.to_data(), copy.to_data());
assert_eq!(page_starts(Arc::new(sliced)), page_starts(copy));
}
#[test]
fn fixed_size_list_with_null_rows() {
let item = Arc::new(Field::new_list_field(DataType::Int32, true));
let nulls = NullBuffer::from_iter((0..10_000).map(|row| row % 3 != 0));
// The same valid rows, and different values in the slots of null rows
let list = |null_slot: i32| {
let values = (0..20_000).map(|v| match v / 2 % 3 {
0 => Some(null_slot + v),
_ => (v % 5 != 0).then_some(v),
});
let values = Arc::new(Int32Array::from_iter(values));
FixedSizeListArray::new(item.clone(), 2, values, Some(nulls.clone()))
};
let (a, b) = (list(0), list(1_000_000));
assert_eq!(a.to_data(), b.to_data());
assert_eq!(page_starts(Arc::new(a)), page_starts(Arc::new(b)));
}
#[test]
fn list_view_in_reverse() {
let list = ListArray::from_iter_primitive::<Int32Type, _, _>(values(10_000));
let item = Arc::new(Field::new_list_field(DataType::Int32, true));
let offsets = ScalarBuffer::from_iter((0..10_000).rev().map(|row| row * 2));
let sizes = ScalarBuffer::from_iter((0..10_000).map(|_| 2));
let view = ListViewArray::new(item, offsets, sizes, list.values().clone(), None);
page_starts(Arc::new(view));
}
#[test]
fn overlapping_list_views() {
let item = Arc::new(Field::new_list_field(DataType::Int32, true));
let offsets = ScalarBuffer::from_iter((0..10_000).map(|_| 0));
let sizes = ScalarBuffer::from_iter((0..10_000).map(|_| 2));
let values = Arc::new(Int32Array::from(vec![Some(1), None]));
let view = ListViewArray::new(item, offsets, sizes, values, None);
page_starts(Arc::new(view));
}
On main (17444b900), in a debug build:
sliced_listandfixed_size_list_with_null_rowsfail, as the pages start at different rows.list_view_in_reversepanics atparquet/src/arrow/arrow_writer/levels.rs:1285:54withattempt to subtract with overflow.overlapping_list_viewspanics atparquet/src/column/chunker/cdc.rs:488:44withrange end index 12 out of range for slice of length 8.
Expected behavior
Page boundaries depend only on the values written, so all four tests pass.
Additional context
This came up in the review of #12350. For ArrowWriter::write_with_selection, that PR hashes the values at the indices the writer writes (ArrayLevels::non_null_indices) rather than at leaf_offset. write could do the same, although that would not fix the panic in slice_for_chunk.
Willingness to contribute
No response
- Lingua principale
- Rust
- Stelle
- 3.7k
- Fork
- 1.5k
- Merge medio
- 2g 16h
- PR unite (30g)
- 183
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di apache/arrow-rs
-
parquet: `ArrowWriter::try_new` panics on a schema with a Union field instead of returning an errorAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
`RunArray::try_new` rejects run ends whose null buffer has no nullsForse già presa @Surajsuthar l’ha presa 2 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
apache/arrow-rs#12427 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Variant] `variant_get` string and binary cast errors show Rust builder type namesForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 61/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di apache/arrow-rs
Issue simili
-
area:ui effort:medium enhancement P7 source:agent
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
marketing
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
machine rename accepts a label already used by another machine, making --machine <label> ambiguousApertamaintainer-needed p2 remote triaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug help wanted ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
userFRM/egui-charts#4605 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno