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

Function test_nulls_with_inference

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

Source from the content-addressed store, hash-verified

1761
1762 #[test]
1763 fn test_nulls_with_inference() {
1764 let mut file = File::open("test/data/various_types.csv").unwrap();
1765 let format = Format::default().with_header(true).with_delimiter(b'|');
1766
1767 let (schema, _) = format.infer_schema(&mut file, None).unwrap();
1768 file.rewind().unwrap();
1769
1770 let builder = ReaderBuilder::new(Arc::new(schema))
1771 .with_format(format)
1772 .with_batch_size(512)
1773 .with_projection(vec![0, 1, 2, 3, 4, 5]);
1774
1775 let mut csv = builder.build(file).unwrap();
1776 let batch = csv.next().unwrap().unwrap();
1777
1778 assert_eq!(10, batch.num_rows());
1779 assert_eq!(6, batch.num_columns());
1780
1781 let schema = batch.schema();
1782
1783 assert_eq!(&DataType::Int64, schema.field(0).data_type());
1784 assert_eq!(&DataType::Float64, schema.field(1).data_type());
1785 assert_eq!(&DataType::Float64, schema.field(2).data_type());
1786 assert_eq!(&DataType::Boolean, schema.field(3).data_type());
1787 assert_eq!(&DataType::Date32, schema.field(4).data_type());
1788 assert_eq!(
1789 &DataType::Timestamp(TimeUnit::Second, None),
1790 schema.field(5).data_type()
1791 );
1792
1793 let names: Vec<&str> = schema.fields().iter().map(|x| x.name().as_str()).collect();
1794 assert_eq!(
1795 names,
1796 vec![
1797 "c_int",
1798 "c_float",
1799 "c_string",
1800 "c_bool",
1801 "c_date",
1802 "c_datetime"
1803 ]
1804 );
1805
1806 assert!(schema.field(0).is_nullable());
1807 assert!(schema.field(1).is_nullable());
1808 assert!(schema.field(2).is_nullable());
1809 assert!(schema.field(3).is_nullable());
1810 assert!(schema.field(4).is_nullable());
1811 assert!(schema.field(5).is_nullable());
1812
1813 assert!(!batch.column(1).is_null(0));
1814 assert!(!batch.column(1).is_null(1));
1815 assert!(batch.column(1).is_null(2));
1816 assert!(!batch.column(1).is_null(3));
1817 assert!(!batch.column(1).is_null(4));
1818 }
1819
1820 #[test]

Callers

nothing calls this directly

Calls 15

defaultFunction · 0.85
infer_schemaMethod · 0.80
with_formatMethod · 0.80
collectMethod · 0.80
with_delimiterMethod · 0.45
with_headerMethod · 0.45
with_projectionMethod · 0.45
with_batch_sizeMethod · 0.45
buildMethod · 0.45
nextMethod · 0.45
schemaMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected