This is an automated email from the ASF dual-hosted git repository.
viirya pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 121666e464 Add more debugging info to StructBuilder validate_content
(#5357)
121666e464 is described below
commit 121666e464170d7dce41bfd61de001a19affde72
Author: Liang-Chi Hsieh <[email protected]>
AuthorDate: Thu Feb 1 00:36:34 2024 -0800
Add more debugging info to StructBuilder validate_content (#5357)
---
arrow-array/src/builder/struct_builder.rs | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/arrow-array/src/builder/struct_builder.rs
b/arrow-array/src/builder/struct_builder.rs
index 196ae8092b..917b58522f 100644
--- a/arrow-array/src/builder/struct_builder.rs
+++ b/arrow-array/src/builder/struct_builder.rs
@@ -18,7 +18,7 @@
use crate::builder::*;
use crate::{ArrayRef, StructArray};
use arrow_buffer::NullBufferBuilder;
-use arrow_schema::{DataType, Fields, IntervalUnit, TimeUnit};
+use arrow_schema::{DataType, Fields, IntervalUnit, SchemaBuilder, TimeUnit};
use std::any::Any;
use std::sync::Arc;
@@ -286,9 +286,21 @@ impl StructBuilder {
if self.fields.len() != self.field_builders.len() {
panic!("Number of fields is not equal to the number of
field_builders.");
}
- if !self.field_builders.iter().all(|x| x.len() == self.len()) {
- panic!("StructBuilder and field_builders are of unequal lengths.");
- }
+ self.field_builders.iter().enumerate().for_each(|(idx, x)| {
+ if x.len() != self.len() {
+ let builder = SchemaBuilder::from(&self.fields);
+ let schema = builder.finish();
+
+ panic!("{}", format!(
+ "StructBuilder ({:?}) and field_builder with index {}
({:?}) are of unequal lengths: ({} != {}).",
+ schema,
+ idx,
+ self.fields[idx].data_type(),
+ self.len(),
+ x.len()
+ ));
+ }
+ });
}
}
@@ -558,7 +570,9 @@ mod tests {
}
#[test]
- #[should_panic(expected = "StructBuilder and field_builders are of unequal
lengths.")]
+ #[should_panic(
+ expected = "StructBuilder (Schema { fields: [Field { name: \"f1\",
data_type: Int32, nullable: false, dict_id: 0, dict_is_ordered: false,
metadata: {} }, Field { name: \"f2\", data_type: Boolean, nullable: false,
dict_id: 0, dict_is_ordered: false, metadata: {} }], metadata: {} }) and
field_builder with index 1 (Boolean) are of unequal lengths: (2 != 1)."
+ )]
fn test_struct_array_builder_unequal_field_builders_lengths() {
let mut int_builder = Int32Builder::with_capacity(10);
let mut bool_builder = BooleanBuilder::new();