Skip to content

Commit f5b004c

Browse files
committed
clippy
1 parent 63fe9b8 commit f5b004c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

native/spark-expr/src/array_funcs/get_array_struct_fields.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717

1818
use arrow::array::{make_array, Array, GenericListArray, OffsetSizeTrait, StructArray};
19+
use arrow::buffer::NullBuffer;
1920
use arrow::datatypes::{DataType, FieldRef, Schema};
2021
use arrow::record_batch::RecordBatch;
2122
use datafusion::common::{
@@ -148,27 +149,28 @@ fn get_array_struct_fields<O: OffsetSizeTrait>(
148149
.values()
149150
.as_any()
150151
.downcast_ref::<StructArray>()
151-
.expect("A struct is expected");
152+
.expect("A StructType is expected");
152153

153154
let field = Arc::clone(&values.fields()[ordinal]);
154155
// Get struct column by ordinal
155-
let column = values.column(ordinal);
156+
let extracted_column = values.column(ordinal);
156157

157-
let data = if values.null_count() > column.null_count() {
158+
let data = if values.null_count() == extracted_column.null_count() {
159+
Arc::clone(extracted_column)
160+
} else {
158161
// In some cases the column obtained from struct by ordinal doesn't
159-
// represent all nulls which imposed by parent values.
162+
// represent all nulls that imposed by parent values.
160163
// This maybe caused by a low level reader bug and needs more investigation.
161-
// For this specific case we patch the null buffer for column taking them
162-
// from parent values
164+
// For this specific case we patch the null buffer for the column by merging nulls buffers
165+
// from parent and column
166+
let merged_nulls = NullBuffer::union(values.nulls(), extracted_column.nulls());
163167
make_array(
164-
column
168+
extracted_column
165169
.into_data()
166170
.into_builder()
167-
.nulls(values.nulls().cloned())
171+
.nulls(merged_nulls)
168172
.build()?,
169173
)
170-
} else {
171-
Arc::clone(column)
172174
};
173175

174176
let array = GenericListArray::new(

0 commit comments

Comments
 (0)