This is an automated email from the ASF dual-hosted git repository.
jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 1f93870ad3 Change json_format to return java null when java null is
received (#11673)
1f93870ad3 is described below
commit 1f93870ad3f80363a480f166393f0de2bc9af125
Author: Gonzalo Ortiz Jaureguizar <[email protected]>
AuthorDate: Wed Sep 27 19:23:09 2023 +0200
Change json_format to return java null when java null is received (#11673)
---
.../pinot/common/function/scalar/JsonFunctions.java | 2 +-
.../pinot/core/data/function/JsonFunctionsTest.java | 15 +++++++++++++++
.../org/apache/pinot/spi/annotations/ScalarFunction.java | 11 ++++++++---
3 files changed, 24 insertions(+), 4 deletions(-)
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 fa50cc6c48..5effbe3e54 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 class JsonFunctions {
/**
* 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 fa9f6dfced..6aa8bcbe3d 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 class JsonFunctionsTest {
});
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 f0d14f7dd9..46a743d52c 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 @@ public @interface ScalarFunction {
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;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]