Skip to content

Commit

Permalink
Addressing Hyukjin Kwon's review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGekk committed Sep 4, 2018
1 parent 72d2628 commit 90c9687
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion R/pkg/R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ setMethod("to_date",

#' @details
#' \code{to_json}: Converts a column containing a \code{structType}, a \code{mapType}
#' or an array into a Column of JSON string.
#' or an \code{arrayType} into a Column of JSON string.
#' Resolving the Column can fail if an unsupported type is encountered.
#'
#' @rdname column_collection_functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,10 @@ case class StructsToJson(

@transient
lazy val gen = new JacksonGenerator(
rowSchema, writer, new JSONOptions(options, timeZoneId.get))
inputSchema, writer, new JSONOptions(options, timeZoneId.get))

@transient
lazy val rowSchema = child.dataType
lazy val inputSchema = child.dataType

// This converts rows to the JSON output according to the given schema.
@transient
Expand All @@ -674,7 +674,7 @@ case class StructsToJson(
UTF8String.fromString(json)
}

child.dataType match {
inputSchema match {
case _: StructType =>
(row: Any) =>
gen.write(row.asInstanceOf[InternalRow])
Expand All @@ -692,28 +692,28 @@ case class StructsToJson(

override def dataType: DataType = StringType

override def checkInputDataTypes(): TypeCheckResult = child.dataType match {
case _: StructType =>
override def checkInputDataTypes(): TypeCheckResult = inputSchema match {
case struct: StructType =>
try {
JacksonUtils.verifySchema(rowSchema.asInstanceOf[StructType])
JacksonUtils.verifySchema(struct)
TypeCheckResult.TypeCheckSuccess
} catch {
case e: UnsupportedOperationException =>
TypeCheckResult.TypeCheckFailure(e.getMessage)
}
case _: MapType =>
case map: MapType =>
// TODO: let `JacksonUtils.verifySchema` verify a `MapType`
try {
val st = StructType(StructField("a", rowSchema.asInstanceOf[MapType]) :: Nil)
val st = StructType(StructField("a", map) :: Nil)
JacksonUtils.verifySchema(st)
TypeCheckResult.TypeCheckSuccess
} catch {
case e: UnsupportedOperationException =>
TypeCheckResult.TypeCheckFailure(e.getMessage)
}
case _: ArrayType =>
case array: ArrayType =>
try {
JacksonUtils.verifyType(prettyName, rowSchema)
JacksonUtils.verifyType(prettyName, array)
TypeCheckResult.TypeCheckSuccess
} catch {
case e: UnsupportedOperationException =>
Expand Down

0 comments on commit 90c9687

Please sign in to comment.