Github user ueshin commented on a diff in the pull request:
https://github.com/apache/spark/pull/16750#discussion_r100225659
--- Diff:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/JsonExpressionsSuite.scala
---
@@ -357,30 +361,70 @@ class JsonExpressionsSuite extends SparkFunSuite with
ExpressionEvalHelper {
val jsonData = """{"a" 1}"""
val schema = StructType(StructField("a", IntegerType) :: Nil)
checkEvaluation(
- JsonToStruct(schema, Map.empty, Literal(jsonData)),
+ JsonToStruct(schema, Map.empty, Literal(jsonData), gmtId),
null
)
// Other modes should still return `null`.
checkEvaluation(
- JsonToStruct(schema, Map("mode" -> ParseModes.PERMISSIVE_MODE),
Literal(jsonData)),
+ JsonToStruct(schema, Map("mode" -> ParseModes.PERMISSIVE_MODE),
Literal(jsonData), gmtId),
null
)
}
test("from_json null input column") {
val schema = StructType(StructField("a", IntegerType) :: Nil)
checkEvaluation(
- JsonToStruct(schema, Map.empty, Literal.create(null, StringType)),
+ JsonToStruct(schema, Map.empty, Literal.create(null, StringType),
gmtId),
null
)
}
+ test("from_json with timestamp") {
+ val schema = StructType(StructField("t", TimestampType) :: Nil)
+
+ val jsonData1 = """{"t": "2016-01-01T00:00:00.123Z"}"""
+ var c = Calendar.getInstance(DateTimeUtils.TimeZoneGMT)
+ c.set(2016, 0, 1, 0, 0, 0)
+ c.set(Calendar.MILLISECOND, 123)
+ checkEvaluation(
+ JsonToStruct(schema, Map.empty, Literal(jsonData1), gmtId),
+ InternalRow.fromSeq(c.getTimeInMillis * 1000L :: Nil)
--- End diff --
Thanks, I'll use it.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]