Skip to main content

arrow_json/reader/
null_array.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership
3// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements
4
5use std::sync::Arc;
6
7use arrow_array::{ArrayRef, NullArray};
8use arrow_schema::ArrowError;
9
10use crate::reader::tape::{Tape, TapeElement};
11use crate::reader::{ArrayDecoder, DecoderContext};
12
13#[derive(Default)]
14pub struct NullArrayDecoder {
15    ignore_type_conflicts: bool,
16}
17impl NullArrayDecoder {
18    pub fn new(ctx: &DecoderContext) -> Self {
19        Self {
20            ignore_type_conflicts: ctx.ignore_type_conflicts(),
21        }
22    }
23}
24
25impl ArrayDecoder for NullArrayDecoder {
26    fn decode(&mut self, tape: &Tape<'_>, pos: &[u32]) -> Result<ArrayRef, ArrowError> {
27        if !self.ignore_type_conflicts {
28            for p in pos {
29                if !matches!(tape.get(*p), TapeElement::Null) {
30                    return Err(tape.error(*p, "null"));
31                }
32            }
33        }
34        Ok(Arc::new(NullArray::new(pos.len())))
35    }
36}