Airblader commented on a change in pull request #17186:
URL: https://github.com/apache/flink/pull/17186#discussion_r707260516



##########
File path: 
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/codegen/JsonGenerateUtils.scala
##########
@@ -0,0 +1,84 @@
+/*
+ * 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
+
+import org.apache.flink.table.planner.codegen.CodeGenUtils.typeTerm
+import 
org.apache.flink.table.planner.functions.sql.FlinkSqlOperatorTable.JSON_OBJECT
+import org.apache.flink.table.types.logical.LogicalTypeRoot._
+
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ContainerNode
+import 
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.util.RawValue
+
+import org.apache.calcite.rex.{RexCall, RexNode}
+
+/** Utility for generating JSON function calls. */
+object JsonGenerateUtils {
+
+  /**
+   * Returns a term which wraps the given <code>valueExpr</code> into a 
[[JsonNode]] of the
+   * appropriate type.
+   *
+   * @param containerNodeTerm Name of the [[ContainerNode]] from which to 
create the node.
+   * @param valueExpr Generated expression of the value which should be 
wrapped.
+   * @return Generated code fragment creating the appropriate node.
+   */
+  def createPrimitiveNodeTerm(containerNodeTerm: String, valueExpr: 
GeneratedExpression): String = {
+    valueExpr.resultType.getTypeRoot match {
+      case CHAR | VARCHAR => 
s"$containerNodeTerm.textNode(${valueExpr.resultTerm}.toString())"
+      case BOOLEAN => 
s"$containerNodeTerm.booleanNode(${valueExpr.resultTerm})"
+      case DECIMAL => 
s"$containerNodeTerm.numberNode(${valueExpr.resultTerm}.toBigDecimal())"

Review comment:
       @twalthr An alternative to passing the formatting to Jackson here would 
be enforcing our own SQL-compliant formatting and inserting it as a raw node. 
On the other hand, we're constructing a JSON string and I _assume_ that means 
we're not bound to doing that? We'll have the same question for supporting 
timestamp types, of course, where e.g. one could argue that a more JSON-native 
format makes sense.




-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to