Skip to content

Commit

Permalink
Modify tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarutak committed May 11, 2021
1 parent e72074c commit fabab22
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Expand Up @@ -173,25 +173,49 @@ class JacksonParser(
case ByteType =>
(parser: JsonParser) => parseJsonToken[java.lang.Byte](parser, dataType) {
case VALUE_NUMBER_INT => parser.getByteValue
case VALUE_STRING => parser.getText.toByte
case VALUE_STRING if parser.getText.length > 0 =>
try {
parser.getText.toByte
} catch {
case _: NumberFormatException => throw new RuntimeException(
s"Cannot parse ${parser.getText} as ${ByteType.catalogString}.")
}
}

case ShortType =>
(parser: JsonParser) => parseJsonToken[java.lang.Short](parser, dataType) {
case VALUE_NUMBER_INT => parser.getShortValue
case VALUE_STRING => parser.getText.toShort
case VALUE_STRING if parser.getText.length > 0 =>
try {
parser.getText.toShort
} catch {
case _: NumberFormatException => throw new RuntimeException(
s"Cannot parse ${parser.getText} as ${ShortType.catalogString}.")
}
}

case IntegerType =>
(parser: JsonParser) => parseJsonToken[java.lang.Integer](parser, dataType) {
case VALUE_NUMBER_INT => parser.getIntValue
case VALUE_STRING => parser.getText.toInt
case VALUE_STRING if parser.getText.length > 0 =>
try {
parser.getText.toInt
} catch {
case _: NumberFormatException => throw new RuntimeException(
s"Cannot parse ${parser.getText} as ${IntegerType.catalogString}.")
}
}

case LongType =>
(parser: JsonParser) => parseJsonToken[java.lang.Long](parser, dataType) {
case VALUE_NUMBER_INT => parser.getLongValue
case VALUE_STRING => parser.getText.toLong
case VALUE_STRING if parser.getText.length > 0 =>
try {
parser.getText.toLong
} catch {
case _: NumberFormatException => throw new RuntimeException(
s"Cannot parse ${parser.getText} as ${LongType.catalogString}.")
}
}

case FloatType =>
Expand Down
Expand Up @@ -244,7 +244,7 @@ select from_json('[1, "2", 3]', 'array<int>')
-- !query schema
struct<from_json([1, "2", 3]):array<int>>
-- !query output
NULL
[1,2,3]


-- !query
Expand Down
Expand Up @@ -2066,7 +2066,7 @@ abstract class JsonSuite
val data =
"""{"field": 1}
|{"field": 2}
|{"field": "3"}""".stripMargin
|{"field": "x"}""".stripMargin
Seq(data).toDF().repartition(1).write.text(path)
val schema = new StructType().add("field", ByteType).add("_corrupt_record", StringType)
// negative cases
Expand All @@ -2081,7 +2081,7 @@ abstract class JsonSuite
assert(df.filter($"_corrupt_record".isNull).count() == 2)
checkAnswer(
df.select("_corrupt_record"),
Row(null) :: Row(null) :: Row("{\"field\": \"3\"}") :: Nil
Row(null) :: Row(null) :: Row("{\"field\": \"x\"}") :: Nil
)
}
}
Expand Down

0 comments on commit fabab22

Please sign in to comment.