twalthr commented on a change in pull request #16776:
URL: https://github.com/apache/flink/pull/16776#discussion_r688555289



##########
File path: 
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/calls/JsonValueCallGen.scala
##########
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.planner.codegen.calls
+import org.apache.calcite.sql.{SqlJsonEmptyOrError, 
SqlJsonValueEmptyOrErrorBehavior}
+import org.apache.flink.table.planner.codegen.CodeGenUtils.{BINARY_STRING, 
qualifyEnum, qualifyMethod}
+import 
org.apache.flink.table.planner.codegen.GenerateUtils.generateCallWithStmtIfArgsNotNull
+import org.apache.flink.table.planner.codegen.{CodeGenException, 
CodeGeneratorContext, GeneratedExpression}
+import org.apache.flink.table.types.logical.{LogicalType, LogicalTypeRoot}
+
+/**
+ * [[CallGenerator]] for [[BuiltInMethods.JSON_VALUE]].
+ *
+ * We cannot use [[MethodCallGen]] for a few different reasons. First, the 
return type of the
+ * built-in Calcite function is [[Object]] and needs to be cast based on the 
inferred return type
+ * instead as users can change this using the RETURNING keyword. Furthermore, 
we need to provide
+ * the proper default values in case not all arguments were given.
+ */
+class JsonValueCallGen extends CallGenerator {
+  override def generate(
+      ctx: CodeGeneratorContext,
+      operands: Seq[GeneratedExpression],
+      returnType: LogicalType): GeneratedExpression = {
+
+    generateCallWithStmtIfArgsNotNull(ctx, returnType, operands, 
resultNullable = true) {
+      rawTerms => {
+        val emptyBehavior = getBehavior(operands, SqlJsonEmptyOrError.EMPTY)
+        val errorBehavior = getBehavior(operands, SqlJsonEmptyOrError.ERROR)
+        val terms = Seq(
+          s"${rawTerms.head}.toString()",
+          s"${rawTerms(1)}.toString()",
+          qualifyEnum(emptyBehavior._1),
+          emptyBehavior._2,
+          qualifyEnum(errorBehavior._1),
+          errorBehavior._2
+        )
+
+        val rawResultTerm = ctx.addReusableLocalVariable("Object", "rawResult")

Review comment:
       I don't know. The doc sounds like it is legacy after introducing the 
post code generation splitter. A `newName(fieldName)` should be enough, no?




-- 
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]


Reply via email to