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

Enable Single Quote Support in getJSONObject API with GetJsonObjectOptions #10407

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions integration_tests/src/main/python/get_json_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ def test_get_json_object_quoted_index():
f.get_json_object('jsonStr',r'''$['b']''').alias('sub_b')),
conf={'spark.rapids.sql.expression.GetJsonObject': 'true'})

def test_get_json_object_single_quotes():
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@revans2 Added test_get_json_object_single_quotes. This test would fail when .allowSingleQuotes(false).

schema = StructType([StructField("jsonStr", StringType())])
data = [[r'''{'a':'A'}'''],
[r'''{'b':'"B'}'''],
[r'''{"c":"'C"}''']]

assert_gpu_and_cpu_are_equal_collect(
lambda spark: spark.createDataFrame(data,schema=schema).select(
f.get_json_object('jsonStr',r'''$['a']''').alias('sub_a'),
f.get_json_object('jsonStr',r'''$['b']''').alias('sub_b'),
f.get_json_object('jsonStr',r'''$['c']''').alias('sub_c')),
conf={'spark.rapids.sql.expression.GetJsonObject': 'true'})

@pytest.mark.parametrize('query',["$.store.bicycle",
"$['store'].bicycle",
"$.store['bicycle']",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.nvidia.spark.rapids

import ai.rapids.cudf.ColumnVector
import ai.rapids.cudf.{ColumnVector,GetJsonObjectOptions}
import com.nvidia.spark.rapids.Arm.withResource

import org.apache.spark.sql.catalyst.expressions.{ExpectsInputTypes, Expression}
Expand All @@ -32,8 +32,9 @@ case class GpuGetJsonObject(json: Expression, path: Expression)
override def nullable: Boolean = true
override def prettyName: String = "get_json_object"

override def doColumnar(lhs: GpuColumnVector, rhs: GpuScalar): ColumnVector = {
lhs.getBase().getJSONObject(rhs.getBase)
override def doColumnar(lhs: GpuColumnVector, rhs: GpuScalar): ColumnVector = {
lhs.getBase().getJSONObject(rhs.getBase,
GetJsonObjectOptions.builder().allowSingleQuotes(true).build());
}

override def doColumnar(numRows: Int, lhs: GpuScalar, rhs: GpuScalar): ColumnVector = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.nvidia.spark.rapids

import ai.rapids.cudf.Scalar
import ai.rapids.cudf.{GetJsonObjectOptions,Scalar}
import com.nvidia.spark.rapids.Arm._
import com.nvidia.spark.rapids.RapidsPluginImplicits._
import com.nvidia.spark.rapids.RmmRapidsRetryIterator.{splitSpillableInHalfByRows, withRetry}
Expand Down Expand Up @@ -69,7 +69,8 @@ case class GpuJsonTuple(children: Seq[Expression]) extends GpuGenerator
}

withResource(fieldScalars) { fieldScalars =>
withResource(fieldScalars.safeMap(field => json.getJSONObject(field))) { resultCols =>
withResource(fieldScalars.safeMap(field => json.getJSONObject(field,
GetJsonObjectOptions.builder().allowSingleQuotes(true).build()))) { resultCols =>
val generatorCols = resultCols.safeMap(_.incRefCount).zip(schema).safeMap {
case (col, dataType) => GpuColumnVector.from(col, dataType)
}
Expand Down
Loading