Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,8 @@ class JacksonParser(

case _: StringType => (parser: JsonParser) => {
// This must be enabled if we will retrieve the bytes directly from the raw content:
val includeSourceInLocation = JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION
val originalMask = if (includeSourceInLocation.enabledIn(parser.getFeatureMask)) {
1
} else {
0
}
parser.overrideStdFeatures(includeSourceInLocation.getMask, includeSourceInLocation.getMask)
val oldFeature = parser.getFeatureMask
parser.setFeatureMask(oldFeature | JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION.getMask)
val result = parseJsonToken[UTF8String](parser, dataType) {
case VALUE_STRING =>
UTF8String.fromString(parser.getText)
Expand Down Expand Up @@ -344,7 +339,7 @@ class JacksonParser(
}
}
// Reset back to the original configuration:
parser.overrideStdFeatures(includeSourceInLocation.getMask, originalMask)
parser.setFeatureMask(oldFeature)
result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ import org.apache.spark.sql.types.StructType
import org.apache.spark.unsafe.types.UTF8String

class JacksonParserSuite extends SparkFunSuite {
test("feature mask should remain unchanged") {
val options = new JSONOptions(Map.empty[String, String], "GMT", "")
val parser = new JacksonParser(StructType.fromDDL("a string"), options, false, Nil)
val input = """{"a": {"b": 1}}""".getBytes
// The creating function is usually called inside `parser.parse`, but we need the JSON parser
// here for testing purpose.
val jsonParser = options.buildJsonFactory().createParser(input)
val oldFeature = jsonParser.getFeatureMask
val result = parser.parse[Array[Byte]](input, (_, _) => jsonParser, UTF8String.fromBytes)
assert(result === Seq(InternalRow(UTF8String.fromString("""{"b": 1}"""))))
assert(jsonParser.getFeatureMask == oldFeature)
}

test("skipping rows using pushdown filters") {
def check(
input: String = """{"i":1, "s": "a"}""",
Expand Down