delta_kernel 0.25.0

Core crate providing a Delta/Deltalake implementation focused on interoperability with a wide range of query engines.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
//! Write-time validation for void type usage in schemas.
//!
//! The Delta protocol allows void columns in table metadata. Void columns are never written to
//! Parquet files; reads generate null values on the fly for missing void columns. However, certain
//! void placements make data writes impossible and must be rejected at write time:
//! - Void nested inside Array or Map types (not materialized by Delta, and not supported by the
//!   logical-to-physical write transform, which only descends through Struct fields)
//! - Structs that contain no non-void fields (would produce an empty Parquet struct)
//! - Tables that contain no non-void columns (would produce an empty Parquet schema)

use std::borrow::Cow;
use std::sync::Arc;

use super::{DataType, PrimitiveType, Schema, SchemaRef, StructField, StructType};
use crate::expressions::ExpressionStructPatchBuilder;
use crate::transforms::{transform_output_type, SchemaTransform};
use crate::{DeltaResult, Error};

/// Returns true when this struct directly contains no non-void fields. The check is local --
/// it does not recurse into nested structs, because the caller (`ValidateForWrite`) walks every
/// struct in the schema and applies this predicate at each level. Empty structs also qualify
/// (they would produce an unwriteable empty Parquet struct).
///
/// This predicate is the validator's responsibility, not the stripper's. The stripper could
/// derive a reduced physical schema for an all-void struct, but write semantics require
/// rejecting the schema before that derivation happens.
fn has_no_non_void_fields(st: &StructType) -> bool {
    st.fields().all(|f| *f.data_type() == DataType::VOID)
}

/// Schema visitor that drops void fields at every nesting level.
///
/// This is intentionally separate from `ValidateForWrite`: validation decides
/// whether a logical write schema is allowed, while this transform derives the
/// physical schema used for Parquet writes, including metadata-only paths.
struct StripVoidFields;

impl<'a> SchemaTransform<'a> for StripVoidFields {
    transform_output_type!(|'a, T| Option<Cow<'a, T>>);

    fn transform_primitive(&mut self, ptype: &'a PrimitiveType) -> Option<Cow<'a, PrimitiveType>> {
        (*ptype != PrimitiveType::Void).then_some(Cow::Borrowed(ptype))
    }
}

/// Returns `schema` with all void fields removed from structs at every nesting level.
/// In the common case where the schema contains no void fields, returns the same `Arc`
/// without copying.
///
/// Pairs with `validate_schema_for_write`, which rejects void placements inside Array or Map
/// before the stripped physical schema is used for writing. An all-void or empty input yields
/// an empty schema; write callers are expected to run `validate_schema_for_write` before using
/// the stripped schema.
pub(crate) fn strip_void_from_schema(schema: SchemaRef) -> SchemaRef {
    match StripVoidFields.transform_struct(&schema) {
        Some(Cow::Owned(stripped)) => Arc::new(stripped),
        Some(Cow::Borrowed(_)) => schema,
        None => Arc::new(StructType::new_unchecked(Vec::<StructField>::new())),
    }
}

/// Validates that a schema is suitable for writing data. This is the kernel-internal write-time
/// rejection point for invalid void placements: [`StructType::try_new`] validates structural
/// properties only (field-name uniqueness, metadata-column rules) and accepts schemas like
/// `Array<Void>` or all-void structs. Both JSON-deserialized metadata (which round-trips through
/// `try_new`) and any `new_unchecked` paths therefore rely on this validator.
///
/// Writes are rejected when:
/// - Void is nested inside Array or Map. Parquet's UNKNOWN logical type can in principle annotate
///   any physical type with all-null values, but Delta itself does not materialize void columns in
///   data files, and our logical-to-physical transform does not descend into Array elements or Map
///   values to drop them.
/// - A struct contains no non-void fields (would produce an empty Parquet struct)
/// - The table schema contains no non-void columns (would produce an empty Parquet schema)
pub(crate) fn validate_schema_for_write(schema: &Schema) -> DeltaResult<()> {
    ValidateForWrite {
        container_depth: 0,
        depth: 0,
    }
    .transform_struct(schema)
}

struct ValidateForWrite {
    container_depth: usize,
    depth: usize,
}

impl ValidateForWrite {
    fn descend_into_container(&mut self, etype: &DataType, position: &str) -> DeltaResult<()> {
        if *etype == DataType::VOID {
            return Err(Error::schema(format!(
                "Void type is not allowed as {position}"
            )));
        }
        self.container_depth += 1;
        let result = self.transform(etype);
        self.container_depth -= 1;
        result
    }
}

impl<'a> SchemaTransform<'a> for ValidateForWrite {
    transform_output_type!(|'a, T| DeltaResult<()>);

    fn transform_struct(&mut self, stype: &'a StructType) -> DeltaResult<()> {
        if has_no_non_void_fields(stype) {
            return Err(Error::schema(if self.container_depth > 0 {
                "A struct nested in Array or Map must contain at least one non-void field"
            } else if self.depth == 0 {
                "Table schema must contain at least one non-void column"
            } else {
                "Cannot write to a table with a struct that contains no non-void fields"
            }));
        }
        self.depth += 1;
        let result = self.recurse_into_struct(stype);
        self.depth -= 1;
        result
    }

    fn transform_struct_field(&mut self, field: &'a StructField) -> DeltaResult<()> {
        // Reject void inside a struct nested in Array or Map. `StripVoidFields` can drop
        // the field from the physical schema, but the logical-to-physical write transform
        // built by `add_void_stripping_inner` descends only through struct fields. Allowing
        // this case would leave the runtime expression passing the void field through while
        // the physical schema no longer expects it, putting the two out of sync at write
        // time. Lifting this restriction requires extending the runtime transform to descend
        // into Array elements and Map keys/values.
        if self.container_depth > 0 && *field.data_type() == DataType::VOID {
            return Err(Error::schema(
                "Void type is not allowed inside a struct nested in Array or Map",
            ));
        }
        self.recurse_into_struct_field(field)
    }

    fn transform_array_element(&mut self, etype: &'a DataType) -> DeltaResult<()> {
        self.descend_into_container(etype, "an array element type")
    }

    fn transform_map_key(&mut self, etype: &'a DataType) -> DeltaResult<()> {
        self.descend_into_container(etype, "a map key type")
    }

    fn transform_map_value(&mut self, etype: &'a DataType) -> DeltaResult<()> {
        self.descend_into_container(etype, "a map value type")
    }
}

/// Appends void-field-stripping operations to `patch`, recursing through struct fields in
/// `st` (the logical schema). Returns `patch` unchanged when `st` contains no void fields.
///
/// Composition: `st` is read directly to locate void fields, not the partial result of applying
/// `patch`. Composing `patch` first with operations on disjoint columns (e.g. partition
/// column drops) is therefore safe, but composing with operations that already drop or replace
/// the same void-named columns is not -- the resulting patch would double-drop or conflict.
/// Don't reorder this relative to such operations.
pub(crate) fn add_void_stripping(
    patch: ExpressionStructPatchBuilder,
    st: &StructType,
) -> ExpressionStructPatchBuilder {
    add_void_stripping_inner(patch, st, &mut Vec::new())
}

/// Recursive helper that records a drop for every void field in `st`, threading `path` (the field
/// names from the root struct down to `st`) so nested drops are recorded at their full path.
///
/// The builder lowers each `drop_at` call into the appropriate nested patch and only materializes a
/// nested patch when a drop actually lands under that path, so structs with no void fields
/// contribute nothing. `path` is pushed/popped in place to avoid reallocating at each level.
///
/// This intentionally descends only through Struct fields; write validation rejects void
/// placements inside Array or Map before this patch is used.
fn add_void_stripping_inner<'a>(
    mut patch: ExpressionStructPatchBuilder,
    st: &'a StructType,
    path: &mut Vec<&'a str>,
) -> ExpressionStructPatchBuilder {
    for field in st.fields() {
        if *field.data_type() == DataType::VOID {
            patch = patch.drop_at(path.iter().copied(), field.name());
        } else if let DataType::Struct(inner) = field.data_type() {
            path.push(field.name());
            patch = add_void_stripping_inner(patch, inner, path);
            path.pop();
        }
    }
    patch
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::schema::{
        ArrayType, ColumnMetadataKey, DataType, MapType, MetadataValue, StructField, StructType,
    };

    // ---- validate_schema_for_write tests ----

    #[test]
    fn test_validator_catches_void_in_map_from_json() {
        let json = r#"{
            "name": "m",
            "type": {
                "type": "map",
                "keyType": "string",
                "valueType": "void",
                "valueContainsNull": true
            },
            "nullable": true,
            "metadata": {}
        }"#;

        // Deserialization succeeds — serde populates fields directly
        let field: StructField = serde_json::from_str(json).unwrap();
        if let DataType::Map(map_type) = field.data_type() {
            assert_eq!(*map_type.value_type(), DataType::VOID);
        } else {
            panic!("expected map type");
        }

        // The dedicated validator is what actually catches this
        let schema = StructType::new_unchecked([field]);
        assert!(validate_schema_for_write(&schema).is_err());
    }

    #[rstest::rstest]
    #[case(
        "void in array",
        StructField::nullable("f", ArrayType::new(DataType::VOID, true)),
        "array element type"
    )]
    #[case(
        "void in map value",
        StructField::nullable("f", MapType::new(DataType::STRING, DataType::VOID, true)),
        "map value type"
    )]
    #[case(
        "void in map key",
        StructField::nullable("f", MapType::new(DataType::VOID, DataType::STRING, true)),
        "map key type"
    )]
    #[case(
        "void in array inside struct",
        StructField::nullable(
            "outer",
            StructType::new_unchecked([
                StructField::nullable("inner", ArrayType::new(DataType::VOID, true)),
            ])
        ),
        "array element type"
    )]
    #[case(
        "void in map inside array",
        StructField::nullable(
            "col",
            ArrayType::new(MapType::new(DataType::STRING, DataType::VOID, true), true,),
        ),
        "map value type"
    )]
    #[case(
        "void inside struct nested in array",
        StructField::nullable(
            "arr",
            ArrayType::new(
                StructType::new_unchecked([
                    StructField::nullable("a", DataType::INTEGER),
                    StructField::nullable("b", DataType::VOID),
                ]),
                true,
            ),
        ),
        "Void type is not allowed inside"
    )]
    #[case(
        "void inside struct nested in map value",
        StructField::nullable(
            "m",
            MapType::new(
                DataType::STRING,
                StructType::new_unchecked([
                    StructField::nullable("a", DataType::INTEGER),
                    StructField::nullable("b", DataType::VOID),
                ]),
                true,
            ),
        ),
        "Void type is not allowed inside"
    )]
    #[case(
        "void inside struct nested in map key",
        StructField::nullable(
            "m",
            MapType::new(
                StructType::new_unchecked([
                    StructField::nullable("a", DataType::INTEGER),
                    StructField::nullable("b", DataType::VOID),
                ]),
                DataType::STRING,
                true,
            ),
        ),
        "Void type is not allowed inside"
    )]
    #[case(
        "void inside struct nested in array inside array",
        StructField::nullable(
            "outer",
            ArrayType::new(
                ArrayType::new(
                    StructType::new_unchecked([
                        StructField::nullable("a", DataType::INTEGER),
                        StructField::nullable("b", DataType::VOID),
                    ]),
                    true,
                ),
                true,
            ),
        ),
        "Void type is not allowed inside"
    )]
    #[case(
        "void in deeply nested struct inside array",
        StructField::nullable(
            "arr",
            ArrayType::new(
                StructType::new_unchecked([
                    StructField::nullable("a", DataType::INTEGER),
                    StructField::nullable(
                        "b",
                        StructType::new_unchecked([
                            StructField::nullable("x", DataType::INTEGER),
                            StructField::nullable("y", DataType::VOID),
                        ]),
                    ),
                ]),
                true,
            ),
        ),
        "Void type is not allowed inside"
    )]
    #[case(
        "void in struct inside array inside struct inside array",
        StructField::nullable(
            "outer",
            ArrayType::new(
                StructType::new_unchecked([StructField::nullable(
                    "inner",
                    ArrayType::new(
                        StructType::new_unchecked([StructField::nullable(
                            "v",
                            DataType::VOID,
                        )]),
                        true,
                    ),
                )]),
                true,
            ),
        ),
        "must contain at least one non-void field"
    )]
    #[case(
        "empty struct nested in array",
        StructField::nullable(
            "arr",
            ArrayType::new(
                StructType::new_unchecked(Vec::<StructField>::new()),
                true,
            ),
        ),
        "struct nested in Array or Map must contain at least one non-void field"
    )]
    #[case(
        "all-void struct nested in map value",
        StructField::nullable(
            "m",
            MapType::new(
                DataType::STRING,
                StructType::new_unchecked([StructField::nullable(
                    "x",
                    DataType::VOID,
                )]),
                true,
            ),
        ),
        "struct nested in Array or Map must contain at least one non-void field"
    )]
    fn test_void_in_complex_type_rejected(
        #[case] desc: &str,
        #[case] field: StructField,
        #[case] expected_msg: &str,
    ) {
        let schema = StructType::new_unchecked([field]);
        let result = validate_schema_for_write(&schema);
        assert!(
            result.unwrap_err().to_string().contains(expected_msg),
            "{desc}: expected error containing '{expected_msg}'"
        );
    }

    #[rstest::rstest]
    #[case(
        "void top level ok",
        StructType::new_unchecked([
            StructField::nullable("id", DataType::INTEGER),
            StructField::nullable("void_col", DataType::VOID),
        ])
    )]
    #[case(
        "test no void ok",
        StructType::new_unchecked([
            StructField::nullable("id", DataType::INTEGER),
            StructField::nullable("name", DataType::STRING),
        ])
    )]
    #[case(
        "void in nested struct",
        StructType::new_unchecked([StructField::nullable(
            "s",
            StructType::new_unchecked([
                StructField::nullable("a", DataType::INTEGER),
                StructField::nullable("b", DataType::VOID),
            ]),
        )])
    )]
    #[case(
        "array of struct without void",
        StructType::new_unchecked([StructField::nullable(
            "arr",
            ArrayType::new(
                StructType::new_unchecked([
                    StructField::nullable("a", DataType::INTEGER),
                    StructField::nullable("b", DataType::STRING),
                ]),
                true,
            ),
        )])
    )]
    #[case(
        "map of struct without void",
        StructType::new_unchecked([StructField::nullable(
            "m",
            MapType::new(
                DataType::STRING,
                StructType::new_unchecked([
                    StructField::nullable("a", DataType::INTEGER),
                    StructField::nullable("b", DataType::STRING),
                ]),
                true,
            ),
        )])
    )]
    fn test_valid_schema_for_complex_types(#[case] desc: &str, #[case] schema: StructType) {
        validate_schema_for_write(&schema)
            .unwrap_or_else(|e| panic!("{desc}: unexpected validation error: {e}"));
    }

    // ---- validate_schema_for_write tests ----

    #[rstest::rstest]
    #[case(
        "with void column",
        StructType::new_unchecked([
            StructField::nullable("id", DataType::INTEGER),
            StructField::nullable("void_col", DataType::VOID),
        ])
    )]
    #[case(
        "no void",
        StructType::new_unchecked([
            StructField::nullable("id", DataType::INTEGER),
            StructField::nullable("name", DataType::STRING),
        ])
    )]
    #[case(
        "struct with mixed void",
        StructType::new_unchecked([StructField::nullable(
            "s",
            StructType::new_unchecked([
                StructField::nullable("a", DataType::INTEGER),
                StructField::nullable("b", DataType::VOID),
            ]),
        )])
    )]
    fn test_write_valid_schemas(#[case] desc: &str, #[case] schema: StructType) {
        validate_schema_for_write(&schema)
            .unwrap_or_else(|e| panic!("{desc}: unexpected validation error: {e}"));
    }

    #[rstest::rstest]
    #[case(
        "all void table",
        StructType::new_unchecked([
            StructField::nullable("a", DataType::VOID),
            StructField::nullable("b", DataType::VOID),
        ]),
        "at least one non-void column"
    )]
    #[case(
        "all void struct",
        StructType::new_unchecked([
            StructField::nullable("id", DataType::INTEGER),
            StructField::nullable(
                "s",
                StructType::new_unchecked([
                    StructField::nullable("x", DataType::VOID),
                    StructField::nullable("y", DataType::VOID),
                ]),
            ),
        ]),
        "contains no non-void fields"
    )]
    #[case(
        "void in array",
        StructType::new_unchecked([StructField::nullable(
            "arr",
            ArrayType::new(DataType::VOID, true),
        )]),
        "array element type"
    )]
    #[case(
        "void in map",
        StructType::new_unchecked([StructField::nullable(
            "m",
            MapType::new(
                DataType::STRING,
                DataType::VOID,
                true,
            ),
        )]),
        "map value type"
    )]
    #[case(
        "nested all void struct",
        StructType::new_unchecked([
            StructField::nullable("id", DataType::INTEGER),
            StructField::nullable(
                "outer",
                StructType::new_unchecked([
                    StructField::nullable(
                        "inner",
                        StructType::new_unchecked([StructField::nullable("x", DataType::VOID)]),
                    ),
                ]),
            ),
        ]),
        "contains no non-void fields"
    )]
    #[case(
        "empty struct at top level",
        StructType::new_unchecked(Vec::<StructField>::new()),
        "at least one non-void column"
    )]
    #[case(
        "nested empty struct",
        StructType::new_unchecked([
            StructField::nullable("id", DataType::INTEGER),
            StructField::nullable(
                "s",
                StructType::new_unchecked(
                    Vec::<StructField>::new(),
                ),
            ),
        ]),
        "contains no non-void fields"
    )]
    fn test_write_rejected_schemas(
        #[case] desc: &str,
        #[case] schema: StructType,
        #[case] expected_msg: &str,
    ) {
        let result = validate_schema_for_write(&schema);
        assert!(
            result.unwrap_err().to_string().contains(expected_msg),
            "{desc}: expected error containing '{expected_msg}'"
        );
    }

    // ---- strip_void_from_schema tests ----

    #[rstest::rstest]
    #[case(
        "schema with no void is noop",
        StructType::new_unchecked([
            StructField::nullable("a", DataType::INTEGER),
            StructField::nullable("b", DataType::STRING),
        ]),
        StructType::new_unchecked([
            StructField::nullable("a", DataType::INTEGER),
            StructField::nullable("b", DataType::STRING),
        ])
    )]
    #[case(
        "top-level void is dropped",
        StructType::new_unchecked([
            StructField::nullable("a", DataType::INTEGER),
            StructField::nullable("v", DataType::VOID),
            StructField::nullable("b", DataType::STRING),
        ]),
        StructType::new_unchecked([
            StructField::nullable("a", DataType::INTEGER),
            StructField::nullable("b", DataType::STRING),
        ])
    )]
    #[case(
        "nested struct with mixed void",
        StructType::new_unchecked([StructField::nullable(
            "s",
            StructType::new_unchecked([
                StructField::nullable("a", DataType::INTEGER),
                StructField::nullable("b", DataType::VOID),
                StructField::nullable("c", DataType::STRING),
            ]),
        )]),
        StructType::new_unchecked([StructField::nullable(
            "s",
            StructType::new_unchecked([
                StructField::nullable("a", DataType::INTEGER),
                StructField::nullable("c", DataType::STRING),
            ]),
        )])
    )]
    #[case(
        "deeply nested void",
        StructType::new_unchecked([StructField::nullable(
            "outer",
            StructType::new_unchecked([StructField::nullable(
                "inner",
                StructType::new_unchecked([
                    StructField::nullable("a", DataType::INTEGER),
                    StructField::nullable("v", DataType::VOID),
                ]),
            )]),
        )]),
        StructType::new_unchecked([StructField::nullable(
            "outer",
            StructType::new_unchecked([StructField::nullable(
                "inner",
                StructType::new_unchecked([StructField::nullable("a", DataType::INTEGER)]),
            )]),
        )])
    )]
    fn test_strip_void_from_schema(
        #[case] desc: &str,
        #[case] input: StructType,
        #[case] expected: StructType,
    ) {
        let stripped = strip_void_from_schema(Arc::new(input));
        assert_eq!(*stripped, expected, "{desc}");
    }

    // A container that has Void as its only "interior" type collapses when the void
    // primitive is filtered: ArrayType / MapType cannot be reconstructed without their
    // element / key / value, so the containing field disappears.
    #[rstest::rstest]
    #[case::array_of_void(DataType::from(ArrayType::new(DataType::VOID, true)))]
    #[case::map_with_void_value(DataType::from(MapType::new(
        DataType::STRING,
        DataType::VOID,
        true
    )))]
    #[case::map_with_void_key(DataType::from(MapType::new(
        DataType::VOID,
        DataType::STRING,
        true
    )))]
    fn test_strip_drops_container_with_void(#[case] field_type: DataType) {
        let schema = Arc::new(StructType::new_unchecked([
            StructField::nullable("id", DataType::INTEGER),
            StructField::nullable("c", field_type),
        ]));
        let stripped = strip_void_from_schema(schema);
        assert!(stripped.field("id").is_some());
        assert!(stripped.field("c").is_none());
    }

    #[test]
    fn test_strip_preserves_metadata() {
        let mut s_field = StructField::nullable(
            "s",
            StructType::new_unchecked([
                StructField::nullable("a", DataType::INTEGER),
                StructField::nullable("b", DataType::VOID),
            ]),
        );
        s_field.metadata.insert(
            ColumnMetadataKey::ColumnMappingPhysicalName.as_ref().into(),
            MetadataValue::String("phys_s".into()),
        );
        let schema = Arc::new(StructType::new_unchecked([s_field]));
        let stripped = strip_void_from_schema(schema);
        assert_eq!(
            stripped
                .field("s")
                .expect("s field present after strip")
                .metadata
                .get(ColumnMetadataKey::ColumnMappingPhysicalName.as_ref()),
            Some(&MetadataValue::String("phys_s".into())),
            "metadata should be preserved after stripping"
        );
    }
}