From 878ec3eca54120fd370a40cbf6603967e2fa1104 Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Tue, 10 Dec 2024 09:41:50 +0000 Subject: [PATCH] implement specific array builder for NullBuilder --- arrow-array/src/builder/null_builder.rs | 39 ++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/arrow-array/src/builder/null_builder.rs b/arrow-array/src/builder/null_builder.rs index 59086dffa907..1da3fcd64afa 100644 --- a/arrow-array/src/builder/null_builder.rs +++ b/arrow-array/src/builder/null_builder.rs @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -use crate::builder::ArrayBuilder; +use crate::builder::{SpecificArrayBuilder, ArrayBuilder}; use crate::{ArrayRef, NullArray}; use arrow_data::ArrayData; use arrow_schema::DataType; @@ -146,6 +146,43 @@ impl ArrayBuilder for NullBuilder { } } +impl SpecificArrayBuilder for NullBuilder { + type Output = NullArray; + type Item<'a> = (); + + fn finish(&mut self) -> Arc { + Arc::new(self.finish()) + } + + fn finish_cloned(&self) -> Arc { + Arc::new(self.finish_cloned()) + } + + fn append_value<'a>(&'a mut self, value: Self::Item<'a>) { + self.append_null(); + } + + fn append_value_ref<'a>(&'a mut self, value: &'a Self::Item<'a>) { + self.append_null(); + } + + fn append_null(&mut self) { + self.append_null(); + } + + fn append_output<'a>(&'a mut self, output: &'a Self::Output) { + self.len += output.len(); + } + + fn append_nulls(&mut self, n: usize) { + self.append_nulls(n) + } + + fn append_option<'a>(&'a mut self, v: Option>) { + self.append_null() + } +} + #[cfg(test)] mod tests { use super::*;