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

Support reading JSON data with single quotes around attribute names and values #10273

Merged
merged 7 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
2 changes: 1 addition & 1 deletion integration_tests/src/main/python/json_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ def test_from_json_map_fallback():
@allow_non_gpu(*non_utc_allow)
def test_from_json_struct(schema):
# note that column 'a' does not use leading zeroes due to https://github.com/NVIDIA/spark-rapids/issues/9588
json_string_gen = StringGen(r'{"a": [1-9]{0,5}, "b": "[A-Z]{0,5}", "c": 1\d\d\d}') \
json_string_gen = StringGen(r'{\'a\': [1-9]{0,5}, "b": \'[A-Z]{0,5}\', "c": 1\d\d\d}') \
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: could use fewer escape sequences with triple quotes

Suggested change
json_string_gen = StringGen(r'{\'a\': [1-9]{0,5}, "b": \'[A-Z]{0,5}\', "c": 1\d\d\d}') \
json_string_gen = StringGen(r'''{'a': [1-9]{0,5}, "b": '[A-Z]{0,5}', "c": 1\d\d\d}''') \

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I will address this in a follow-up PR if that is ok since we need this to make it into the 24.02 release.

.with_special_pattern('', weight=50) \
.with_special_pattern('null', weight=50)
assert_gpu_and_cpu_are_equal_collect(
Expand Down
10 changes: 5 additions & 5 deletions integration_tests/src/test/resources/dates.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ "number": "2020-09-16" }
{ "number": " 2020-09-16" }
{ "number": "2020-09-16 " }
{ "number": "1581-01-01" }
{ "number": "1583-01-01" }
{ 'number': '2020-09-16' }
{ 'number': ' 2020-09-16' }
{ 'number': '2020-09-16 ' }
{ 'number': '1581-01-01' }
{ 'number': '1583-01-01' }
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ class JsonPartitionReader(
cudf.JSONOptions.builder()
.withRecoverWithNull(true)
.withMixedTypesAsStrings(true)
.withNormalizeSingleQuotes(true)
.build
}

Expand Down
jlowe marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, NVIDIA CORPORATION.
* Copyright (c) 2023-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -180,6 +180,7 @@ case class GpuJsonToStructs(
// tracking issue for enabling mixed type as string
// https://github.com/NVIDIA/spark-rapids/issues/10253
.withMixedTypesAsStrings(false)
.withNormalizeSingleQuotes(true)
.build()
withResource(cudf.Table.readJSON(jsonOptions, data, start, length)) { tableWithMeta =>
val names = tableWithMeta.getColumnNames
Expand Down
Loading