()
| 324 | |
| 325 | #[test] |
| 326 | fn write_segment_roundtrip() { |
| 327 | let schema = analytics_schema(); |
| 328 | let mut mt = ColumnarMemtable::new(&schema); |
| 329 | |
| 330 | for i in 0..100 { |
| 331 | mt.append_row(&[ |
| 332 | Value::Integer(i), |
| 333 | Value::String(format!("user_{i}")), |
| 334 | if i % 3 == 0 { |
| 335 | Value::Null |
| 336 | } else { |
| 337 | Value::Float(i as f64 * 0.25) |
| 338 | }, |
| 339 | ]) |
| 340 | .expect("append"); |
| 341 | } |
| 342 | |
| 343 | let (schema, columns, row_count) = mt.drain(); |
| 344 | let writer = SegmentWriter::plain(); |
| 345 | let segment = writer |
| 346 | .write_segment(&schema, &columns, row_count, None) |
| 347 | .expect("write"); |
| 348 | |
| 349 | // Verify header. |
| 350 | let header = SegmentHeader::from_bytes(&segment).expect("valid header"); |
| 351 | assert_eq!(header.magic, *b"NDBS"); |
| 352 | assert_eq!(header.version_major, 1); |
| 353 | |
| 354 | // Verify footer. |
| 355 | let footer = SegmentFooter::from_segment_tail(&segment).expect("valid footer"); |
| 356 | assert_eq!(footer.column_count, 3); |
| 357 | assert_eq!(footer.row_count, 100); |
| 358 | assert_eq!(footer.profile_tag, PROFILE_PLAIN); |
| 359 | assert_eq!(footer.columns.len(), 3); |
| 360 | |
| 361 | // Verify column metadata. |
| 362 | assert_eq!(footer.columns[0].name, "id"); |
| 363 | assert_eq!(footer.columns[1].name, "name"); |
| 364 | assert_eq!(footer.columns[2].name, "score"); |
| 365 | |
| 366 | // Each column should have 1 block (100 rows < BLOCK_SIZE=1024). |
| 367 | assert_eq!(footer.columns[0].block_count, 1); |
| 368 | assert_eq!(footer.columns[0].block_stats[0].row_count, 100); |
| 369 | |
| 370 | // id: min=0, max=99. |
| 371 | assert_eq!(footer.columns[0].block_stats[0].min, 0.0); |
| 372 | assert_eq!(footer.columns[0].block_stats[0].max, 99.0); |
| 373 | assert_eq!(footer.columns[0].block_stats[0].null_count, 0); |
| 374 | |
| 375 | // score: 34 nulls (every 3rd row), min=0.25 (row 1), max=99*0.25=24.75 (row 99). |
| 376 | assert_eq!(footer.columns[2].block_stats[0].null_count, 34); |
| 377 | } |
| 378 | |
| 379 | #[test] |
| 380 | fn write_segment_multi_block() { |
nothing calls this directly
no test coverage detected