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 @@ -446,6 +446,8 @@ case class MapObjects private(
override def genCode(ctx: CodegenContext, ev: ExprCode): String = {
val javaType = ctx.javaType(dataType)
val elementJavaType = ctx.javaType(loopVar.dataType)
ctx.addMutableState("boolean", loopVar.isNull, "")
ctx.addMutableState(elementJavaType, loopVar.value, "")
val genInputData = inputData.gen(ctx)
val genFunction = lambdaFunction.gen(ctx)
val dataLength = ctx.freshName("dataLength")
Expand All @@ -466,9 +468,9 @@ case class MapObjects private(
}

val loopNullCheck = if (primitiveElement) {
s"boolean ${loopVar.isNull} = ${genInputData.value}.isNullAt($loopIndex);"
s"${loopVar.isNull} = ${genInputData.value}.isNullAt($loopIndex);"
} else {
s"boolean ${loopVar.isNull} = ${genInputData.isNull} || ${loopVar.value} == null;"
s"${loopVar.isNull} = ${genInputData.isNull} || ${loopVar.value} == null;"
}

s"""
Expand All @@ -484,7 +486,7 @@ case class MapObjects private(

int $loopIndex = 0;
while ($loopIndex < $dataLength) {
$elementJavaType ${loopVar.value} =
${loopVar.value} =
($elementJavaType)${genInputData.value}${itemAccessor(loopIndex)};
$loopNullCheck

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1664,4 +1664,19 @@ class JsonSuite extends QueryTest with SharedSQLContext with TestJsonData {
)
}
}

test("wide nested json table") {
val nested = (1 to 100).map { i =>
s"""
|"c$i": $i
""".stripMargin
}.mkString(", ")
val json = s"""
|{"a": [{$nested}], "b": [{$nested}]}
""".stripMargin
val rdd = sqlContext.sparkContext.makeRDD(Seq(json))
val df = sqlContext.read.json(rdd)
assert(df.schema.size === 2)
df.collect()
}
}