Skip to content

Comments

fix: avoid panic if offset index not exists.#4761

Merged
tustvold merged 2 commits intoapache:masterfrom
RinChanNOWWW:fix
Sep 4, 2023
Merged

fix: avoid panic if offset index not exists.#4761
tustvold merged 2 commits intoapache:masterfrom
RinChanNOWWW:fix

Conversation

@RinChanNOWWW
Copy link
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

index_reader::read_pages_locations will return an empty Vec<PageLocation> if there isn't an offset index:

pub fn read_pages_locations<R: ChunkReader>(
    reader: &R,
    chunks: &[ColumnChunkMetaData],
) -> Result<Vec<Vec<PageLocation>>, ParquetError> {
    let fetch = chunks
        .iter()
        .fold(None, |range, c| acc_range(range, c.offset_index_range()));

    let fetch = match fetch {
        Some(r) => r,
        None => return Ok(vec![]),
    };

    let bytes = reader.get_bytes(fetch.start as _, fetch.end - fetch.start)?;
    let get = |r: Range<usize>| &bytes[(r.start - fetch.start)..(r.end - fetch.start)];

    chunks
        .iter()
        .map(|c| match c.offset_index_range() {
            Some(r) => decode_offset_index(get(r)),
            None => Err(general_err!("missing offset index")),
        })
        .collect()
}

However, it will be set as a Some(ParquetOffsetIndex) to ParquetMetaData's offset_index.

When we read data by a ChunkReader, we will get page locations of a column by i[rg_idx][self.column_idx]. But i[rg_idx] maybe empty and it will lead to panic!

What changes are included in this PR?

Check if offset_index is empty before getting PageLocations from it.

Are there any user-facing changes?

No.

@github-actions github-actions bot added the parquet Changes to the parquet crate label Sep 1, 2023
@tustvold
Copy link
Contributor

tustvold commented Sep 1, 2023

Could we get a test for this please?

@RinChanNOWWW
Copy link
Contributor Author

Could we get a test for this please?

Done. PTAL.

@tustvold tustvold merged commit 587250c into apache:master Sep 4, 2023
@tustvold
Copy link
Contributor

tustvold commented Sep 4, 2023

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquet Changes to the parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants