Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate old JSON reader (#3610) #3718

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -295,6 +295,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 @@ -582,6 +582,7 @@ where
/// [`RawDecoder`]: crate::raw::RawDecoder
/// [#3610]: https://github.com/apache/arrow-rs/issues/3610
#[derive(Debug)]
#[deprecated(note = "Use RawDecoder instead")]
Comment on lines 582 to +585
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need the comment? Actually it reads unclear and seems strange to put issue link there.

Suggested change
/// [`RawDecoder`]: crate::raw::RawDecoder
/// [#3610]: https://github.com/apache/arrow-rs/issues/3610
#[derive(Debug)]
#[deprecated(note = "Use RawDecoder instead")]
#[derive(Debug)]
#[deprecated(note = "Use RawDecoder instead")]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are link shorthand, they don't get rendered, but are used to attach links to the text above.

image

pub struct Decoder {
/// Explicit schema for the JSON file
schema: SchemaRef,
Expand Down Expand Up @@ -638,6 +639,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 @@ -1604,12 +1606,15 @@ fn flatten_json_string_values(values: &[Value]) -> Vec<Option<String>> {
/// [`RawReader`]: crate::raw::RawReader
/// [#3610]: https://github.com/apache/arrow-rs/issues/3610
Comment on lines 1606 to 1607
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Suggested change
/// [`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 @@ -1656,6 +1661,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 @@ -1670,6 +1676,7 @@ pub struct ReaderBuilder {
options: DecoderOptions,
}

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

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

Expand All @@ -1759,6 +1767,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}}
Copy link
Contributor Author

@tustvold tustvold Feb 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't actually valid JSON, it contained a duplicate key - the RawReader handles this differently (preserving the duplicate) than the old JSON reader which preserves only the last instance

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds like behavior change. Do we have document it at RawReader?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prior behaviour wasn't documented on Decoder, so I think this is fine

{"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