clintropolis commented on code in PR #12920:
URL: https://github.com/apache/druid/pull/12920#discussion_r951902392


##########
processing/src/main/java/org/apache/druid/query/expression/NestedDataExpressions.java:
##########
@@ -139,38 +149,45 @@ public ToJsonExpr(List<Expr> args)
         public ExprEval eval(ObjectBinding bindings)
         {
           ExprEval input = args.get(0).eval(bindings);
-          return ExprEval.ofComplex(
-              TYPE,
-              maybeUnwrapStructuredData(input)
-          );
+          try {
+            final Object unwrapped = unwrap(input);
+            final String stringify = unwrapped == null ? null : 
jsonMapper.writeValueAsString(unwrapped);
+            return ExprEval.ofType(
+                ExpressionType.STRING,
+                stringify
+            );
+          }
+          catch (JsonProcessingException e) {
+            throw new IAE(e, "Unable to stringify [%s] to JSON", 
input.value());
+          }
         }
 
         @Override
         public Expr visit(Shuttle shuttle)
         {
           List<Expr> newArgs = args.stream().map(x -> 
x.visit(shuttle)).collect(Collectors.toList());
-          return shuttle.visit(new ToJsonExpr(newArgs));
+          return shuttle.visit(new ToJsonStringExpr(newArgs));
         }
 
         @Nullable
         @Override
         public ExpressionType getOutputType(InputBindingInspector inspector)
         {
-          return TYPE;
+          return ExpressionType.STRING;
         }
       }
-      return new ToJsonExpr(args);
+      return new ToJsonStringExpr(args);
     }
   }
 
-  public static class ToJsonStringExprMacro implements ExprMacroTable.ExprMacro
+  public static class ParseJsonExprMacro implements ExprMacroTable.ExprMacro
   {
-    public static final String NAME = "to_json_string";
+    public static final String NAME = "parse_json";

Review Comment:
   no, docs in #12922 were written as if this PR were already merged, 
(`to_json_string` still exists, but `to_json` is removed and `try_parse_json` 
is added, so this is a result of funny diff stuff i think)



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

Reply via email to