Repository: influxdata/influxdb
File: influxdb3_catalog/src/catalog.rs (Rust)

Code before:
            id,
            name: name.into(),
            data_type,
            nullable,
        }
    }
}

pub fn influx_column_type_from_field_value(fv: &FieldValue<'_>) -> InfluxColumnType {
    match fv {
        FieldValue::I64(_) => InfluxColumnType::Field(InfluxFieldType::Integer),
        FieldValue::U64(_) => InfluxColumnType::Field(InfluxFieldType::UInteger),
        FieldValue::F64(_) => InfluxColumnType::Field(InfluxFieldType::Float),
        FieldValue::String(_) => InfluxColumnType::Field(InfluxFieldType::String),
        FieldValue::Boolean(_) => InfluxColumnType::Field(InfluxFieldType::Boolean),
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use influxdb3_wal::CatalogOp::CreateTable;
    use influxdb3_wal::{create, DatabaseDefinition, FieldDataType, WalOp};
    use pretty_assertions::assert_eq;
    use test_helpers::assert_contains;

    #[test]
    fn catalog_serialization() {
        let node_id = Arc::from("sample-host-id");
        let instance_id = Arc::from("instance-id");
        let cloned_instance_id = Arc::clone(&instance_id);
        let catalog = Catalog::new(node_id, cloned_instance_id);
        let mut database = DatabaseSchema {
            id: DbId::from(0),
            name: "test_db".into(),
            tables: SerdeVecMap::new(),
            table_map: {
                let mut map = BiHashMap::new();
                map.insert(TableId::from(1), "test_table_1".into());
                map.insert(TableId::from(2), "test_table_2".into());
                map
            },
            processing_engine_triggers: Default::default(),
            deleted: false,
        };
        use InfluxColumnType::*;
        use InfluxFieldType::*;
        database.tables.insert(
            TableId::from(1),
            Arc::new(
                TableDefinition::new(

Review comment (suggestion):
This is a neat feature in `insta` that allows you to make the same snapshot assertion twice, and it checks the result against the same snapshot file. I used it here to check roundtrip serialization/deserialization.

Code after:
                TableDefinition::new(
                    TableId::from(2),
                    "test_table_2".into(),
                    vec![
                        (ColumnId::new(), "tag_1".into(), Tag),
                        (ColumnId::new(), "tag_2".into(), Tag),
                        (ColumnId::new(), "tag_3".into(), Tag),
                        (ColumnId::new(), "time".into(), Timestamp),
                        (ColumnId::new(), "string_field".into(), Field(String)),
                        (ColumnId::new(), "bool_field".into(), Field(Boolean)),
                        (ColumnId::new(), "i64_field".into(), Field(Integer)),
                        (ColumnId::new(), "u64_field".into(), Field(UInteger)),
                        (ColumnId::new(), "f64_field".into(), Field(Float)),
                    ],
                    vec![9.into(), 10.into(), 11.into()],
                )
                .unwrap(),
            ),
        );
        catalog
            .inner
            .write()
            .databases
            .insert(database.id, Arc::new(database));

        insta::allow_duplicates! {
            insta::with_settings!({
                sort_maps => true,
                description => "catalog serialization to help catch breaking changes"
            }, {
                insta::assert_json_snapshot!(catalog);
                // Serialize/deserialize to ensure roundtrip to/from JSON
                let serialized = serde_json::to_string(&catalog).unwrap();
                let catalog: Catalog = serde_json::from_str(&serialized).unwrap();
                insta::assert_json_snapshot!(catalog);
                assert_eq!(instance_id, catalog.instance_id());
                assert_eq!(catalog.db_name_to_id("test_db"), Some(DbId::from(0)));
            });
        }
    }

    #[test]
    fn invalid_catalog_deserialization() {
        // Duplicate databases
        {
            let json = r#"{
                "databases": [
                    [
                        0,
                        {
                            "id": 0,