Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Moved CSV and JSON testing away from using files.
Browse files Browse the repository at this point in the history
This allows miri to check them, and make the testing less reliant
on a FS, which it does not actually need.
  • Loading branch information
jorgecarleitao committed Aug 16, 2021
1 parent a5f0575 commit e4b77b1
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 1,460 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Expand Up @@ -159,11 +159,11 @@ jobs:
env:
RUST_BACKTRACE: full
RUST_LOG: 'trace'
# --skip io: miri does not handle IO very well, unfortunately.
# --skip io: miri can't handle opening of files, so we skip those
run: |
cargo miri setup
cargo clean
cargo miri test -- --skip io
cargo miri test -- --skip io::parquet --skip io::ipc
coverage:
name: Coverage
Expand Down
29 changes: 15 additions & 14 deletions src/io/json/read/infer_schema.rs
Expand Up @@ -170,20 +170,18 @@ fn generate_schema(spec: HashMap<String, HashSet<DataType>>) -> Result<Schema> {
///
/// # Examples
/// ```
/// use std::fs::File;
/// use std::io::{BufReader, SeekFrom, Seek};
/// use flate2::read::GzDecoder;
/// use std::io::{BufReader, Cursor, SeekFrom, Seek};
/// use arrow2::io::json::infer_json_schema;
///
/// let mut file = File::open("test/data/mixed_arrays.json.gz").unwrap();
/// let data = r#"{"a":1, "b":[2.0, 1.3, -6.1], "c":[false, true], "d":4.1}
/// {"a":-10, "b":[2.0, 1.3, -6.1], "c":null, "d":null}
/// {"a":2, "b":[2.0, null, -6.1], "c":[false, null], "d":"text"}
/// {"a":3, "b":4, "c": true, "d":[1, false, "array", 2.4]}
/// "#;
///
/// // file's cursor's offset at 0
/// let mut reader = BufReader::new(GzDecoder::new(&file));
/// let mut reader = BufReader::new(Cursor::new(data));
/// let inferred_schema = infer_json_schema(&mut reader, None).unwrap();
/// // cursor's offset at end of file
///
/// // seek back to start so that the original file is usable again
/// file.seek(SeekFrom::Start(0)).unwrap();
/// ```
pub fn infer_json_schema<R: Read>(
reader: &mut BufReader<R>,
Expand Down Expand Up @@ -345,14 +343,17 @@ where
/// # Examples
/// ```
/// use std::fs::File;
/// use std::io::BufReader;
/// use std::io::{BufReader, Cursor};
/// use arrow2::io::json::infer_json_schema_from_seekable;
///
/// let file = File::open("test/data/mixed_arrays.json").unwrap();
/// // file's cursor's offset at 0
/// let mut reader = BufReader::new(file);
/// let data = r#"{"a":1, "b":[2.0, 1.3, -6.1], "c":[false, true], "d":4.1}
/// {"a":-10, "b":[2.0, 1.3, -6.1], "c":null, "d":null}
/// {"a":2, "b":[2.0, null, -6.1], "c":[false, null], "d":"text"}
/// {"a":3, "b":4, "c": true, "d":[1, false, "array", 2.4]}
/// "#;
/// let mut reader = BufReader::new(Cursor::new(data));
/// let inferred_schema = infer_json_schema_from_seekable(&mut reader, None).unwrap();
/// // file's cursor's offset automatically set at 0
/// // cursor's position automatically set at 0
/// ```
pub fn infer_json_schema_from_seekable<R: Read + Seek>(
reader: &mut BufReader<R>,
Expand Down
20 changes: 11 additions & 9 deletions src/io/json/read/reader.rs
Expand Up @@ -133,19 +133,21 @@ impl Decoder {
/// use std::sync::Arc;
/// use arrow2::datatypes::{DataType, Field, Schema};
/// use arrow2::io::json;
/// use std::fs::File;
/// use std::io::BufReader;
/// use std::io::{Cursor, BufReader};
///
/// let schema = Arc::new(Schema::new(vec![
/// Field::new("a", DataType::Float64, false),
/// Field::new("b", DataType::Float64, false),
/// Field::new("c", DataType::Float64, false),
/// Field::new("a", DataType::Int64, true),
/// Field::new("b", DataType::Float32, true),
/// Field::new("c", DataType::Boolean, true),
/// Field::new("d", DataType::Utf8, true),
/// ]));
///
/// let file = File::open("test/data/basic.json").unwrap();
///
/// let mut json = json::Reader::new(BufReader::new(file), schema, 1024, None);
/// let batch = json.next().unwrap().unwrap();
/// let data = r#"{"a":1, "b":2.0, "c":false, "d":"4"}
/// {"a":-10, "b":-3.5, "c":true, "d":null}
/// {"a":100000000, "b":0.6, "d":"text"}"#;
/// let mut reader = BufReader::new(Cursor::new(data));
/// let mut reader = json::Reader::new(&mut reader, schema, 1024, None);
/// let batch = reader.next().unwrap().unwrap();
/// ```
#[derive(Debug)]
pub struct Reader<R: Read> {
Expand Down
3 changes: 0 additions & 3 deletions test/data/arrays.json

This file was deleted.

12 changes: 0 additions & 12 deletions test/data/basic.json

This file was deleted.

12 changes: 0 additions & 12 deletions test/data/basic_nulls.json

This file was deleted.

0 comments on commit e4b77b1

Please sign in to comment.