MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_csv_with_dictionary

Function test_csv_with_dictionary

arrow-csv/src/reader/mod.rs:1586–1616  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1584
1585 #[test]
1586 fn test_csv_with_dictionary() {
1587 let schema = Arc::new(Schema::new(vec![
1588 Field::new_dictionary("city", DataType::Int32, DataType::Utf8, false),
1589 Field::new("lat", DataType::Float64, false),
1590 Field::new("lng", DataType::Float64, false),
1591 ]));
1592
1593 let file = File::open("test/data/uk_cities.csv").unwrap();
1594
1595 let mut csv = ReaderBuilder::new(schema)
1596 .with_projection(vec![0, 1])
1597 .build(file)
1598 .unwrap();
1599
1600 let projected_schema = Arc::new(Schema::new(vec![
1601 Field::new_dictionary("city", DataType::Int32, DataType::Utf8, false),
1602 Field::new("lat", DataType::Float64, false),
1603 ]));
1604 assert_eq!(projected_schema, csv.schema());
1605 let batch = csv.next().unwrap().unwrap();
1606 assert_eq!(projected_schema, batch.schema());
1607 assert_eq!(37, batch.num_rows());
1608 assert_eq!(2, batch.num_columns());
1609
1610 let strings = arrow_cast::cast(batch.column(0), &DataType::Utf8).unwrap();
1611 let strings = strings.as_string::<i32>();
1612
1613 assert_eq!(strings.value(0), "Elgin, Scotland, the UK");
1614 assert_eq!(strings.value(4), "Eastbourne, East Sussex, UK");
1615 assert_eq!(strings.value(29), "Uckfield, East Sussex, UK");
1616 }
1617
1618 #[test]
1619 fn test_csv_with_nullable_dictionary() {

Callers

nothing calls this directly

Calls 5

castFunction · 0.85
buildMethod · 0.45
with_projectionMethod · 0.45
nextMethod · 0.45
columnMethod · 0.45

Tested by

no test coverage detected