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

JNI switches to nested JSON reader #12732

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions java/src/main/native/src/TableJni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1334,8 +1334,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_Table_readAndInferJSON(

cudf::io::json_reader_options_builder opts = cudf::io::json_reader_options::builder(source)
.dayfirst(static_cast<bool>(day_first))
.lines(static_cast<bool>(lines))
.legacy(true);
.lines(static_cast<bool>(lines));

auto result =
std::make_unique<cudf::io::table_with_metadata>(cudf::io::read_json(opts.build()));
Expand Down Expand Up @@ -1441,8 +1440,7 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_Table_readJSON(

cudf::io::json_reader_options_builder opts = cudf::io::json_reader_options::builder(source)
.dayfirst(static_cast<bool>(day_first))
.lines(static_cast<bool>(lines))
.legacy(true);
.lines(static_cast<bool>(lines));

if (!n_col_names.is_null() && data_types.size() > 0) {
if (n_col_names.size() != n_types.size()) {
Expand Down
30 changes: 23 additions & 7 deletions java/src/test/java/ai/rapids/cudf/TableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -335,22 +335,38 @@ void testReadJSONBufferInferred() {
JSONOptions opts = JSONOptions.builder()
.withDayFirst(true)
.build();
byte[] data = ("[false,A,1,2,05/03/2001]\n" +
"[true,B,2,3,31/10/2010]'\n" +
"[false,C,3,4,20/10/1994]\n" +
"[true,D,4,5,18/10/1990]").getBytes(StandardCharsets.UTF_8);
byte[] data = ("[false,A,1,2]\n" +
"[true,B,2,3]\n" +
"[false,C,3,4]\n" +
"[true,D,4,5]").getBytes(StandardCharsets.UTF_8);
try (Table expected = new Table.TestBuilder()
.column(false, true, false, true)
.column("A", "B", "C", "D")
.column(1L, 2L, 3L, 4L)
.column(2L, 3L, 4L, 5L)
.timestampMillisecondsColumn(983750400000L, 1288483200000L, 782611200000L, 656208000000L)
.build();
Table table = Table.readJSON(Schema.INFERRED, opts, data)) {
assertTablesAreEqual(expected, table);
}
}

@Test
void testReadJSONSubColumns() {
// JSON file has 2 columns, here only read 1 column
Schema schema = Schema.builder()
.column(DType.INT32, "age")
.build();
JSONOptions opts = JSONOptions.builder()
.withLines(true)
.build();
try (Table expected = new Table.TestBuilder()
.column(null, 30, 19)
.build();
Table table = Table.readJSON(schema, opts, TEST_SIMPLE_JSON_FILE)) {
assertTablesAreEqual(expected, table);
}
}

@Test
void testReadJSONBuffer() {
// JSON reader will set the column according to the iterator if can't infer the name
Expand All @@ -363,7 +379,7 @@ void testReadJSONBuffer() {
JSONOptions opts = JSONOptions.builder()
.build();
byte[] data = ("[A,1,2]\n" +
"[B,2,3]'\n" +
"[B,2,3]\n" +
"[C,3,4]\n" +
"[D,4,5]").getBytes(StandardCharsets.UTF_8);
try (Table expected = new Table.TestBuilder()
Expand All @@ -389,7 +405,7 @@ void testReadJSONBufferWithOffset() {
.build();
int bytesToIgnore = 8;
byte[] data = ("[A,1,2]\n" +
"[B,2,3]'\n" +
"[B,2,3]\n" +
"[C,3,4]\n" +
"[D,4,5]").getBytes(StandardCharsets.UTF_8);
try (Table expected = new Table.TestBuilder()
Expand Down