cloud-fan commented on code in PR #49609:
URL: https://github.com/apache/spark/pull/49609#discussion_r1929960626
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala:
##########
@@ -287,31 +282,65 @@ case class VariantGet(
timeZoneId,
zoneId)
- protected override def nullSafeEval(input: Any, path: Any): Any = {
- VariantGet.variantGet(input.asInstanceOf[VariantVal], parsedPath,
dataType, castArgs)
+ protected override def nullSafeEval(input: Any, path: Any): Any = parsedPath
match {
+ case Some(pp) =>
+ VariantGet.variantGet(input.asInstanceOf[VariantVal], pp, dataType,
castArgs)
+ case _ =>
+ VariantGet.variantGet(input.asInstanceOf[VariantVal],
path.asInstanceOf[UTF8String], dataType,
+ castArgs, prettyName)
}
- protected override def doGenCode(ctx: CodegenContext, ev: ExprCode):
ExprCode = {
- val childCode = child.genCode(ctx)
- val tmp = ctx.freshVariable("tmp", classOf[Object])
- val parsedPathArg = ctx.addReferenceObj("parsedPath", parsedPath)
- val dataTypeArg = ctx.addReferenceObj("dataType", dataType)
- val castArgsArg = ctx.addReferenceObj("castArgs", castArgs)
- val code = code"""
- ${childCode.code}
- boolean ${ev.isNull} = ${childCode.isNull};
- ${CodeGenerator.javaType(dataType)} ${ev.value} =
${CodeGenerator.defaultValue(dataType)};
- if (!${ev.isNull}) {
- Object $tmp =
org.apache.spark.sql.catalyst.expressions.variant.VariantGet.variantGet(
- ${childCode.value}, $parsedPathArg, $dataTypeArg, $castArgsArg);
- if ($tmp == null) {
- ${ev.isNull} = true;
- } else {
- ${ev.value} = (${CodeGenerator.boxedType(dataType)})$tmp;
+ protected override def doGenCode(ctx: CodegenContext, ev: ExprCode):
ExprCode = parsedPath match {
+ case Some(pp) =>
+ val childCode = child.genCode(ctx)
+ val tmp = ctx.freshVariable("tmp", classOf[Object])
+ val parsedPathArg = ctx.addReferenceObj("parsedPath", pp)
+ val dataTypeArg = ctx.addReferenceObj("dataType", dataType)
+ val castArgsArg = ctx.addReferenceObj("castArgs", castArgs)
+ val code = code"""
+ ${childCode.code}
+ boolean ${ev.isNull} = ${childCode.isNull};
+ ${CodeGenerator.javaType(dataType)} ${ev.value} =
${CodeGenerator.defaultValue(dataType)};
+ if (!${ev.isNull}) {
+ Object $tmp =
org.apache.spark.sql.catalyst.expressions.variant.VariantGet.variantGet(
+ ${childCode.value}, $parsedPathArg, $dataTypeArg, $castArgsArg);
+ if ($tmp == null) {
+ ${ev.isNull} = true;
+ } else {
+ ${ev.value} = (${CodeGenerator.boxedType(dataType)})$tmp;
+ }
}
- }
- """
- ev.copy(code = code)
+ """
+ ev.copy(code = code)
+ case None =>
Review Comment:
there are a lot of common code between these two branches, can't we merge
them and adjust a few places w.r.t. `parsedPath`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]