snuyanzin commented on code in PR #28688:
URL: https://github.com/apache/flink/pull/28688#discussion_r3580791820
##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/ExprCodeGenerator.scala:
##########
@@ -935,6 +936,31 @@ class ExprCodeGenerator(
case BuiltInFunctionDefinitions.JSON_STRING =>
new JsonStringCallGen(call, rexProgram).generate(ctx, operands,
resultType)
+ case BuiltInFunctionDefinitions.JSON_LENGTH =>
+ generateCallWithStmtIfArgsNotNull(ctx, resultType, operands,
resultNullable = true) {
+ argTerms =>
+ val inputTerm = s"${argTerms.head}.toString()"
+ val (varName, parseCode) =
+ ctx.getReusableInputUnboxingExprs(inputTerm, Int.MinValue)
match {
+ case Some(expr) => (expr.resultTerm, "")
+ case None =>
+ val v = CodeGenUtils.newName(ctx, "jsonParsed")
+ ctx.addReusableMember(
+ s"${classOf[SqlJsonUtils.JsonValueContext].getName}
$v;")
+ ctx.addReusableInputUnboxingExprs(
+ inputTerm,
+ Int.MinValue,
+ GeneratedExpression(v, "false", "", null))
+ (v, s"$v =
${qualifyMethod(BuiltInMethods.JSON_PARSE)}($inputTerm);")
+ }
+ val (method, terms) =
+ if (operands.length > 1)
+ (BuiltInMethods.JSON_LENGTH_PATH, Seq(varName,
s"${argTerms(1)}.toString()"))
+ else
+ (BuiltInMethods.JSON_LENGTH, Seq(varName))
+ (parseCode, s"${qualifyMethod(method)}(${terms.mkString(",
")})")
Review Comment:
is it possible to extract it ideally to java helper?
--
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]