Skip to content

Commit

Permalink
Deprecate old JSON reader (#3610) (#3718)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Feb 22, 2023
1 parent 61ea9f2 commit 6bf0aab
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions arrow-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub mod writer;
mod raw;

pub use self::raw::{RawDecoder, RawReader, RawReaderBuilder};
#[allow(deprecated)]
pub use self::reader::{Reader, ReaderBuilder};
pub use self::writer::{ArrayWriter, LineDelimitedWriter, Writer};
use half::f16;
Expand Down
1 change: 1 addition & 0 deletions arrow-json/src/raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ fn tape_error(d: TapeElement, expected: &str) -> ArrowError {
}

#[cfg(test)]
#[allow(deprecated)]
mod tests {
use super::*;
use crate::reader::infer_json_schema;
Expand Down
9 changes: 9 additions & 0 deletions arrow-json/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ where
/// [`RawDecoder`]: crate::raw::RawDecoder
/// [#3610]: https://github.com/apache/arrow-rs/issues/3610
#[derive(Debug)]
#[deprecated(note = "Use RawDecoder instead")]
pub struct Decoder {
/// Explicit schema for the JSON file
schema: SchemaRef,
Expand Down Expand Up @@ -640,6 +641,7 @@ impl DecoderOptions {
}
}

#[allow(deprecated)]
impl Decoder {
/// Create a new JSON decoder from some value that implements an
/// iterator over [`serde_json::Value`]s (aka implements the
Expand Down Expand Up @@ -1606,12 +1608,15 @@ fn flatten_json_string_values(values: &[Value]) -> Vec<Option<String>> {
/// [`RawReader`]: crate::raw::RawReader
/// [#3610]: https://github.com/apache/arrow-rs/issues/3610
#[derive(Debug)]
#[deprecated(note = "Use RawReader instead")]
#[allow(deprecated)]
pub struct Reader<R: Read> {
reader: BufReader<R>,
/// JSON value decoder
decoder: Decoder,
}

#[allow(deprecated)]
impl<R: Read> Reader<R> {
/// Create a new JSON Reader from any value that implements the `Read` trait.
///
Expand Down Expand Up @@ -1658,6 +1663,7 @@ impl<R: Read> Reader<R> {
/// [#3610]: https://github.com/apache/arrow-rs/issues/3610
///
#[derive(Debug, Default)]
#[deprecated(note = "Use RawReaderBuilder instead")]
pub struct ReaderBuilder {
/// Optional schema for the JSON file
///
Expand All @@ -1672,6 +1678,7 @@ pub struct ReaderBuilder {
options: DecoderOptions,
}

#[allow(deprecated)]
impl ReaderBuilder {
/// Create a new builder for configuring JSON parsing options.
///
Expand Down Expand Up @@ -1752,6 +1759,7 @@ impl ReaderBuilder {
}
}

#[allow(deprecated)]
impl<R: Read> Iterator for Reader<R> {
type Item = Result<RecordBatch, ArrowError>;

Expand All @@ -1761,6 +1769,7 @@ impl<R: Read> Iterator for Reader<R> {
}

#[cfg(test)]
#[allow(deprecated)]
mod tests {
use super::*;
use arrow_array::cast::{
Expand Down
3 changes: 3 additions & 0 deletions arrow-json/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,7 @@ mod tests {
);
}

#[allow(deprecated)]
fn test_write_for_file(test_file: &str) {
let builder = ReaderBuilder::new()
.infer_schema(None)
Expand Down Expand Up @@ -1295,6 +1296,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn json_list_roundtrip() {
let json_content = r#"
{"list": [{"ints": 1}]}
Expand Down Expand Up @@ -1406,6 +1408,7 @@ mod tests {
}

#[test]
#[allow(deprecated)]
fn test_write_single_batch() {
let test_file = "test/data/basic.json";
let builder = ReaderBuilder::new()
Expand Down
5 changes: 3 additions & 2 deletions arrow/benches/json_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ use arrow::util::bench_util::{
create_primitive_array, create_string_array, create_string_array_with_len,
};
use arrow_array::RecordBatch;
use arrow_json::LineDelimitedWriter;
use arrow_json::RawReaderBuilder;
use arrow_json::{LineDelimitedWriter, ReaderBuilder};
use std::io::Cursor;
use std::sync::Arc;

#[allow(deprecated)]
fn do_bench(c: &mut Criterion, name: &str, json: &str, schema: SchemaRef) {
c.bench_function(&format!("{name} (basic)"), |b| {
b.iter(|| {
let cursor = Cursor::new(black_box(json));
let builder = ReaderBuilder::new()
let builder = arrow_json::ReaderBuilder::new()
.with_schema(schema.clone())
.with_batch_size(64);

Expand Down
6 changes: 2 additions & 4 deletions parquet/src/arrow/arrow_writer/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ mod tests {
// Note: we are using the JSON Arrow reader for brevity
let json_content = r#"
{"stocks":{"long": "$AAA", "short": "$BBB"}}
{"stocks":{"long": null, "long": "$CCC", "short": null}}
{"stocks":{"long": "$CCC", "short": null}}
{"stocks":{"hedged": "$YYY", "long": null, "short": "$D"}}
"#;
let entries_struct_type = DataType::Struct(vec![
Expand All @@ -1138,9 +1138,7 @@ mod tests {
false,
);
let schema = Arc::new(Schema::new(vec![stocks_field]));
let builder = arrow::json::ReaderBuilder::new()
.with_schema(schema)
.with_batch_size(64);
let builder = arrow::json::RawReaderBuilder::new(schema).with_batch_size(64);
let mut reader = builder.build(std::io::Cursor::new(json_content)).unwrap();

let batch = reader.next().unwrap().unwrap();
Expand Down
4 changes: 1 addition & 3 deletions parquet/src/arrow/arrow_writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,9 +1026,7 @@ mod tests {
true,
);
let schema = Arc::new(Schema::new(vec![stocks_field]));
let builder = arrow::json::ReaderBuilder::new()
.with_schema(schema)
.with_batch_size(64);
let builder = arrow::json::RawReaderBuilder::new(schema).with_batch_size(64);
let mut reader = builder.build(std::io::Cursor::new(json_content)).unwrap();

let batch = reader.next().unwrap().unwrap();
Expand Down

0 comments on commit 6bf0aab

Please sign in to comment.