quickwit-oss/tantivy

monotonic mapping broken for `get_docids_for_value_range`

Opened this issue · 0 comments

#[test]
fn test_bug_1() {
    use crate::ColumnarWriter;

    let mut columnar_writer = ColumnarWriter::default();

    // This column gets internally coerced to i64
    columnar_writer.record_numerical(0, "full", 0 as u64);

    let mut wrt: Vec<u8> = Vec::new();
    columnar_writer.serialize(1, &mut wrt).unwrap();

    let reader = ColumnarReader::open(wrt).unwrap();
    // Open the column as u64
    let column = reader.read_columns("full").unwrap()[0]
        .open()
        .unwrap()
        .coerce_numerical(crate::NumericalType::U64)
        .unwrap();
    let DynamicColumn::U64(column) = column else {
        panic!();
    };
    let mut docids = Vec::new();

    // The monotonic mapping incorrectly converts the value range
    let full_range = 0..=u64::MAX;
    column.get_docids_for_value_range(full_range, 0..1, &mut docids);
    assert_eq!(docids, vec![0]); // fails, returns []
}

Impact

get_docids_for_value_range is only used by fast field range, which opens the column as u64 lenient and has it's own conversion layer and is therefore unaffected.