fn test_identifier_field_ids()

in crates/iceberg/src/spec/schema/mod.rs [1073:1193]


    fn test_identifier_field_ids() {
        // field in map
        assert!(Schema::builder()
            .with_schema_id(1)
            .with_identifier_field_ids(vec![2])
            .with_fields(vec![NestedField::required(
                1,
                "Map",
                Type::Map(MapType::new(
                    NestedField::map_key_element(2, Type::Primitive(PrimitiveType::String)).into(),
                    NestedField::map_value_element(
                        3,
                        Type::Primitive(PrimitiveType::Boolean),
                        true,
                    )
                    .into(),
                )),
            )
            .into()])
            .build()
            .is_err());
        assert!(Schema::builder()
            .with_schema_id(1)
            .with_identifier_field_ids(vec![3])
            .with_fields(vec![NestedField::required(
                1,
                "Map",
                Type::Map(MapType::new(
                    NestedField::map_key_element(2, Type::Primitive(PrimitiveType::String)).into(),
                    NestedField::map_value_element(
                        3,
                        Type::Primitive(PrimitiveType::Boolean),
                        true,
                    )
                    .into(),
                )),
            )
            .into()])
            .build()
            .is_err());

        // field in list
        assert!(Schema::builder()
            .with_schema_id(1)
            .with_identifier_field_ids(vec![2])
            .with_fields(vec![NestedField::required(
                1,
                "List",
                Type::List(ListType::new(
                    NestedField::list_element(2, Type::Primitive(PrimitiveType::String), true)
                        .into(),
                )),
            )
            .into()])
            .build()
            .is_err());

        // field in optional struct
        assert!(Schema::builder()
            .with_schema_id(1)
            .with_identifier_field_ids(vec![2])
            .with_fields(vec![NestedField::optional(
                1,
                "Struct",
                Type::Struct(StructType::new(vec![
                    NestedField::required(2, "name", Type::Primitive(PrimitiveType::String)).into(),
                    NestedField::optional(3, "age", Type::Primitive(PrimitiveType::Int)).into(),
                ])),
            )
            .into()])
            .build()
            .is_err());

        // float and double
        assert!(Schema::builder()
            .with_schema_id(1)
            .with_identifier_field_ids(vec![1])
            .with_fields(vec![NestedField::required(
                1,
                "Float",
                Type::Primitive(PrimitiveType::Float),
            )
            .into()])
            .build()
            .is_err());
        assert!(Schema::builder()
            .with_schema_id(1)
            .with_identifier_field_ids(vec![1])
            .with_fields(vec![NestedField::required(
                1,
                "Double",
                Type::Primitive(PrimitiveType::Double),
            )
            .into()])
            .build()
            .is_err());

        // optional field
        assert!(Schema::builder()
            .with_schema_id(1)
            .with_identifier_field_ids(vec![1])
            .with_fields(vec![NestedField::required(
                1,
                "Required",
                Type::Primitive(PrimitiveType::String),
            )
            .into()])
            .build()
            .is_ok());
        assert!(Schema::builder()
            .with_schema_id(1)
            .with_identifier_field_ids(vec![1])
            .with_fields(vec![NestedField::optional(
                1,
                "Optional",
                Type::Primitive(PrimitiveType::String),
            )
            .into()])
            .build()
            .is_err());
    }