diff --git a/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java b/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java index fa50cc6c4868..5effbe3e5448 100644 --- a/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java +++ b/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/JsonFunctions.java @@ -76,7 +76,7 @@ public static String toJsonMapStr(@Nullable Map map) /** * Convert object to Json String */ - @ScalarFunction(nullableParameters = true) + @ScalarFunction public static String jsonFormat(Object object) throws JsonProcessingException { return JsonUtils.objectToString(object); diff --git a/pinot-core/src/test/java/org/apache/pinot/core/data/function/JsonFunctionsTest.java b/pinot-core/src/test/java/org/apache/pinot/core/data/function/JsonFunctionsTest.java index fa9f6dfced2b..6aa8bcbe3d8f 100644 --- a/pinot-core/src/test/java/org/apache/pinot/core/data/function/JsonFunctionsTest.java +++ b/pinot-core/src/test/java/org/apache/pinot/core/data/function/JsonFunctionsTest.java @@ -137,4 +137,19 @@ public Object[][] jsonFunctionsDataProvider() }); return inputs.toArray(new Object[0][]); } + + @Test(description = "jsonFormat(Java null) should return Java null") + public void jsonFormatWithJavaNullReturnsJavaNull() { + GenericRow row = new GenericRow(); + row.putValue("jsonMap", null); + testFunction("json_format(jsonMap)", Lists.newArrayList("jsonMap"), row, null); + } + + @Test(description = "jsonFormat(JSON null) should return \"null\"") + public void jsonFormatWithJsonNullReturnsStringNull() + throws IOException { + GenericRow row = new GenericRow(); + row.putValue("jsonMap", JsonUtils.stringToJsonNode("null")); + testFunction("json_format(jsonMap)", Lists.newArrayList("jsonMap"), row, "null"); + } } diff --git a/pinot-spi/src/main/java/org/apache/pinot/spi/annotations/ScalarFunction.java b/pinot-spi/src/main/java/org/apache/pinot/spi/annotations/ScalarFunction.java index f0d14f7dd98f..46a743d52c79 100644 --- a/pinot-spi/src/main/java/org/apache/pinot/spi/annotations/ScalarFunction.java +++ b/pinot-spi/src/main/java/org/apache/pinot/spi/annotations/ScalarFunction.java @@ -46,11 +46,16 @@ boolean enabled() default true; - // If empty, FunctionsRegistry registers the method name as function name; - // If not empty, FunctionsRegistry only registers the function names specified here, the method name is ignored. + /** + * If empty, FunctionsRegistry registers the method name as function name; + * If not empty, FunctionsRegistry only registers the function names specified here, the method name is ignored. + */ String[] names() default {}; - // Whether the scalar function expects and can handle null arguments. + /** + * Whether the scalar function expects and can handle null arguments. + * + */ boolean nullableParameters() default false; boolean isPlaceholder() default false;